convert text cdx stream to CDXObject/IDXObject.
323499
def make_obj_iter(text_iter, query):
    
    if query.secondary_index_only:
        cls = IDXObject
    else:
        cls = CDXObject

    return (cls(line) for line in text_iter)
96144
def _tostream(parser, obj, stream, skipprepack = False):
    
    if hasattr(parser, 'tostream'):
        return parser.tostream(obj, stream, skipprepack)
    else:
        data = parser.tobytes(obj, skipprepack)
        cls = type(parser)
        if cls not in _deprecated_parsers:
            _deprecated_parsers.add(cls)
            warnings.warn("Parser %r does not have 'tostream' interfaces" % (cls,), UserWarning)
        return stream.write(data)
1052793
def load_wc(cls, stream):
        """"""
        wc = wcxf.WC.load(stream)
        return cls.from_wc(wc)
944633
def _fill_cdata(cls):
    """"""

    funcs = {}
    for key, name in [("b", "char"), ("h", "short"),
                      ("i", "int"), ("q", "longlong")]:
        for echar, esuffix in [("<", "le"), (">", "be")]:
            esuffix = "_" + esuffix
            for unsigned in [True, False]:
                s = struct.Struct(echar + (key.upper() if unsigned else key))
                get_wrapper = lambda f: lambda *a, **k: f(*a, **k)[0]
                unpack = get_wrapper(s.unpack)
                unpack_from = get_wrapper(s.unpack_from)

                def get_unpack_from(s):
                    def unpack_from(data, offset=0):
                        return s.unpack_from(data, offset)[0], offset + s.size
                    return unpack_from

                unpack_from = get_unpack_from(s)
                pack = s.pack

                prefix = "u" if unsigned else ""
                if s.size == 1:
                    esuffix = ""
                bits = str(s.size * 8)

                if unsigned:
                    max_ = 2 ** (s.size * 8) - 1
                    min_ = 0
                else:
                    max_ = 2 ** (s.size * 8 - 1) - 1
                    min_ = - 2 ** (s.size * 8 - 1)

                funcs["%s%s_min" % (prefix, name)] = min_
                funcs["%s%s_max" % (prefix, name)] = max_
                funcs["%sint%s_min" % (prefix, bits)] = min_
                funcs["%sint%s_max" % (prefix, bits)] = max_

                funcs["%s%s%s" % (prefix, name, esuffix)] = unpack
                funcs["%sint%s%s" % (prefix, bits, esuffix)] = unpack
                funcs["%s%s%s_from" % (prefix, name, esuffix)] = unpack_from
                funcs["%sint%s%s_from" % (prefix, bits, esuffix)] = unpack_from
                funcs["to_%s%s%s" % (prefix, name, esuffix)] = pack
                funcs["to_%sint%s%s" % (prefix, bits, esuffix)] = pack

    for key, func in iteritems(funcs):
        setattr(cls, key, staticmethod(func))
1368474
def transform(self, textual):
        """"""
        if textual is None:
            return None
        type = textual[0]
        try:
            method = getattr(self, type + '_to_pyobject')
            return method(textual)
        except AttributeError:
            return None
392138
def load_stream(filename):
    """"""
    rawfile = pkg_resources.resource_stream(__name__, filename)
    if six.PY2:
        return rawfile
    return io.TextIOWrapper(rawfile, 'utf-8')
1020651
def transform_source(text):
    '''
    '''
    toks = tokenize.generate_tokens(StringIO(text).readline)
    result = []
    replacing_keyword = False
    for toktype, tokvalue, _, _, _ in toks:
        if toktype == tokenize.NAME and tokvalue == 'switch':
            result.extend([
                (tokenize.NAME, 'for'),
                (tokenize.NAME, '__case'),
                (tokenize.NAME, 'in'),
                (tokenize.NAME, '_Switch'),
                (tokenize.OP, '(')
            ])
            replacing_keyword = True
        elif toktype == tokenize.NAME and (tokvalue == 'case' or tokvalue == 'default'):
            result.extend([
                (tokenize.NAME, 'if'),
                (tokenize.NAME, '__case'),
                (tokenize.OP, '(')
            ])
            replacing_keyword = True
        elif replacing_keyword and tokvalue == ':':
            result.extend([
                (tokenize.OP, ')'),
                (tokenize.OP, ':')
            ])
            replacing_keyword = False
        else:
            result.append((toktype, tokvalue))
    return tokenize.untokenize(result)
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)
1059496
def stream_object_data(self, ref):
		""""""
		cmd = self.__get_persistent_cmd("cat_file_all", "cat_file", batch=True)
		hexsha, typename, size = self.__get_object_header(cmd, ref)
		return (hexsha, typename, size, self.CatFileContentStream(size, cmd.stdout))
