我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用unicodedata.name()。
def haveibeenpwned(self, name : str): '''Check if your account has been breached''' url = "https://haveibeenpwned.com/api/v2/breachedaccount/{0}?truncateResponse=true".format(name) async with clients.aiohttp_session.get(url) as resp: status = resp.status data = await resp.json() if status in [404, 400]: breachedaccounts = "None" else: breachedaccounts = "" for breachedaccount in data: breachedaccounts += breachedaccount["Name"] + ", " breachedaccounts = breachedaccounts[:-2] url = "https://haveibeenpwned.com/api/v2/pasteaccount/{0}".format(name) async with clients.aiohttp_session.get(url) as resp: status = resp.status data = await resp.json() if status in [404, 400]: pastedaccounts = "None" else: pastedaccounts = "" for pastedaccount in data: pastedaccounts += pastedaccount["Source"] + " (" + pastedaccount["Id"] + "), " pastedaccounts = pastedaccounts[:-2] await self.bot.embed_reply("Breached accounts: {}\nPastes: {}".format(breachedaccounts, pastedaccounts))
def imagerecognition(self, image_url : str): '''Image recognition''' try: response = clients.clarifai_general_model.predict_by_url(image_url) except clarifai.rest.ApiError as e: await self.bot.embed_reply(":no_entry: Error: `{}`".format(e.response.json()["outputs"][0]["status"]["details"])) return if response["status"]["description"] != "Ok": await self.bot.embed_reply(":no_entry: Error") return names = {} for concept in response["outputs"][0]["data"]["concepts"]: names[concept["name"]] = concept["value"] * 100 output = "" for name, value in sorted(names.items(), key = lambda i: i[1], reverse = True): output += "**{}**: {:.2f}%, ".format(name, value) output = output[:-2] await self.bot.embed_reply(output)
def lichess_user_all(self, ctx, username : str): '''WIP''' data = self.lichess_user_data embed = discord.Embed(title = data["username"], url = data["url"], color = clients.bot_color) avatar = ctx.message.author.avatar_url or ctx.message.author.default_avatar_url embed.set_author(name = ctx.message.author.display_name, icon_url = avatar) embed.description = "Online: {}\n".format(data["online"]) embed.description += "Member since {}\n".format(datetime.datetime.utcfromtimestamp(data["createdAt"] / 1000.0).strftime("%b %#d, %Y")) # embed.add_field(name = "Games", value = "Played: {0[all]}\nRated: {0[rated]}\nWins: {0[win]}\nLosses: {0[loss]}\nDraws: {0[draw]}\nBookmarks: {0[bookmark]}\nAI: {0[ai]}".format(data["count"])) embed.add_field(name = "Follows", value = "Followers: {0[nbFollowers]}\nFollowing: {0[nbFollowing]}".format(data)) embed.add_field(name = "Time", value = "Spent playing: {}\nOn TV: {}".format(utilities.secs_to_letter_format(data["playTime"]["total"]), utilities.secs_to_letter_format(data["playTime"]["tv"]))) for mode, field_name in (("bullet", ":zap: Bullet"), ("blitz", ":fire: Blitz"), ("classical", ":hourglass: Classical"), ("correspondence", ":envelope: Correspondence"), ("crazyhouse", ":pisces: Crazyhouse"), ("chess960", ":game_die: Chess960"), ("kingOfTheHill", ":triangular_flag_on_post: King Of The Hill"), ("threeCheck", ":three: Three-Check"), ("antichess", ":arrows_clockwise: Antichess"), ("atomic", ":atom: Atomic"), ("horde", ":question: Horde"), ("racingKings", ":checkered_flag: Racing Kings"), ("puzzle", ":bow_and_arrow: Training")): if data["perfs"].get(mode, {}).get("games", 0) == 0: continue prov = '?' if data["perfs"][mode]["prov"] else "" chart = ":chart_with_upwards_trend:" if data["perfs"][mode]["prog"] >= 0 else ":chart_with_downwards_trend:" value = "Games: {0[games]}\nRating: {0[rating]}{1} ± {0[rd]}\n{2} {0[prog]}".format(data["perfs"][mode], prov, chart) embed.add_field(name = field_name, value = value) embed.set_footer(text = "Last seen") embed.timestamp = datetime.datetime.utcfromtimestamp(data["seenAt"] / 1000.0) await self.bot.say(embed = embed)
def rotmg_characters(self, ctx, player : str): '''Realm of the Mad God player characters information''' url = "https://nightfirec.at/realmeye-api/?player={}".format(player) # http://webhost.ischool.uw.edu/~joatwood/realmeye_api/0.3/ async with clients.aiohttp_session.get(url) as resp: data = await resp.json() if "error" in data: await self.bot.embed_reply("Error: " + data["error"]) return embed = discord.Embed(title = "{}'s Characters".format(data["player"]), color = clients.bot_color) avatar = ctx.message.author.avatar_url or ctx.message.author.default_avatar_url embed.set_author(name = ctx.message.author.display_name, icon_url = avatar) for character in data["characters"]: value = "Fame: {0[fame]:,}, Exp: {0[exp]:,}, Rank: {0[place]:,}, Class Quests Completed: {0[cqc]}, Stats Maxed: {0[stats_maxed]}".format(character) value += "\nHP: {0[hp]}, MP: {0[mp]}, Attack: {0[attack]}, Defense: {0[defense]}, Speed: {0[speed]}, Vitality: {0[vitality]}, Wisdom: {0[wisdom]}, Dexterity: {0[dexterity]}".format(character["stats"]) equips = [] for type, equip in character["equips"].items(): equips.append("{}: {}".format(type.capitalize(), equip)) value += '\n' + ", ".join(equips) value += "\nPet: {0[pet]}, Clothing Dye: {0[character_dyes][clothing_dye]}, Accessory Dye: {0[character_dyes][accessory_dye]}, Backpack: {0[backpack]}".format(character) value += "\nLast Seen: {0[last_seen]}, Last Server: {0[last_server]}".format(character) embed.add_field(name = "Level {0[level]} {0[class]}".format(character), value = value, inline = False) await self.bot.say(embed = embed)
def spotifyinfo(self, ctx, url : str): '''Information about a Spotify track''' path = urllib.parse.urlparse(url).path if path[:7] != "/track/": await self.bot.embed_reply(":no_entry: Syntax error") return trackid = path[7:] api_url = "https://api.spotify.com/v1/tracks/" + trackid async with clients.aiohttp_session.get(api_url) as resp: data = await resp.json() # tracknumber = str(data["track_number"]) description = "Artist: [{}]({})\n".format(data["artists"][0]["name"], data["artists"][0]["external_urls"]["spotify"]) description += "Album: [{}]({})\n".format(data["album"]["name"], data["album"]["external_urls"]["spotify"]) description += "Duration: {}\n".format(utilities.secs_to_colon_format(data["duration_ms"] / 1000)) description += "[Preview]({})".format(data["preview_url"]) await self.bot.embed_reply(description, title = data["name"], title_url = url, thumbnail_url = data["album"]["images"][0]["url"])
def XetexBody(self): data = '' prevcode = 0 for code in sorted(self.font.chars): try: uniname = unicodedata.name(unichr(code)) except ValueError: uniname = '' if code - prevcode > 1: gaps = len([x for x in range(prevcode + 1, code) if unicodedata.category(unichr(x))[0] != 'C']) if gaps: data += ('\\rowcolor{missing}\\multicolumn{3}{|c|}' '{\\small %d visible characters not mapped to glyphs} \\\\\n') % (gaps) prevcode = code data += ('\\texttt{%04X} & {\\customfont\\symbol{%d}} &' '{\\small %s}\\\\\n') % (code, code, uniname) return data
def XetexBody(self): data = '' uni = {} for code, name in self.font.chars.items(): if name not in uni: uni[name] = [] uni[name].append(code) for glyph in self.font.glyphs: if glyph.class_name: data += '\\rowcolor{%s}\n' % glyph.class_name if glyph.name in uni: chars = ', '.join('u%04X' % x for x in glyph.chars) else: chars = '' data += '%d & %s & %s & %d & %d & %d & %s\\\\\n' % ( glyph.index, TexGlyph(glyph), TexEscape(glyph.name), glyph.advance_width, glyph.lsb, glyph.class_def, chars) return data
def charinfo(self, ctx, *, chars): """Get unicode character info.""" if not chars: return chars = unicodedata.normalize('NFC', chars) if len(chars) > 25: await ctx.send('Too many emoji.') return embed = discord.Embed() for char in chars: uc = hex(ord(char))[2:] name = unicodedata.name(char, 'unknown') if name in {'SPACE', 'EM QUAD', 'EN QUAD'} or ' SPACE' in name: char = '" "' short = len(uc) <= 4 code = f'`\\{"u" if short else "U"}{uc.lower().zfill(4 if short else 8)}`' embed.add_field(name=name, value=f'{char} [{code}](http://www.fileformat.info/info/unicode/char/{uc}/index.htm)') await ctx.send(embed=embed)
def __init__(self, emoji): self.raw = emoji if isinstance(emoji, str): self.id = 0 self.unicode = emoji self.custom = False self.managed = False self.name = [unicodedata.name(ch) for ch in emoji] self.category = [unicodedata.category(ch) for ch in emoji] self.roles = [] self.guild = None else: self.id = emoji.id self.unicode = '' self.custom = True self.managed = getattr(emoji, 'managed', None) self.name = [emoji.name] self.category = ['custom'] self.roles = getattr(emoji, 'roles', None) self.guild = getattr(emoji, 'guild', None)
def charinfo(self, *, characters: str): """Shows you information about a number of characters in emojis. Only up to 15 characters at a time. """ if len(characters) > 15: await self.bot.say('Too many characters ({}/15)'.format(len(characters))) return fmt = '`\\U{0:>08}`: {1} - {2} \N{EM DASH} <http://www.fileformat.info/info/unicode/char/{0}>' def to_string(c): digit = format(ord(c), 'x') name = unicodedata.name(c, 'Name not found.') return fmt.format(digit, name, c) await self.bot.say('\n'.join(map(to_string, characters)))
def build_index(self, chars=None): if chars is None: chars = (chr(i) for i in range(32, sys.maxunicode)) index = {} for char in chars: try: name = unicodedata.name(char) except ValueError: continue if name.startswith(CJK_UNI_PREFIX): name = CJK_UNI_PREFIX elif name.startswith(CJK_CMP_PREFIX): name = CJK_CMP_PREFIX for word in tokenize(name): index.setdefault(word, set()).add(char) self.index = index
def show_encodings(): print(end='\t\t') for encoding in encodings: print(encoding.ljust(widths[encoding] * 2), end='\t') print() for lineno, char in enumerate(chars): codepoint = 'U+{:04X}'.format(ord(char)) print(char, codepoint, sep='\t', end='\t') for encoding in encodings: try: bytes = char.encode(encoding) dump = ' '.join('%02X' % byte for byte in bytes) except UnicodeEncodeError: dump = missing_mark dump = dump.ljust(widths[encoding] * 2) print(dump, end='\t') # print(chr(callout1_code + lineno)) print(unicodedata.name(char)) # print() #list_chars()
def show_usage(name): usage = """ Usage: %s script where script is a number between 1-9 1 - devnag 2 - bengali / assamese 3 - punjabi 4 - gujarati 5 - oriya 6 - tamil 7 - telugu 8 - kannada 9 - malayalam the program reads from stdin and writes to stdout any msgs to the user (error msgs etc) are printed on stderr """ % (name) logging.info(sys.stderr, usage) sys.exit(1)
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
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
def member(self, ctx, member : discord.Member = None): """Retrieves information about a member of the guild.""" async with ctx.typing(): member = member or ctx.author icon_url = member.avatar_url_as(static_format='png') e = discord.Embed(type='rich', color=member.color) e.set_thumbnail(url=icon_url) e.add_field(name='Name', value=str(member)) e.add_field(name='ID', value=member.id) e.add_field(name='Nickname', value=member.nick) e.add_field(name='Bot Created' if member.bot else 'User Joined Discord', value=member.created_at.strftime(datetime_format)) e.add_field(name='Joined Guild', value=member.joined_at.strftime(datetime_format)) e.add_field(name='Color', value=str(member.color).upper()) e.add_field(name='Status and Game', value='%s, playing %s' % (str(member.status).title(), member.game), inline=False) roles = sorted(member.roles)[1:] # Remove @everyone roles.reverse() e.add_field(name='Roles', value=', '.join(role.name for role in roles) or 'None', inline=False) e.add_field(name='Icon URL', value=icon_url, inline=False) await ctx.send(embed=e)
def guild(self, ctx): """Retrieves information about this guild.""" guild = ctx.guild e = discord.Embed(type='rich', color=blurple) e.set_thumbnail(url=guild.icon_url) e.add_field(name='Name', value=guild.name) e.add_field(name='ID', value=guild.id) e.add_field(name='Created at', value=guild.created_at.strftime(datetime_format)) e.add_field(name='Owner', value=guild.owner) e.add_field(name='Members', value=guild.member_count) e.add_field(name='Channels', value=len(guild.channels)) e.add_field(name='Roles', value=len(guild.role_hierarchy)-1) # Remove @everyone e.add_field(name='Emoji', value=len(guild.emojis)) e.add_field(name='Region', value=guild.region.name) e.add_field(name='Icon URL', value=guild.icon_url or 'This guild has no icon.') await ctx.send(embed=e)
def unicode_name_matches(self, text): u"""Match Latex-like syntax for unicode characters base on the name of the character. This does ``\\GREEK SMALL LETTER ETA`` -> ``?`` Works only on valid python 3 identifier, or on combining characters that will combine to form a valid identifier. Used on Python 3 only. """ slashpos = text.rfind('\\') if slashpos > -1: s = text[slashpos+1:] try : unic = unicodedata.lookup(s) # allow combining chars if ('a'+unic).isidentifier(): return '\\'+s,[unic] except KeyError: pass return u'', []
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 ("x", "\u3042", "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
def test_hangul_syllables(self): self.checkletter("HANGUL SYLLABLE GA", "\uac00") self.checkletter("HANGUL SYLLABLE GGWEOSS", "\uafe8") self.checkletter("HANGUL SYLLABLE DOLS", "\ub3d0") self.checkletter("HANGUL SYLLABLE RYAN", "\ub7b8") self.checkletter("HANGUL SYLLABLE MWIK", "\ubba0") self.checkletter("HANGUL SYLLABLE BBWAEM", "\ubf88") self.checkletter("HANGUL SYLLABLE SSEOL", "\uc370") self.checkletter("HANGUL SYLLABLE YI", "\uc758") self.checkletter("HANGUL SYLLABLE JJYOSS", "\ucb40") self.checkletter("HANGUL SYLLABLE KYEOLS", "\ucf28") self.checkletter("HANGUL SYLLABLE PAN", "\ud310") self.checkletter("HANGUL SYLLABLE HWEOK", "\ud6f8") self.checkletter("HANGUL SYLLABLE HIH", "\ud7a3") import unicodedata self.assertRaises(ValueError, unicodedata.name, "\ud7a4")
def test_strict_error_handling(self): # bogus character name self.assertRaises( UnicodeError, str, b"\\N{blah}", 'unicode-escape', 'strict' ) # long bogus character name self.assertRaises( UnicodeError, str, bytes("\\N{%s}" % ("x" * 100000), "ascii"), 'unicode-escape', 'strict' ) # missing closing brace self.assertRaises( UnicodeError, str, b"\\N{SPACE", 'unicode-escape', 'strict' ) # missing opening brace self.assertRaises( UnicodeError, str, b"\\NSPACE", 'unicode-escape', 'strict' )
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
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")
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' )
def _change_flowbox_font(self): ''' Update the font and fontsize used in the current content of the flowbox. ''' for flowbox_child in self._flowbox.get_children(): label = flowbox_child.get_child().get_child() text = label.get_label() (emoji, name) = self._parse_emoji_and_name_from_text(text) if emoji: new_text = ( '<span font="%s %s" fallback="%s">' %(self._font, self._fontsize, str(self._fallback).lower()) + html.escape(emoji) + '</span>') if name: new_text += ( '<span fallback="false" font="%s">' %(self._fontsize / 2) + html.escape(name) + '</span>') label.set_text(new_text) label.set_use_markup(True) self.show_all() self._busy_stop()
def test_hangul_syllables(self): self.checkletter("HANGUL SYLLABLE GA", "\uac00") self.checkletter("HANGUL SYLLABLE GGWEOSS", "\uafe8") self.checkletter("HANGUL SYLLABLE DOLS", "\ub3d0") self.checkletter("HANGUL SYLLABLE RYAN", "\ub7b8") self.checkletter("HANGUL SYLLABLE MWIK", "\ubba0") self.checkletter("HANGUL SYLLABLE BBWAEM", "\ubf88") self.checkletter("HANGUL SYLLABLE SSEOL", "\uc370") self.checkletter("HANGUL SYLLABLE YI", "\uc758") self.checkletter("HANGUL SYLLABLE JJYOSS", "\ucb40") self.checkletter("HANGUL SYLLABLE KYEOLS", "\ucf28") self.checkletter("HANGUL SYLLABLE PAN", "\ud310") self.checkletter("HANGUL SYLLABLE HWEOK", "\ud6f8") self.checkletter("HANGUL SYLLABLE HIH", "\ud7a3") self.assertRaises(ValueError, unicodedata.name, "\ud7a4")
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)
def charinfo(self, *, characters: str): """Shows you information about a number of characters. Only up to 15 characters at a time. """ if len(characters) > 15: await self.bot.say('Too many characters ({}/15)'.format(len(characters))) return def to_string(c): digit = format(ord(c), 'x') name = unicodedata.name(c, 'Name not found.') return '`0x{0}`: {1} - {2} \N{EM DASH} <http://www.fileformat.info/info/unicode/char/{0}>'.format(digit, name, c) await self.bot.say('\n'.join(map(to_string, characters)))
def merge_ams(amsmath, amshelp, lshort): for amsk, amsv in chain(amsmath.items(), amshelp.items()): if amsk not in lshort: lshort.update({amsk: amsv}) continue lvdict = lshort[amsk] for k, v in amsv.items(): # Can't just check ``__contains__`` here bec. some vals are None. if k not in lvdict or (v in lvdict[k] if is_seq(lvdict[k]) else v == lvdict[k]): continue if k not in ('name', 'meta'): lvdict.update({k: enlist(v, lvdict[k])}) elif k == 'meta' and v is not None: if lvdict['meta'] is None: lvdict['meta'] = {} for mk, mv in v.items(): if mk not in lvdict['meta']: lvdict['meta'].update({mk: mv}) else: # This doesn't run, but add concat logic if that # ever changes. pass else: assert v is None
def main(): # ????????????Unicode??,???????????? print("A") print("\u0041") print("\N{LATIN CAPITAL LETTER A}") # ????????encode()???????????????? print("\u00A1Help!") print("\u00A1Help!".encode("utf-8")) print(b"\xc2\xa1Help!".decode("utf-8")) # unicodedata??,???????????????.???????????Unicode?????. # ????unicodedata??,???????????Unicode?????.?????????????????. # ??????????????,??????????UTF-8 data = b"\xd9\x85\xd8\xb1\xd8\xad\xd8\xa8\xd8\xa7\xd8\xa3\xd9\x84\xd8\xa7\xd9\x86" print(data.decode("utf-8")) # ?ud.name()?????????,?????? for ch in data.decode("utf-8"): print(ord(ch), ud.name(ch))
def global_matches(self, text): """Compute matches when text is a simple name. Return a list of all keywords, built-in functions and names currently defined in self.namespace or self.global_namespace that match. """ matches = [] match_append = matches.append n = len(text) for lst in [keyword.kwlist, builtin_mod.__dict__.keys(), self.namespace.keys(), self.global_namespace.keys()]: for word in lst: if word[:n] == text and word != "__builtins__": match_append(word) return [cast_unicode_py2(m) for m in matches]
def python_matches(self, text): """Match attributes or global python names""" if "." in text: try: matches = self.attr_matches(text) if text.endswith('.') and self.omit__names: if self.omit__names == 1: # true if txt is _not_ a __ name, false otherwise: no__name = (lambda txt: re.match(r'.*\.__.*?__',txt) is None) else: # true if txt is _not_ a _ name, false otherwise: no__name = (lambda txt: re.match(r'\._.*?',txt[txt.rindex('.'):]) is None) matches = filter(no__name, matches) except NameError: # catches <undefined attributes>.<tab> matches = [] else: matches = self.global_matches(text) return matches
def MasterInfo(): for i in range (0, 30): try: print "Name" + ":" + " " + current_font.masters[i].name print "id" + ":" + " " + current_font.masters[i].id print "weight" + ":" + " " + current_font.masters[i].weight print "width" + ":" + " " + current_font.masters[i].width print current_font.masters[i].weightValue #object type: Float print current_font.masters[i].widthValue #object type: Float print current_font.masters[i].customName print current_font.masters[i].customValue print current_font.masters[i].italicAngle except AttributeError: number_fonts = str(i) print ("Total number of masters in font:" + " " + number_fonts) break
def drawInfo(): #Font Name, Designer and Glyphname on every page font("System Font Bold") fontSize(10) text(current_font.familyName + " " + "by" + " " + str(current_font.designer), (0, 0)) glyph_name = current_glyph.name #new variable because to avoid conflict and confusion font("System Font Light") translate(0, - 12) uni_glyph = current_glyph.string print current_glyph.string try: text(unicodedata.name(uni_glyph), (0, 0)) except: print 'No Name' translate(0, - 12) text(glyph_name, (0, 0)) translate(0, - 12) text('0x' + current_font.glyphs['A'].unicode, (0, 0))
def command_chars(string, vargs): """ Print a list of all IPA characters in the given string. It will print the Unicode representation, the full IPA name, and the Unicode "U+"-prefixed hexadecimal codepoint representation of each IPA character. :param str string: the string to act upon :param dict vargs: the command line arguments """ try: ipa_string = IPAString( unicode_string=string, ignore=vargs["ignore"], single_char_parsing=vargs["single_char_parsing"] ) for c in ipa_string: print(u"'%s'\t%s (%s)" % (c.unicode_repr, c.name, unicode_to_hex(c.unicode_repr))) except ValueError as exc: print_error(str(exc))