當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。