python类category()的实例源码

utils.py 文件源码 项目:nonce2vec 作者: minimalparts 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def deaccent(text):
    """
    Remove accentuation from the given string. Input text is either a unicode string or utf8 encoded bytestring.

    Return input string with accents removed, as unicode.

    >>> deaccent("Šéf chomutovských komunist? dostal poštou bílý prášek")
    u'Sef chomutovskych komunistu dostal postou bily prasek'

    """
    if not isinstance(text, unicode):
        # assume utf8 for byte strings, use default (strict) error handling
        text = text.decode('utf8')
    norm = unicodedata.normalize("NFD", text)
    result = u('').join(ch for ch in norm if unicodedata.category(ch) != 'Mn')
    return unicodedata.normalize("NFC", result)
core.py 文件源码 项目:my-first-blog 作者: AnkurBegining 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def check_initial_combiner(label):

    if unicodedata.category(label[0])[0] == 'M':
        raise IDNAError('Label begins with an illegal combining character')
    return True
cleantitle.py 文件源码 项目:plugin.video.exodus 作者: lastship 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def normalize(title):
    try:
        try: return title.decode('ascii').encode("utf-8")
        except: pass

        return str(''.join(c for c in unicodedata.normalize('NFKD', unicode(title.decode('utf-8'))) if unicodedata.category(c) != 'Mn'))
    except:
        return title
core.py 文件源码 项目:googletranslate.popclipext 作者: wizyoung 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def check_initial_combiner(label):

    if unicodedata.category(label[0])[0] == 'M':
        raise IDNAError('Label begins with an illegal combining character')
    return True
core.py 文件源码 项目:pip-update-requirements 作者: alanhamlett 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def check_initial_combiner(label):

    if unicodedata.category(label[0])[0] == 'M':
        raise IDNAError('Label begins with an illegal combining character')
    return True
helper.py 文件源码 项目:Cuneiform 作者: nervouna 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def pinyinify(string):
    # TODO: Use static file instead of constructing table in real time
    table = dict()
    for i in range(sys.maxunicode):
        if re.match('P|S|Z|C', unicodedata.category(chr(i))) is not None:
            table[i] = '-'
    string = string.translate(table)
    for char in [x for x in string if unicodedata.name(x).startswith('CJK')]:
        string = string.replace(char, pinyin.get(char, format='strip') + '-')
    string = re.sub('\-+', '-', string)
    return pinyin.get(string, delimiter='', format='strip').lower()
core.py 文件源码 项目:noc-orchestrator 作者: DirceuSilvaLabs 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def check_initial_combiner(label):

    if unicodedata.category(label[0])[0] == 'M':
        raise IDNAError('Label begins with an illegal combining character')
    return True
core.py 文件源码 项目:jira_worklog_scanner 作者: pgarneau 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def check_initial_combiner(label):

    if unicodedata.category(label[0])[0] == 'M':
        raise IDNAError('Label begins with an illegal combining character')
    return True
core.py 文件源码 项目:workflows.kyoyue 作者: wizyoung 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def check_initial_combiner(label):

    if unicodedata.category(label[0])[0] == 'M':
        raise IDNAError('Label begins with an illegal combining character')
    return True
util.py 文件源码 项目:oadoi 作者: Impactstory 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def replace_punctuation(text, sub):
    punctutation_cats = set(['Pc', 'Pd', 'Ps', 'Pe', 'Pi', 'Pf', 'Po'])
    chars = []
    for my_char in text:
        if unicodedata.category(my_char) in punctutation_cats:
            chars.append(sub)
        else:
            chars.append(my_char)
    return u"".join(chars)


# from http://stackoverflow.com/a/22238613/596939
roster_thread.py 文件源码 项目:xmpp-cloud-auth 作者: jsxc 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def sanitize(name):
    name = unicode(name)
    printable = set(('Lu', 'Ll', 'Lm', 'Lo', 'Nd', 'Nl', 'No', 'Pc', 'Pd', 'Ps', 'Pe', 'Pi', 'Pf', 'Po', 'Sm', 'Sc', 'Sk', 'So', 'Zs'))
    return utf8(''.join(c for c in name if unicodedata.category(c) in printable and c != '@'))
fontreport.py 文件源码 项目:fontreport 作者: googlei18n 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def Plaintext(self):
    data = ''
    for category, code in sorted(FontFile.NAME_CODES.items(),
                                 key=lambda x:x[1]):
      if code in self.font._names:
        data += '%15s: %s\n' % (category, self.font._names[code])
    return data
fontreport.py 文件源码 项目:fontreport 作者: googlei18n 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def XetexBody(self):
    data = ''
    for category, code in sorted(FontFile.NAME_CODES.items(),
                                 key=lambda x:x[1]):
      if code in self.font._names:
        data += '%s & %s \\\\\n' % (category,
                                    TexEscape(self.font._names[code]))
    return data
thesaurus_query.py 文件源码 项目:thesaurus_query.vim 作者: Ron89 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _double_width_char_count(word):
    dw_count = 0
    for char in word:
        if _unicode_data.category(char) in _double_width_type:
            dw_count += 1
    return dw_count
core.py 文件源码 项目:purelove 作者: hucmosin 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def check_initial_combiner(label):

    if unicodedata.category(label[0])[0] == 'M':
        raise IDNAError('Label begins with an illegal combining character')
    return True
core.py 文件源码 项目:harbour-sailfinder 作者: DylanVanAssche 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def check_initial_combiner(label):

    if unicodedata.category(label[0])[0] == 'M':
        raise IDNAError('Label begins with an illegal combining character')
    return True
core.py 文件源码 项目:harbour-sailfinder 作者: DylanVanAssche 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def check_initial_combiner(label):

    if unicodedata.category(label[0])[0] == 'M':
        raise IDNAError('Label begins with an illegal combining character')
    return True
reader.py 文件源码 项目:pyrepl 作者: dajose 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def _make_unctrl_map():
    uc_map = {}
    for c in map(unichr, range(256)):
        if unicodedata.category(c)[0] != 'C':
            uc_map[c] = c
    for i in range(32):
        c = unichr(i)
        uc_map[c] = '^' + unichr(ord('A') + i - 1)
    uc_map[b'\t'] = '    '  # display TABs as 4 characters
    uc_map[b'\177'] = unicode('^?')
    for i in range(256):
        c = unichr(i)
        if c not in uc_map:
            uc_map[c] = unicode('\\%03o') % i
    return uc_map
reader.py 文件源码 项目:pyrepl 作者: dajose 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _my_unctrl(c, u=_make_unctrl_map()):
    if c in u:
        return u[c]
    else:
        if unicodedata.category(c).startswith('C'):
            return b'\u%04x' % ord(c)
        else:
            return c
__init__.py 文件源码 项目:ChemDataExtractor 作者: mcs07 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def is_punct(text):
    for char in text:
        if not unicodedata.category(char).startswith('P'):
            return False
    else:
        return True


问题


面经


文章

微信
公众号

扫码关注公众号