Parse unicode category tables.
322516
def _parse_category(fname, categories):
        """"""
        version, date, values = None, None, []
        print("parsing {} ..".format(fname))
        for line in open(fname, 'rb'):
            uline = line.decode('utf-8')
            if version is None:
                version = uline.split(None, 1)[1].rstrip()
                continue
            elif date is None:
                date = uline.split(':', 1)[1].rstrip()
                continue
            if uline.startswith('#') or not uline.lstrip():
                continue
            addrs, details = uline.split(';', 1)
            addrs, details = addrs.rstrip(), details.lstrip()
            if any(details.startswith('{} #'.format(value))
                   for value in categories):
                start, stop = addrs, addrs
                if '..' in addrs:
                    start, stop = addrs.split('..')
                values.extend(range(int(start, 16), int(stop, 16) + 1))
        return version, date, sorted(values)
1241445
def parse_tables(self):
        
        tables = self._parse_tables(self._build_doc(), self.match, self.attrs)
        return (self._parse_thead_tbody_tfoot(table) for table in tables)
394760
def build_unicode_property_table(output):
    """"""

    if not os.path.exists(output):
        os.mkdir(output)
    gen_properties(output)
633613
def _structure_unicode(self, obj, cl):
        """"""
        if not isinstance(obj, (bytes, unicode)):
            return cl(str(obj))
        else:
            return obj
920423
private function _getCategory($tables)
    {
        if (isset($tables['category']) && $tables['category'] == 'database-table-name') {
            $category = $this->_normalizeTablename($tables['table']);
        } else {
            $category = Scanner::CATEGORY_DATABASE;
        }

        return $category;
    }
461101
function () {
  var cats = getCategories();
  for (var i in cats) {
    log.debug('\n\nTEST CATEGORY: ' + cats[i]);
    testCategory(cats[i]);
  }
}
589390
def strings_to_categoricals(adata):
    
    from pandas.api.types import is_string_dtype
    from pandas import Categorical
    for df in [adata.obs, adata.var]:
        string_cols = [key for key in df.columns if is_string_dtype(df[key])]
        for key in string_cols:
            c = df[key]
            c = Categorical(c)
            if len(c.categories) < len(c): df[key] = c
975723
def parse_string_table(self, tables):
        
        self.info("String table: %s" % (tables.tables, ))

        for table in tables.tables:
            if table.table_name == "userinfo":
                for item in table.items:
                    if len(item.data) > 0:
                        if len(item.data) == 140:
                            p = PlayerInfo()
                            ctypes.memmove(ctypes.addressof(p), item.data, 140)
                            p.str = item.str
                            self.run_hooks(p)
            if table.table_name == "CombatLogNames":
                self.combat_log_names = dict(enumerate(
                    (item.str for item in table.items)))
70157
def get_indic_positional_category_property(value, is_bytes=False):
    """"""

    if PY35:
        obj = unidata.ascii_indic_positional_category if is_bytes else unidata.unicode_indic_positional_category
        alias_key = 'indicpositionalcategory'
    else:
        obj = unidata.ascii_indic_matra_category if is_bytes else unidata.unicode_indic_matra_category
        alias_key = 'indicmatracategory'

    if value.startswith('^'):
        negated = value[1:]
        value = '^' + unidata.unicode_alias[alias_key].get(negated, negated)
    else:
        value = unidata.unicode_alias[alias_key].get(value, value)

    return obj[value]
1233823
def _get_unicode(data, force=False):
    """"""
    if isinstance(data, binary_type):
        return data.decode('utf-8')
    elif data is None:
        return ''
    elif force:
        if PY2:
            return unicode(data)
        else:
            return str(data)
    else:
        return data
