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


Python unicodedata.lookup函数代码示例

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


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

示例1: test_aliases

 def test_aliases(self):
     # Check that the aliases defined in the NameAliases.txt file work.
     # This should be updated when new aliases are added or the file
     # should be downloaded and parsed instead.  See #12753.
     aliases = [
         ('LATIN CAPITAL LETTER GHA', 0x01A2),
         ('LATIN SMALL LETTER GHA', 0x01A3),
         ('KANNADA LETTER LLLA', 0x0CDE),
         ('LAO LETTER FO FON', 0x0E9D),
         ('LAO LETTER FO FAY', 0x0E9F),
         ('LAO LETTER RO', 0x0EA3),
         ('LAO LETTER LO', 0x0EA5),
         ('TIBETAN MARK BKA- SHOG GI MGO RGYAN', 0x0FD0),
         ('YI SYLLABLE ITERATION MARK', 0xA015),
         ('PRESENTATION FORM FOR VERTICAL RIGHT WHITE LENTICULAR BRACKET', 0xFE18),
         ('BYZANTINE MUSICAL SYMBOL FTHORA SKLIRON CHROMA VASIS', 0x1D0C5)
     ]
     for alias, codepoint in aliases:
         self.checkletter(alias, chr(codepoint))
         name = unicodedata.name(chr(codepoint))
         self.assertNotEqual(name, alias)
         self.assertEqual(unicodedata.lookup(alias),
                          unicodedata.lookup(name))
         with self.assertRaises(KeyError):
             unicodedata.ucd_3_2_0.lookup(alias)
开发者ID:alfonsodiecko,项目名称:PYTHON_DIST,代码行数:25,代码来源:test_ucn.py

示例2: _CleanUpSimpleRegex

def _CleanUpSimpleRegex(regex):
    regex = _RemoveChars(regex, [unicodedata.lookup('SPACE'), unicodedata.lookup('EM DASH'), unicodedata.lookup('EN DASH')])
    # TODO(shreevatsa): Make this work. Why does this regex have to be simple?
    # regex = regex.replace('4', '(LLLL|GLL|LGL|LLG|GG)')
    regex = regex.replace('4', '')
    assert re.match(r'^[LG.]*$', regex), regex
    return regex
开发者ID:sanskrit-coders,项目名称:Chandas,代码行数:7,代码来源:__init__.py

示例3: katakana_to_hiragana

def katakana_to_hiragana(text):
    # Only a to n, other symbols are not changed
    h_sa = unicodedata.lookup('HIRAGANA LETTER SMALL A')
    k_sa = unicodedata.lookup('KATAKANA LETTER SMALL A')
    k_n = unicodedata.lookup('KATAKANA LETTER N')
    return ''.join(chr(ord(h_sa) + ord(c) - ord(k_sa))
                   if is_katakana(c) and ord(c) <= ord(k_n)
                   else c for c in text)
开发者ID:asolano,项目名称:shiritori,代码行数:8,代码来源:game.py

示例4: test_nbsp_and_space_glyphs_width

 def test_nbsp_and_space_glyphs_width(self):
     """ Nbsp and space glyphs should have the same width"""
     space = 0
     nbsp = 0
     for x in self.font.glyphs():
         if x.unicode == ord(unicodedata.lookup('NO-BREAK SPACE')):
             nbsp = x.width
         elif x.unicode == ord(unicodedata.lookup('SPACE')):
             space = x.width
     self.assertEqual(space, nbsp)
开发者ID:pathumego,项目名称:fontbakery,代码行数:10,代码来源:result_test.py

示例5: init_view_objects

 def init_view_objects(self):
   box = wx.BoxSizer(wx.VERTICAL)
   instructions = wx.StaticText(
     self.frame,
     label="Use %s and %s to move up and down the test cases" % (
       unicodedata.lookup('LEFTWARDS ARROW'),
       unicodedata.lookup('RIGHTWARDS ARROW')),
     style=wx.ALIGN_CENTER,
   )
   box.Add(instructions, 0, wx.EXPAND)
   self.view_objects = MyGLWindow(self.frame, size=(1280, 800))
   self.view_objects.SetFocus()
   box.Add(self.view_objects, wx.EXPAND, wx.EXPAND)
   self.frame.SetSizer(box)
   box.SetSizeHints(self.frame)
