本文整理汇总了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)
示例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
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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
示例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
示例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)
示例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)
示例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())
示例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)