773831
def dict_unicodeize(some_dict):
    """"""

    # some python 2/3 compat
    if isinstance(some_dict, ("".__class__, u"".__class__)):
        if sys.version_info >= (3, 0):
            return some_dict

        return some_dict.decode('utf-8')
    elif isinstance(some_dict, collections.Mapping):
        return dict(map(dict_unicodeize, iteritems(some_dict)))
    elif isinstance(some_dict, collections.Iterable):
        return type(some_dict)(map(dict_unicodeize, some_dict))

    return some_dict
341664
def _unicode(p):
    
    q = {}
    for tag in p:
        vals = []
        for v in p[tag]:
            if type(v) is not str:                                                              # pragma: no cover
                v = v.decode('utf-8')
            vals.append(v)
        if type(tag) is not str:                                                                # pragma: no cover
            tag = tag.decode('utf-8')
        q[tag] = vals
    return q
240335
def _parse_tables(self, soup):
        
        tables = []
        for t in soup.find_all('table'):
            t_dict = {'width': 0, 'table': t, 'trs': [], 'col_width': {}}
            trs = t.find_all('tr')
            if len(trs) > 0:
                for tr in trs:
                    tr_dict = []
                    tds = tr.find_all('th') + tr.find_all('td')
                    if len(tds) > 0:
                        for i, td in enumerate(tds):
                            td_text = self._find_any_text(td)
                            length = len(td_text)
                            if i in t_dict['col_width']:
                                t_dict['col_width'][i] = max(
                                    length,
                                    t_dict['col_width'][i]
                                )
                            else:
                                t_dict['col_width'][i] = length
                            tr_dict.append({
                                'text': td_text,
                                'colspan': int(td.get('colspan', 1)),
                            })
                        t_dict['trs'].append(tr_dict)
                for col in t_dict['col_width']:
                    t_dict['width'] += t_dict['col_width'][col]
                tables.append(t_dict)
        return tables
66173
def parse(resp) -> DataFrameType:
    """"""
    statements = []
    for statement in resp['results']:
        series = {}
        for s in statement.get('series', []):
            series[_get_name(s)] = _drop_zero_index(_serializer(s))
        statements.append(series)

    if len(statements) == 1:
        series: dict = statements[0]
        if len(series) == 1:
            return list(series.values())[0]  # DataFrame
        else:
            return series  # dict
    return statements
565681
def _translate(unistr, table):
    ''''''
    if type(unistr) is str:
        try:
            unistr = unistr.decode('utf-8')
        # Python 3 returns AttributeError when .decode() is called on a str
        # This means it is already unicode.
        except AttributeError:
            pass
    try:
        if type(unistr) is not unicode:
            return unistr
    # Python 3 returns NameError because unicode is not a type.
    except NameError:
        pass

    chars = []
    for c in unistr:
        replacement = table.get(c)
        chars.append(replacement if replacement else c)
    return u''.join(chars)
1017482
def generate_unicode_table():
    """"""

    uver = get_unicodedata()
    fail = False
    path = os.path.join(os.path.dirname(__file__), 'tools')
    fp, pathname, desc = imp.find_module('unipropgen', [path])
    try:
        unipropgen = imp.load_module('unipropgen', fp, pathname, desc)
        unipropgen.build_tables(
            os.path.join(
                os.path.dirname(__file__),
                'backrefs', 'uniprops', 'unidata'
            ),
            uver
        )
    except Exception:
        print(traceback.format_exc())
        fail = True
    finally:
        fp.close()

    assert not fail, "Failed uniprops.py generation!"
58437
def _repr_categories(self):
        
        max_categories = (10 if get_option("display.max_categories") == 0 else
                          get_option("display.max_categories"))
        from pandas.io.formats import format as fmt
        if len(self.categories) > max_categories:
            num = max_categories // 2
            head = fmt.format_array(self.categories[:num], None)
            tail = fmt.format_array(self.categories[-num:], None)
            category_strs = head + ["..."] + tail
        else:
            category_strs = fmt.format_array(self.categories, None)

        # Strip all leading spaces, which format_array adds for columns...
        category_strs = [x.strip() for x in category_strs]
        return category_strs