开发者ID:cctbx,项目名称:cctbx-playground,代码行数:15,代码来源:wx_ellipsoids_test.py

示例6: get_special_chars

def get_special_chars(language, additional='', source=''):
    """Return list of special characters."""
    for char in settings.SPECIAL_CHARS:
        yield format_char(char)
    code = language.code.replace('_', '-').split('-')[0]

    if code in EXTRA_CHARS:
        for char in EXTRA_CHARS[code]:
            yield format_char(char)

    yield get_quote(code, DOUBLE_OPEN, _('Opening double quote'))
    yield get_quote(code, DOUBLE_CLOSE, _('Closing double quote'))
    yield get_quote(code, SINGLE_OPEN, _('Opening single quote'))
    yield get_quote(code, SINGLE_CLOSE, _('Closing single quote'))

    if code in HYPHEN_LANGS:
        yield _('Hyphen'), '-', '-'

    if code in EN_DASH_LANGS:
        yield _('En dash'), '–', '–'

    if code in EM_DASH_LANGS:
        yield _('Em dash'), '—', '—'

    for char in additional:
        yield _('User configured character: {}').format(char), char, char

    rtl = language.direction == 'rtl'
    for char in set(source):
        try:
            name = unicodedata.name(char)
        except ValueError:
            continue
        if 'ARROW' in name:
            if rtl and 'LEFT' in name:
                try:
                    char = unicodedata.lookup(name.replace('LEFT', 'RIGHT'))
                except KeyError:
                    continue
                yield format_char(char)
            elif rtl and 'RIGHT' in name:
                try:
                    char = unicodedata.lookup(name.replace('RIGHT', 'LEFT'))
                except KeyError:
                    continue
                yield format_char(char)
            else:
                yield format_char(char)
开发者ID:nijel,项目名称:weblate,代码行数:48,代码来源:specialchars.py

示例7: test_ascii_letters

    def test_ascii_letters(self):
        import unicodedata

        for char in "".join(map(chr, xrange(ord("a"), ord("z")))):
            name = "LATIN SMALL LETTER %s" % char.upper()
            code = unicodedata.lookup(name)
            self.assertEqual(unicodedata.name(code), name)
开发者ID:89sos98,项目名称:main,代码行数:7,代码来源:test_ucn.py

示例8: setup

def setup(app):

    # Register Builders
    app.add_builder(builder.SlideBuilder)
    app.add_builder(builder.DirectorySlideBuilder)
    app.add_builder(builder.SingleFileSlideBuilder)
    app.add_builder(builder.InlineSlideBuilder)
    app.add_builder(builder.DirectoryInlineSlideBuilder)

    app.connect('html-collect-pages', slides.get_extra_pages)

    # core slide configuration
    app.add_config_value('slide_title', None, 'html')
    app.add_config_value('slide_theme', 'slides', 'html')
    app.add_config_value('slide_levels', 3, 'html')
    app.add_config_value('slide_theme_options', {}, 'html')
    app.add_config_value('slide_theme_path', [], 'html')
    app.add_config_value('slide_numbers', False, 'html')
    app.add_config_value('slide_footer', None, 'html')
    app.add_config_value('autoslides', True, 'env')

    # support for linking html output to slides
    app.add_config_value('slide_link_html_to_slides', False, 'html')
    app.add_config_value('slide_link_html_sections_to_slides', False, 'html')
    app.add_config_value('slide_relative_path', '../slides/', 'html')
    app.add_config_value('slide_html_slide_link_symbol',
                         unicodedata.lookup('section sign'), 'html')

    # support for linking from slide output to html
    app.add_config_value('slide_link_to_html', False, 'html')
    app.add_config_value('slide_html_relative_path', '../html/', 'html')

    # slide-related directives
    app.add_node(directives.if_slides)
    app.add_directive('ifnotslides', directives.IfBuildingSlides)
    app.add_directive('ifslides', directives.IfBuildingSlides)
    app.add_directive('notslides', directives.IfBuildingSlides)
    app.add_directive('slides', directives.IfBuildingSlides)
    app.add_transform(directives.TransformSlideConditions)

    app.add_node(directives.slideconf,
                 html=(directives.raiseSkip, None),
                 latex=(directives.raiseSkip, None),
                 text=(directives.raiseSkip, None),
                 man=(directives.raiseSkip, None),
                 texinfo=(directives.raiseSkip, None),
    )
    app.add_directive('slideconf', directives.SlideConf)
    app.connect('doctree-resolved', directives.process_slideconf_nodes)

    app.add_node(directives.slide)
    app.add_directive('slide', directives.SlideDirective)
    app.connect('doctree-resolved', directives.process_slide_nodes)

    app.add_node(directives.nextslide)
    app.add_directive('nextslide', directives.NextSlideDirective)
    app.add_transform(directives.TransformNextSlides)

    app.connect('builder-inited', html.inspect_config)
    app.connect('html-page-context', html.add_link)
