'Parses the contents generically, or using a spec with optional params
:param spec:
A class derived from Asn1Value that defines what class_ and tag the
value should have, and the semantics of the encoded value. The
return value will be of this type. If omitted, the encoded value
will be decoded using the standard universal tag based on the
encoded tag number.
:param spec_params:
A dict of params to pass to the spec object
:return:
An object of the type spec, or if not present, a child of Asn1Value'

def parse(self, spec=None, spec_params=None):

    if ((self._parsed is None) or (self._parsed[1:3] != (spec, spec_params))):
        try:
            passed_params = spec_params
            if (self.tag_type == u'explicit'):
                passed_params = ({} if (not spec_params) else spec_params.copy())
                passed_params[u'tag_type'] = self.tag_type
                passed_params[u'tag'] = self.explicit_tag
            contents = ((self._header + self.contents) + self._trailer)
            (parsed_value, _) = _parse_build(contents, spec=spec, spec_params=passed_params)
            self._parsed = (parsed_value, spec, spec_params)
            self.tag_type = None
            self.tag = None
            self._header = ''
            self.contents = contents
            self._trailer = ''
        except (ValueError, TypeError) as e:
            args = e.args[1:]
            e.args = (((e.args[0] + (u'\n                while    parsing    %s' % type_name(self))),) + args)
            raise e
    return self._parsed[0]
