当前位置: 首页>>代码示例>>Python>>正文


Python unicodedata.name方法代码示例

本文整理汇总了Python中unicodedata.name方法的典型用法代码示例。如果您正苦于以下问题:Python unicodedata.name方法的具体用法?Python unicodedata.name怎么用?Python unicodedata.name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在unicodedata的用法示例。


在下文中一共展示了unicodedata.name方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import name [as 别名]
def main(global_delay, local_delay, concurrency):
    global global_sleep, local_sleep, semaphore, index
    global_sleep = global_delay
    local_sleep = local_delay
    semaphore = asyncio.Semaphore(concurrency)
    print('Global delay =', global_delay)
    print('Local delay =', local_delay)
    print('Max. concurrency =', concurrency)
    print('Building inverted index...')
    index = build_index()

    app = web.Application()
    app.router.add_get('/', usage)
    app.router.add_get('/index/{word}', index_for)
    app.router.add_get('/name/{char}', char_name)

    print('Listening on port', PORT)
    web.run_app(app, port=PORT) 
开发者ID:fluentpython,项目名称:concurrency2017,代码行数:20,代码来源:signs_server.py

示例2: main

# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import name [as 别名]
def main(argv):
  if len(argv) < 2:
    sys.exit('Must specify one or more font files.')

  cps = set()
  for filename in argv[1:]:
    if not os.path.isfile(filename):
      sys.exit('%s is not a file' % filename)
    cps |= fonts.CodepointsInFont(filename)

  for cp in sorted(cps):
    show_char = ''
    if FLAGS.show_char:
      show_char = (' ' + unichr(cp).strip() + ' ' +
                   unicodedata.name(unichr(cp), ''))
    show_subset = ''
    if FLAGS.show_subsets:
      show_subset = ' subset:%s' % ','.join(fonts.SubsetsForCodepoint(cp))

    print(u'0x%04X%s%s' % (cp, show_char, show_subset)) 
开发者ID:googlefonts,项目名称:gftools,代码行数:22,代码来源:gftools-ttf2cp.py

示例3: test_longstrings

# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import name [as 别名]
def test_longstrings(self):
        # test long strings to check for memory overflow problems
        errors = [ "strict", "ignore", "replace", "xmlcharrefreplace",
                   "backslashreplace"]
        # register the handlers under different names,
        # to prevent the codec from recognizing the name
        for err in errors:
            codecs.register_error("test." + err, codecs.lookup_error(err))
        l = 1000
        errors += [ "test." + err for err in errors ]
        for uni in [ s*l for s in (u"x", u"\u3042", u"a\xe4") ]:
            for enc in ("ascii", "latin-1", "iso-8859-1", "iso-8859-15",
                        "utf-8", "utf-7", "utf-16", "utf-32"):
                for err in errors:
                    try:
                        uni.encode(enc, err)
                    except UnicodeError:
                        pass 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:20,代码来源:test_codeccallbacks.py

示例4: test_hangul_syllables

# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import name [as 别名]
def test_hangul_syllables(self):
        self.checkletter("HANGUL SYLLABLE GA", u"\uac00")
        self.checkletter("HANGUL SYLLABLE GGWEOSS", u"\uafe8")
        self.checkletter("HANGUL SYLLABLE DOLS", u"\ub3d0")
        self.checkletter("HANGUL SYLLABLE RYAN", u"\ub7b8")
        self.checkletter("HANGUL SYLLABLE MWIK", u"\ubba0")
        self.checkletter("HANGUL SYLLABLE BBWAEM", u"\ubf88")
        self.checkletter("HANGUL SYLLABLE SSEOL", u"\uc370")
        self.checkletter("HANGUL SYLLABLE YI", u"\uc758")
        self.checkletter("HANGUL SYLLABLE JJYOSS", u"\ucb40")
        self.checkletter("HANGUL SYLLABLE KYEOLS", u"\ucf28")
        self.checkletter("HANGUL SYLLABLE PAN", u"\ud310")
        self.checkletter("HANGUL SYLLABLE HWEOK", u"\ud6f8")
        self.checkletter("HANGUL SYLLABLE HIH", u"\ud7a3")

        import unicodedata
        self.assertRaises(ValueError, unicodedata.name, u"\ud7a4") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:test_ucn.py

示例5: test_strict_eror_handling

# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import name [as 别名]
def test_strict_eror_handling(self):
        # bogus character name
        self.assertRaises(
            UnicodeError,
            unicode, "\\N{blah}", 'unicode-escape', 'strict'
        )
        # long bogus character name
        self.assertRaises(
            UnicodeError,
            unicode, "\\N{%s}" % ("x" * 100000), 'unicode-escape', 'strict'
        )
        # missing closing brace
        self.assertRaises(
            UnicodeError,
            unicode, "\\N{SPACE", 'unicode-escape', 'strict'
        )
        # missing opening brace
        self.assertRaises(
            UnicodeError,
            unicode, "\\NSPACE", 'unicode-escape', 'strict'
        ) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:23,代码来源:test_ucn.py

示例6: test_ipy2_gh357

# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import name [as 别名]
def test_ipy2_gh357(self):
        """https://github.com/IronLanguages/ironpython2/issues/357"""

        import unicodedata

        if is_cli:
            self.assertEqual(unicodedata.name(u'\u4e2d'), '<CJK IDEOGRAPH, FIRST>..<CJK IDEOGRAPH, LAST>')
        else:
            self.assertEqual(unicodedata.name(u'\u4e2d'), 'CJK UNIFIED IDEOGRAPH-4E2D')

        self.assertRaises(ValueError, unicodedata.decimal, u'\u4e2d')
        self.assertEqual(unicodedata.decimal(u'\u4e2d', 0), 0)
        self.assertRaises(ValueError, unicodedata.digit, u'\u4e2d')
        self.assertEqual(unicodedata.digit(u'\u4e2d', 0), 0)
        self.assertRaises(ValueError, unicodedata.numeric, u'\u4e2d')
        self.assertEqual(unicodedata.numeric(u'\u4e2d', 0), 0)
        self.assertEqual(unicodedata.category(u'\u4e2d'), 'Lo')
        self.assertEqual(unicodedata.bidirectional(u'\u4e2d'), 'L')
        self.assertEqual(unicodedata.combining(u'\u4e2d'), 0)
        self.assertEqual(unicodedata.east_asian_width(u'\u4e2d'), 'W')
        self.assertEqual(unicodedata.mirrored(u'\u4e2d'), 0)
        self.assertEqual(unicodedata.decomposition(u'\u4e2d'), '') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:24,代码来源:test_regressions.py

示例7: get_unicode_index

# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import name [as 别名]
def get_unicode_index(symbol):
    """get_unicode_index(symbol) -> integer

Return the integer index (from the Unicode table) of symbol.  *symbol*
can be a single unicode character, a TeX command (i.e. r'\pi'), or a
Type1 symbol name (i.e. 'phi').
"""
    # From UTF #25: U+2212 minus sign is the preferred
    # representation of the unary and binary minus sign rather than
    # the ASCII-derived U+002D hyphen-minus, because minus sign is
    # unambiguous and because it is rendered with a more desirable
    # length, usually longer than a hyphen.
    if symbol == '-':
        return 0x2212
    try:# This will succeed if symbol is a single unicode char
        return ord(symbol)
    except TypeError:
        pass
    try:# Is symbol a TeX symbol (i.e. \alpha)
        return tex2uni[symbol.strip("\\")]
    except KeyError:
        message = """'%(symbol)s' is not a valid Unicode character or
TeX/Type1 symbol"""%locals()
        raise ValueError(message) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:26,代码来源:mathtext.py

示例8: render_glyph

# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import name [as 别名]
def render_glyph(self, ox, oy, facename, font_class, sym, fontsize, dpi):
        """
        Draw a glyph at

          - *ox*, *oy*: position

          - *facename*: One of the TeX face names

          - *font_class*:

          - *sym*: TeX symbol name or single character

          - *fontsize*: fontsize in points

          - *dpi*: The dpi to draw at.
        """
        info = self._get_info(facename, font_class, sym, fontsize, dpi)
        realpath, stat_key = get_realpath_and_stat(info.font.fname)
        used_characters = self.used_characters.setdefault(
            stat_key, (realpath, set()))
        used_characters[1].add(info.num)
        self.mathtext_backend.render_glyph(ox, oy, info) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:24,代码来源:mathtext.py

示例9: unicode

# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import name [as 别名]
def unicode(self, irc, msg, args, query):
        """[character]
        Look up unicode character details
        """
        url = "http://unicodelookup.com/lookup?"
        url = url + urlencode({"q": query, "o": 0})
        data = web.getUrl(url)
        try:
            data = json.loads(data)
            responses = []
            for result in data["results"]:
                ucode = result[2].replace("0x", "U+")
                name = unicodedata.name("{0}".format(query))
                responses.append(
                    "%s (%s): %s [HTML: %s / Decimal: %s / Hex: %s]"
                    % (ucode, name, result[4], result[3], result[1], result[2])
                )
            response = "; ".join(responses)
            irc.reply(response)
        except ValueError:
            irc.reply("No unicode characters matching /" + query + "/ found.") 