开发者ID:AlbertMietus,项目名称:hieroglyph,代码行数:60,代码来源:__init__.py

示例9: make_basic_glyphs

def make_basic_glyphs(font):
    # This works, but prints out "failed to parse color" 6 times per glyph.
    # That is going to be annoying as heck unless I can suppress that output.
    for d in config['directories'].values():
        for f in os.listdir(d):
            fullpath = path.join(d, f)
            # This avoids accidentally processing subdirectories.  If I ever
            # want to change the directory structure drastically, then I can
            # investigate os.walk().
            if path.isfile(fullpath):
                print('Processing file: {}'.format(f))
                # Retrieve the filename sans extension, i.e., the glyph's
                # unicode name.
                glyphname = path.splitext(path.basename(f))[0]
                try:
                    glyphnum = ord(unicodedata.lookup(glyphname))
                except KeyError:
                    printerr(('Filename `{}` does not correspond to a '
                              'unicode name').format(fullpath),
                             level='Warning')
                    continue
                glyph = font.createChar(glyphnum)
                glyph.importOutlines(fullpath)
                glyph.correctDirection()
                adjust_bearings(d, glyph, glyphname)
开发者ID:hmc678,项目名称:Mazon,代码行数:25,代码来源:makefont.py

示例10: simplify_el

def simplify_el(string):
    result = []
    for c in string:
        try:
            name = unicodedata.name(c).split()
        except ValueError:
            continue
        if 'WITH' in name:
            assert name[4] == 'WITH'
            # possible diacritics: TONOS OXIA DIALYTIKA VARIA DASIA
            #                      PERISPOMENI PROSGEGRAMMENI YPOGEGRAMMENI
            diacritics = []
            if 'DIALYTIKA' in name[5:]:
                diacritics.append('DIALYTIKA')
            if any(a in name[5:]
                   for a in ['TONOS', 'OXIA', 'VARIA', 'PERISPOMENI']):
                diacritics.append('TONOS')
            new_name = name[:4]
            if len(diacritics) >= 1:
                new_name += ['WITH', diacritics[0]]
            for d in diacritics[1:]:
                new_name += ['AND', d]
            result.append(unicodedata.lookup(' '.join(new_name)))
        else:
            # oxia, tonos, acute, RIGHT SINGLE QUOTATION MARK (they look the same)
            if c in ('´', '΄', '´', '’'):
                c = "'"
            result.append(c)
    result = ''.join(result)
    result = ' '.join(convert_numbers(word)
                      for word in result.split())
    return result
开发者ID:mik01aj,项目名称:corthus,代码行数:32,代码来源:simplify_el.py

示例11: normalize_char