232404
def iddtxt2groups(txt):
    """"""
    try:
        txt = txt.decode('ISO-8859-2')
    except AttributeError as e:
        pass # for python 3
    txt = nocomment(txt, '!')
    txt = txt.replace("\\group", "!-group") # retains group in next line
    txt = nocomment(txt, '\\') # remove all other idd info
    lines = txt.splitlines()
    lines = [line.strip() for line in lines] # cleanup
    lines = [line for line in lines if line != ''] # cleanup
    txt = '\n'.join(lines)
    gsplits = txt.split('!') # split into groups, since we have !-group
    gsplits = [gsplit.splitlines() for gsplit in gsplits] # split group

    gsplits[0].insert(0, None)
        # Put None for the first group that does nothave a group name
    gdict = {}
    for gsplit in gsplits:
        gdict.update({gsplit[0]:gsplit[1:]})
        # makes dict {groupname:[k1, k2], groupname2:[k3, k4]}

    gdict = {k:'\n'.join(v) for k, v in gdict.items()}# joins lines back
    gdict = {k:v.split(';') for k, v in gdict.items()} # splits into idfobjects
    gdict = {k:[i.strip() for i in v] for k, v in gdict.items()} # cleanup
    gdict = {k:[i.splitlines() for i in v] for k, v in gdict.items()}
        # splits idfobjects into lines
    gdict = {k:[i for i in v if len(i) > 0] for k, v in gdict.items()}
        # cleanup - removes blank lines
    gdict = {k:[i[0] for i in v] for k, v in gdict.items()} # use first line
    gdict = {k:[i.split(',')[0] for i in v] for k, v in gdict.items()}
        # remove ','
    nvalue = gdict.pop(None) # remove group with no name
    gdict = {k[len('-group '):]:v for k, v in gdict.items()} # get group name
    gdict.update({None:nvalue}) # put back group with no name
    return gdict
955589
def text_to_data(self, text, elt, ps):
        '''
        '''
        if self.strip: text = text.strip()
        if self.pyclass is not None:
            return self.pyclass(text.encode(UNICODE_ENCODING))
        return text.encode(UNICODE_ENCODING)
1176994
def FromTextFormat(cls, text):
    """"""
    tmp = cls.protobuf()  # pylint: disable=not-callable
    text_format.Merge(text, tmp)

    return cls.FromSerializedString(tmp.SerializeToString())
857802
def xtob(data, sep=''):
    """"""
    # remove the non-hex characters
    data = re.sub("[^0-9a-fA-F]", '', data)

    # interpret the hex
    return binascii.unhexlify(data)
1207803
private static Object decodeObject(String text) {
        Object result = null;
        if (text.startsWith("[]"))
            result = HexString.hexToBin(text, 2);
        else
            result = URLDecode(text);
        return result;
    }
1169118
def to_rawtx(tx):
    
    if tx.get('hex'):
        return tx['hex']

    new_tx = {}

    locktime = tx.get('locktime', 0)
    new_tx['locktime'] = locktime
    new_tx['version'] = tx.get('version', 1)
    new_tx['ins'] = [
        {
            'outpoint': {'hash': str(x['txid']), 'index': x['n']},
            'script': str(x['scriptSig'].replace(' ', '')),
            'sequence': x.get('sequence', 0xFFFFFFFF if locktime == 0 else None)
        } for x in tx['inputs']
    ]

    new_tx['outs'] = [
        {
            'script': str(x['scriptPubKey']),
            'value': x['amount']
        } for x in tx['outputs']
    ]

    return serialize(new_tx)
1221554
def inline_parse(text, verbose=False):
    """"""
    if isinstance(text, str):
        text = text.decode('utf-8')

    parsed = parse(text, verbose=verbose)

    shift = 0
    for quantity in parsed:
        index = quantity.span[1] + shift
        to_add = u' {' + unicode(quantity) + u'}'
        text = text[0:index] + to_add + text[index:]
        shift += len(to_add)

    return text
979618
def process_column(self, idx, value):
        ""
        if value is not None:
            value = str(value).decode(self.encoding)
        return value