Return a new AbiMethod object from an input stream
        :param s: binary input
        :return: new AbiMethod object matching the provided input stream
18989
def from_input_lookup(s):
        
        for pseudo_abi in FourByteDirectory.get_pseudo_abi_for_input(s):
            method = AbiMethod(pseudo_abi)
            types_def = pseudo_abi["inputs"]
            types = [t["type"] for t in types_def]
            names = [t["name"] for t in types_def]

            values = decode_abi(types, s[4:])

            # (type, name, data)
            method.inputs = [{"type": t, "name": n, "data": v} for t, n, v in list(
                zip(types, names, values))]
            return method
307939
def _from_stream(cls, stream, blob, filename=None):
        
        image_header = _ImageHeaderFactory(stream)
        if filename is None:
            filename = 'image.%s' % image_header.default_ext
        return cls(blob, filename, image_header)
828849
def bs(s: int) -> str:
    
    return str(s) if s <= 1 else bs(s >> 1) + str(s & 1)
177559
def from_stream(cls, stream):
        
        stream_rdr = StreamReader(stream, LITTLE_ENDIAN)

        px_width = stream_rdr.read_long(0x12)
        px_height = stream_rdr.read_long(0x16)

        horz_px_per_meter = stream_rdr.read_long(0x26)
        vert_px_per_meter = stream_rdr.read_long(0x2A)

        horz_dpi = cls._dpi(horz_px_per_meter)
        vert_dpi = cls._dpi(vert_px_per_meter)

        return cls(px_width, px_height, horz_dpi, vert_dpi)
508302
def from_bytes(cls, bitstream):
        '''
        
        '''
        from pylisp.packet.lisp.control import type_registry

        # Convert to ConstBitStream (if not already provided)
        if not isinstance(bitstream, ConstBitStream):
            if isinstance(bitstream, Bits):
                bitstream = ConstBitStream(auto=bitstream)
            else:
                bitstream = ConstBitStream(bytes=bitstream)

        # Peek at the bitstream to see which type it is
        type_nr = bitstream.peek('uint:4')

        # Look for the right class
        type_class = type_registry.get_type_class(type_nr)
        if not type_class:
            raise ValueError("Can't handle message type {0}".format(type_nr))

        # Let the specific class handle it from now on
        return type_class.from_bytes(bitstream)
1250572
def FromStream(cls, stream, auto_transfer=True, total_size=None, **kwds):
        """"""
        return cls(stream, auto_transfer=auto_transfer, total_size=total_size,
                   **kwds)
1215689
def from_string(cls, s: str) -> 'ComponentRef':
        

        components = s.split('.')
        return cls.from_tuple(components)
222365
def copy(input, **params):
    
    PARAM_FIELDS = 'fields'

    def filter_fields(obj, fields):
        return {k:v for k,v in obj.items() if k in fields}

    if PARAM_FIELDS in params:
        fields = params.get(PARAM_FIELDS)
        if isinstance(input, list):
            res = []
            for row in input:
                res.append(filter_fields(row, fields))
            return res
        elif isinstance(input, dict):
            return filter_fields(input, fields)
        else:
            raise NotImplementedError('{} is not supported'.format(type(input)))
    else:
        return input
444843
def byteswap(s):
    
    assert len(s) % 2 == 0
    parts = []
    for i in range(0, len(s), 2):
        chunk = s[i:i + 2]
        newchunk = struct.pack('<h', *struct.unpack('>h', chunk))
        parts.append(newchunk)
    return b''.join(parts)
1005293
def FromString(s, **kwargs):
    """"""
    
    f = StringIO.StringIO(s)
    return FromFile(f, **kwargs)
281295
def offsetcopy(s, newoffset):
    
    assert 0 <= newoffset < 8
    if not s.bitlength:
        return copy.copy(s)
    else:
        if newoffset == s.offset % 8:
            return ByteStore(s.getbyteslice(s.byteoffset, s.byteoffset + s.bytelength), s.bitlength, newoffset)
        newdata = []
        d = s._rawarray
        assert newoffset != s.offset % 8
        if newoffset < s.offset % 8:
            # We need to shift everything left
            shiftleft = s.offset % 8 - newoffset
            # First deal with everything except for the final byte
            for x in range(s.byteoffset, s.byteoffset + s.bytelength - 1):
                newdata.append(((d[x] << shiftleft) & 0xff) +\
                               (d[x + 1] >> (8 - shiftleft)))
            bits_in_last_byte = (s.offset + s.bitlength) % 8
            if not bits_in_last_byte:
                bits_in_last_byte = 8
            if bits_in_last_byte > shiftleft:
                newdata.append((d[s.byteoffset + s.bytelength - 1] << shiftleft) & 0xff)
        else: # newoffset > s._offset % 8
            shiftright = newoffset - s.offset % 8
            newdata.append(s.getbyte(0) >> shiftright)
            for x in range(s.byteoffset + 1, s.byteoffset + s.bytelength):
                newdata.append(((d[x - 1] << (8 - shiftright)) & 0xff) +\
                               (d[x] >> shiftright))
            bits_in_last_byte = (s.offset + s.bitlength) % 8
            if not bits_in_last_byte:
                bits_in_last_byte = 8
            if bits_in_last_byte + shiftright > 8:
                newdata.append((d[s.byteoffset + s.bytelength - 1] << (8 - shiftright)) & 0xff)
        new_s = ByteStore(bytearray(newdata), s.bitlength, newoffset)
        assert new_s.offset == newoffset
        return new_s
1083631
def FromStream(cls, stream):
        

        if stream.system:
            specifier = DataStreamSelector.MatchSystemOnly
        else:
            specifier = DataStreamSelector.MatchUserOnly

        return DataStreamSelector(stream.stream_type, stream.stream_id, specifier)
896006
def fsencoding(s, encoding=sys.getfilesystemencoding()):
    
    if isinstance(s, unicode):
        s = s.encode(encoding)
    return s
299952
def from_stream(cls, stream, offset):
        
        ifd_parser = _IfdParser(stream, offset)
        entries = dict((e.tag, e.value) for e in ifd_parser.iter_entries())
        return cls(entries)
1102
def encode(self, s):
        
        if isinstance(s, str) and self.needsEncoding(s):
            for x in self.encodings:
                s = re.sub(x[0], x[1], s)
        return s
667866
def tobytes(s, encoding='ascii'):
    
    # NOTE: after we abandon 2.5, we might simply instead use "bytes(s)"
    # NOTE: after we abandon all 2.*, del this and prepend byte strings with 'b'
    if PY3K:
        if isinstance(s, bytes):
            return s
        else:
            return s.encode(encoding)
    else:
        # for py2.6 on (before 3.0), bytes is same as str;  2.5 has no bytes
        # but handle if unicode is passed
        if isinstance(s, unicode):
            return s.encode(encoding)
        else:
            return s
1035446
def from_stream(cls, stream):
        
        cycles = []
        while True:
            scf_cycle = GroundStateScfCycle.from_stream(stream)
            if scf_cycle is None: break
            cycles.append(scf_cycle)

        return cls(cycles) if cycles else None