Deserialize SimpleMRS string representations

    Args:
        s (str): a SimpleMRS string
        single (bool): if `True`, only return the first Xmrs object
    Returns:
        a generator of Xmrs objects (unless *single* is `True`)
773471
def loads(s, single=False, version=_default_version,
          strict=False, errors='warn'):
    
    ms = deserialize(s, version=version, strict=strict, errors=errors)
    if single:
        return next(ms)
    else:
        return ms
953267
def get_tuple_type_str_parts(s: str) -> Optional[Tuple[str, Optional[str]]]:
    
    match = TUPLE_TYPE_STR_RE.match(s)

    if match is not None:
        tuple_prefix = match.group(1)
        tuple_dims = match.group(2)

        return tuple_prefix, tuple_dims

    return None
973862
def deserialize(stream_or_string, **options):
    '''
    
    '''

    try:
        if not isinstance(stream_or_string, (bytes, six.string_types)):
            return toml.load(stream_or_string, **options)

        if isinstance(stream_or_string, bytes):
            stream_or_string = stream_or_string.decode('utf-8')

        return toml.loads(stream_or_string)
    except Exception as error:
        raise DeserializationError(error)
955964
def deserialize(to_deserialize, *args, **kwargs):
    
    if isinstance(to_deserialize, string_types):
        if re.match('^[0-9a-f]{24}$', to_deserialize):
            return ObjectId(to_deserialize)
        try:
            return bson_loads(to_deserialize, *args, **kwargs)
        except:
            return bson_loads(bson_dumps(to_deserialize), *args, **kwargs)
    else:
        return bson_loads(bson_dumps(to_deserialize), *args, **kwargs)
175616
def deserialize(self, value, **kwargs):                                    #pylint: disable=unused-argument
        
        kwargs.update({'trusted': kwargs.get('trusted', False)})
        if self.deserializer is not None:
            return self.deserializer(value, **kwargs)
        if value is None:
            return None
        return self.from_json(value, **kwargs)
868972
def unwrap_single(self):
        
        try:
            return next(self.itervalues())
        except AttributeError:
            return next(iter(self.values()))
1259522
def to_str(s):
    
    if isinstance(s, bytes):
        s = s.decode('utf-8')
    elif not isinstance(s, str):
        s = str(s)
    return s
1124993
def from_string(type_string):
    '''

    '''
    if type_string == NONE:
        return NONE
    elif type_string == PERIODIC_EC_SHARED:
        return PERIODC_EC_SHARED
    elif type_string == PERIODIC_STATE_SHARED:
        return PERIODIC_STATE_SHARED
    elif type_string == GROUPING:
        return GROUPING
    elif type_string == FSM_EC_SHARED:
        return FSM_EC_SHARED
    elif type_string == FSM_STATE_SHARED:
        return FSM_STATE_SHARED
    else:
        raise InvalidCompositeTypeError(type_string)
758199
def _deserialize(s, proto):  # type: (bytes, _Proto) -> _Proto
    '''
    
    '''
    if not isinstance(s, bytes):
        raise ValueError('Parameter s must be bytes, but got type: {}'.format(type(s)))

    if not (hasattr(proto, 'ParseFromString') and callable(proto.ParseFromString)):
        raise ValueError('No ParseFromString method is detected. '
                         '\ntype is {}'.format(type(proto)))

    decoded = cast(Optional[int], proto.ParseFromString(s))
    if decoded is not None and decoded != len(s):
        raise google.protobuf.message.DecodeError(
            "Protobuf decoding consumed too few bytes: {} out of {}".format(
                decoded, len(s)))
    return proto
1161598
def encode(self, s):
        
        if isinstance(s, basestring) and self.__needs_encoding(s):
            for x in self.encodings:
                s = re.sub(x[0], x[1], s)
        return s
767994
def decode(cls, s):
        
        b = ByteString(s)
        bd = base64.b64decode(b)
        return String(bd)
897835
def xml_str_to_dict(s):
    
    xml = minidom.parseString(s)
    return pythonzimbra.tools.xmlserializer.dom_to_dict(xml.firstChild)
201845
def loads(s, model):
    
    graphs = penman.loads(s, cls=XMRSCodec)
    xs = [model.from_triples(g.triples()) for g in graphs]
    return xs
1361362
def deserialize(cls, v, bind_client=None):
        
        if v is None:
            return None
        o = cls(bind_client=bind_client)
        o.from_dict(v)
        return o
986070
def _simple_po_to_dict(tokens) -> BaseAbundance:
    
    dsl = FUNC_TO_DSL.get(tokens[FUNCTION])
    if dsl is None:
        raise ValueError('invalid tokens: {}'.format(tokens))

    return dsl(
        namespace=tokens[NAMESPACE],
        name=tokens.get(NAME),
        identifier=tokens.get(IDENTIFIER),
    )
482833
def serialize_single_xso(x):
    
    buf = io.BytesIO()
    gen = XMPPXMLGenerator(buf,
                           short_empty_elements=True,
                           sorted_attributes=True)
    x.unparse_to_sax(gen)
    return buf.getvalue().decode("utf8")
1108928
def to_str(s):
    
    if bytes != str:
        """
        这里的比较在python2中是True，在Python3中是False
        """
        if type(s) == bytes:
            return s.decode('utf-8')
    return s