def normalize_char(c):
  try:
    cname = unicodedata.name( unicode(c) )
    cname = cname[:cname.index( ' WITH' )]
    return unicodedata.lookup( cname )
  except ( ValueError, KeyError ):
    return c
开发者ID:rampantpixels,项目名称:lua_lib,代码行数:7,代码来源:plist.py

示例12: test_cjk

    def test_cjk(self):
        import sys
        import unicodedata

        cases = ((0x3400, 0x4DB5), (0x4E00, 0x9FA5))
        if unicodedata.unidata_version >= "5":  # don't know the exact limit
            cases = ((0x3400, 0x4DB5), (0x4E00, 0x9FCB), (0x20000, 0x2A6D6), (0x2A700, 0x2B734))
        elif unicodedata.unidata_version >= "4.1":
            cases = ((0x3400, 0x4DB5), (0x4E00, 0x9FBB), (0x20000, 0x2A6D6))
        for first, last in cases:
            # Test at and inside the boundary
            for i in (first, first + 1, last - 1, last):
                charname = "CJK UNIFIED IDEOGRAPH-%X" % i
                char = ("\\U%08X" % i).decode("unicode-escape")
                assert unicodedata.name(char) == charname
                assert unicodedata.lookup(charname) == char
            # Test outside the boundary
            for i in first - 1, last + 1:
                charname = "CJK UNIFIED IDEOGRAPH-%X" % i
                char = ("\\U%08X" % i).decode("unicode-escape")
                try:
                    unicodedata.name(char)
                except ValueError, e:
                    assert e.message == "no such name"
                raises(KeyError, unicodedata.lookup, charname)
开发者ID:cimarieta,项目名称:usp,代码行数:25,代码来源:test_unicodedata.py

示例13: add

    def add(beta):
        # characters with an irregular name
        IRREGULAR = {
            'GREEK CAPITAL LETTER DIGAMMA': 'GREEK LETTER DIGAMMA',
            'GREEK SMALL LETTER LUNATE SIGMA': 'GREEK LUNATE SIGMA SYMBOL',
            'GREEK CAPITAL LETTER LUNATE SIGMA': 'GREEK CAPITAL LUNATE SIGMA SYMBOL',
        }

        is_capital = '*' in beta
        low_beta = beta.replace('*', '')

        letter = re.search('|'.join(re.escape(x) for x in sorted(LETTERS, key=lambda l: -len(l)) ), low_beta).group(0)
        diacs = [ DIACRITICS[x][is_capital] for x in low_beta.replace(letter, '') ]
        # the only precedence difference between unicode names and betacode
        if 'DIALYTIKA' in diacs:
            diacs.remove('DIALYTIKA')
            diacs.insert(0, 'DIALYTIKA')

        name = 'GREEK {} LETTER {}'.format({ True: 'CAPITAL', False: 'SMALL' }[is_capital], LETTERS[letter].upper() )
        if diacs:
            name += ' WITH ' + ' AND '.join(diacs)

        name = IRREGULAR.get(name, name)
        try:
            found = unicodedata.lookup(name)
        except KeyError:
            raise KeyError(u'Not found {} (name: {})'.format(beta, name))

        t.add(beta, found)
开发者ID:itayperl,项目名称:lsj-kindle,代码行数:29,代码来源:beta2unicode.py

示例14: greek

def greek(name):
    ''' Returns unicode for greek letters
    Example:
    >>> print greek('nu')
    >>> print greek('lamda')
    '''
    return _unicodedata.lookup('GREEK SMALL LETTER '+name.upper())
开发者ID:yuyichao,项目名称:jlab2s13,代码行数:7,代码来源:__init__.py

示例15: half2full

    def half2full(self, char):
        u"""半角カタカナ char を全角カタカナに変換する"""
        if not self.is_halfwidthkatakana(char):
            raise CharTypeException(char)

        name = re.sub(r"^HALFWIDTH\s", "", unicodedata.name(char))
        return unicodedata.lookup(name)
开发者ID:kenkov,项目名称:kovlive,代码行数:7,代码来源:chartype.py


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