开发者ID:oddluck,项目名称:limnoria-plugins,代码行数:23,代码来源:plugin.py

示例10: remove_diacritics

# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import name [as 别名]
def remove_diacritics(self):
        """
        :return: str: the input string stripped of its diacritics

        Examples:
            >>> Word('ġelǣd').remove_diacritics()
            'gelæd'

        """

        w = ''
        for c in unicodedata.normalize('NFKD', self.word):
            if 'LATIN' == unicodedata.name(c)[:5]:
                w += c

        return w 
开发者ID:cltk,项目名称:cltk,代码行数:18,代码来源:phonology.py

示例11: __init__

# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import name [as 别名]
def __init__(self, unicodeHexValue, block):
        """ Set up a unicode character.
        
        Arguments:
        unicodeHexValue -- an integer that should correspond to a 
                           Unicode code point.
        block -- the CharacterBlock this character belongs to.
        
        Raises:
        ValueError -- if unicodeHexValue is not a valid code point.
        
        """
        if unicodeHexValue < 0 or unicodeHexValue > 0x10FFFF:
            raise ValueError("numeric value outside Unicode range")
        self.unicodeHexValue = unicodeHexValue
        """ Use name check to filter out unused characters.
              unicodedata.name() raises ValueError for these
        """
        self.unichr = py23char(self.unicodeHexValue)
        self.name = unicodedata.name(self.unichr)
        self.equivalents = {}
        self._block = block 
开发者ID:cltk,项目名称:cltk,代码行数:24,代码来源:itrans_transliterator.py

示例12: _equivalent

# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import name [as 别名]
def _equivalent(self, char, prev, next, implicitA):
        """ Transliterate a Devanagari character to Latin.
        
        Add implicit As unless overridden by VIRAMA.
        
        """
        result = []
        if char.unichr != DevanagariCharacter._VIRAMA:
            result.append(char.equivalents[self.name])
        """ Append implicit A to consonants if the next character isn't a vowel. """
        if implicitA and char.isConsonant \
        and ((next is not None \
        and next.unichr != DevanagariCharacter._VIRAMA \
        and not next.isVowel) \
        or next is None):
            result.append(characterBlocks['DEVANAGARI']\
                   [DevanagariCharacter._LETTER_A].equivalents[self.name])
        return result 
开发者ID:cltk,项目名称:cltk,代码行数:20,代码来源:itrans_transliterator.py

示例13: __init__

# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import name [as 别名]
def __init__(self, unicodeHexValue, block):
        """ Set up a unicode character.
        
        Arguments:
        unicodeHexValue -- an integer that should correspond to a 
                           Unicode code point.
        block -- the CharacterBlock this character belongs to.
        
        Raises:
        ValueError -- if unicodeHexValue is not a valid code point.
        
        """
        if unicodeHexValue < 0 or unicodeHexValue > 0x10FFFF:
            raise (ValueError, "numeric value outside Unicode range")
        self.unicodeHexValue = unicodeHexValue
        """ Use name check to filter out unused characters.
              unicodedata.name() raises ValueError for these
        """
        self.chr = chr(self.unicodeHexValue)
        self.name = unicodedata.name(self.chr)
        self.equivalents = {}
        self._block = block 
开发者ID:sanskrit-coders,项目名称:indic_transliteration,代码行数:24,代码来源:transliterator.py

示例14: _equivalent

# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import name [as 别名]
def _equivalent(self, char, prev, next, implicitA):
        """ Transliterate a Devanagari character to Latin.
        
        Add implicit As unless overridden by VIRAMA.
        
        """
        implicitA = False  # Force it!
        result = []
        if char.chr != DevanagariCharacter._VIRAMA:
            result.append(char.equivalents[self.name])
        """ Append implicit A to consonants if the next character isn't a vowel. """
        if implicitA and char.isConsonant \
        and ((next is not None \
        and next.chr != DevanagariCharacter._VIRAMA \
        and not next.isVowel) \
        or next is None):
            result.append(characterBlocks['DEVANAGARI']\
                   [DevanagariCharacter._LETTER_A].equivalents[self.name])
        return result 
开发者ID:sanskrit-coders,项目名称:indic_transliteration,代码行数:21,代码来源:transliterator.py

示例15: _combining_class

# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import name [as 别名]
def _combining_class(cp):
    v = unicodedata.combining(unichr(cp))
    if v == 0:
        if not unicodedata.name(unichr(cp)):
            raise ValueError("Unknown character in unicodedata")
    return v 
开发者ID:danielecook,项目名称:gist-alfred,代码行数:8,代码来源:core.py


注:本文中的unicodedata.name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。