def draw(self, context):
layout = self.layout
layout.label(self.bl_label)
for op, name in self.operators:
text = capwords(name.replace("_", " ")) + " (Meta-Rig)"
layout.operator(op, icon='OUTLINER_OB_ARMATURE', text=text)
python类capwords()的实例源码
def __get_song_from_list(cls, element):
ul = element.find('ul', {'class': cls.BOARD_CONTENT_CLASS})
url = ul.get(cls.SONG_URL_PROP)
id_parts = url.split('/')
song_id = id_parts[4] if len(id_parts) > 4 else None
title_item = ul.find('li', {'class': cls.SONG_TITLE_CLASS})
title = capwords(title_item.text) if title_item else None
artist_item = ul.find('li', {'class': cls.SONG_ARTIST_CLASS})
artist = capwords(artist_item.text) if artist_item else None
bit_rate = ul.find('li', {'class': cls.SONG_BIT_RATE_CLASS}).text
bit_rate_parts = bit_rate.split()
bit_rate = bit_rate_parts[0] if bit_rate_parts else None
length = ul.find('li', {'class': cls.SONG_LENGTH_CLASS}).text
length = Song.get_length_from_string(length)
song_dict = {
'song_id': song_id,
'title': title,
'artist': artist,
'bit_rate': bit_rate,
'length': length,
'url': url
}
return Song(**song_dict)
def addHeader (self,key,value):
k=string.capwords(key,"-")
if k.lower() not in ["accept-encoding","content-length","if-modified-since","if-none-match"]:
self._headers[k]=value
def delHeader (self,key):
k = string.capwords(key,"-")
if self._headers.has_key(k):
del self._headers[k]
def __getitem__ (self,key):
k=string.capwords(key,"-")
if k in self._headers:
return self._headers[k]
else:
return ""
def addHeader (self,key,value):
k=string.capwords(key,"-")
self._headers+=[(k,value)]
def method_for(self, name):
"""Return the MWS API method referred to in the argument.
The named method can be in CamelCase or underlined_lower_case.
This is the complement to MWSConnection.any_call.action
"""
action = '_' in name and string.capwords(name, '_') or name
if action in api_call_map:
return getattr(self, api_call_map[action])
return None
def test_capwords(self):
self.assertEqual(string.capwords('abc def ghi'), 'Abc Def Ghi')
self.assertEqual(string.capwords('abc\tdef\nghi'), 'Abc Def Ghi')
self.assertEqual(string.capwords('abc\t def \nghi'), 'Abc Def Ghi')
self.assertEqual(string.capwords('ABC DEF GHI'), 'Abc Def Ghi')
self.assertEqual(string.capwords('ABC-DEF-GHI', '-'), 'Abc-Def-Ghi')
self.assertEqual(string.capwords('ABC-def DEF-ghi GHI'), 'Abc-def Def-ghi Ghi')
self.assertEqual(string.capwords(' aBc DeF '), 'Abc Def')
self.assertEqual(string.capwords('\taBc\tDeF\t'), 'Abc Def')
self.assertEqual(string.capwords('\taBc\tDeF\t', '\t'), '\tAbc\tDef\t')
def test():
string.capwords(1)
def _inforole(self, msg):
"""
provides an infodump of a role, including permissions and position
"""
try:
args = shlex.split(msg.content)
except ValueError as e:
self.logger.warning("Unable to split {data.content}. {e}")
raise CommandSyntaxError(e)
if len(args) > 1:
name = capwords(args[1])
role = find_role(msg.guild, args[1])
if role:
t_dict = {
"name": role.name,
"permissions": role.permissions,
"colour": role.colour,
"hoist": role.hoist,
"mentionable": role.mentionable,
"position": role.position,
"created_at": role.created_at,
"id": role.id
}
t_string = ""
for k, v in t_dict.items():
if k != "permissions":
t_string = f"{t_string}{k}: {v!s}\n"
else:
t_string += k + ": " + ", ".join({x.upper() for x, y in v if y}) + "\n"
await respond(msg, f"**ANALYSIS: role {role.name} has parameters :**\n ```{t_string}```")
else:
await respond(msg, f"**NEGATIVE. ANALYSIS: no role {name} found.**")
else:
raise CommandSyntaxError
def _help(self, msg):
if not self.categories:
await self.build_help()
try:
search = msg.clean_content.split(" ")[1].lower()
except IndexError:
cates = "\n".join(sorted([capwords(x, "_") for x in self.categories.keys()]))
await respond(msg, f"**ANALYSIS: Command categories:**```\n{cates}\n```")
return
if search in [x.lower() for x in self.commands.keys()]:
cmd = self.commands[search]
name = cmd.name
syn = cmd.syntax
if not syn:
syn = "N/A"
doc = cmd.__doc__
perms = cmd.perms
cate = capwords(cmd.category, "_")
aliases = f"(Aliases: {', '.join(cmd.aliases)})" if cmd.aliases else ""
if not {x for x, y in msg.author.guild_permissions if y} >= perms:
raise UserPermissionError
text = f"**ANALYSIS: Command {name}:**```\n{name} (Category {cate}) {aliases}\n\n{doc}\n\n" \
f"Syntax: {syn}\n```"
await respond(msg, text)
elif search in self.categories.keys():
name = capwords(search, "_")
userperms = {x for x, y in msg.author.guild_permissions if y}
cmds = {x.name for x in self.categories[search].values() if userperms >= x.perms}
cmds = sorted(list(cmds))
if cmds:
text = "\n".join(cmds)
await respond(msg, f"**ANALYSIS: Category {name}:**```\n{text}\n```")
else:
await respond(msg, "**WARNING: You do not have permission for any command in this category.**")
else:
await respond(msg, f"**WARNING: No such category or command {search}**")
def country_from_name(name):
countrydict = COUNTRY_DICT
is_country_in_here = [x for x in countrydict.keys() if x in name.lower()]
country = ''
if is_country_in_here:
country = string.capwords(is_country_in_here[0])
return country
def _processFormal(self, elem, sessionID):
"""Process a <formal> AIML element.
<formal> elements process their contents recursively, and then
capitalize the first letter of each word of the result.
"""
response = ""
for e in elem[2:]:
response += self._processElement(e, sessionID)
return string.capwords(response)
# <gender>
def __setitem__(self, i, y):
self._regexIsDirty = True
# for each entry the user adds, we actually add three entrys:
super(type(self), self).__setitem__(string.lower(i), string.lower(y)) # key = value
super(type(self), self).__setitem__(string.capwords(i), string.capwords(y)) # Key = Value
super(type(self), self).__setitem__(string.upper(i), string.upper(y)) # KEY = VALUE
def test_capwords(self):
self.assertEqual(string.capwords('abc def ghi'), 'Abc Def Ghi')
self.assertEqual(string.capwords('abc\tdef\nghi'), 'Abc Def Ghi')
self.assertEqual(string.capwords('abc\t def \nghi'), 'Abc Def Ghi')
self.assertEqual(string.capwords('ABC DEF GHI'), 'Abc Def Ghi')
self.assertEqual(string.capwords('ABC-DEF-GHI', '-'), 'Abc-Def-Ghi')
self.assertEqual(string.capwords('ABC-def DEF-ghi GHI'), 'Abc-def Def-ghi Ghi')
self.assertEqual(string.capwords(' aBc DeF '), 'Abc Def')
self.assertEqual(string.capwords('\taBc\tDeF\t'), 'Abc Def')
self.assertEqual(string.capwords('\taBc\tDeF\t', '\t'), '\tAbc\tDef\t')
def test_capwords(self):
self.assertEqual(string.capwords('abc def ghi'), 'Abc Def Ghi')
self.assertEqual(string.capwords('abc\tdef\nghi'), 'Abc Def Ghi')
self.assertEqual(string.capwords('abc\t def \nghi'), 'Abc Def Ghi')
self.assertEqual(string.capwords('ABC DEF GHI'), 'Abc Def Ghi')
self.assertEqual(string.capwords('ABC-DEF-GHI', '-'), 'Abc-Def-Ghi')
self.assertEqual(string.capwords('ABC-def DEF-ghi GHI'), 'Abc-def Def-ghi Ghi')
self.assertEqual(string.capwords(' aBc DeF '), 'Abc Def')
self.assertEqual(string.capwords('\taBc\tDeF\t'), 'Abc Def')
self.assertEqual(string.capwords('\taBc\tDeF\t', '\t'), '\tAbc\tDef\t')
def _show_classes(self, rule_type):
"""????rule_type?????????????"""
import string
plogger.info(os.linesep + '# {}?findkey??'.format(string.capwords(rule_type)))
for findkey in sorted(SimpleFinder.getinstance().find_class_all(rule_type).keys()):
plogger.info('- ' + findkey)
def test_capwords(self):
self.assertEqual(string.capwords('abc def ghi'), 'Abc Def Ghi')
self.assertEqual(string.capwords('abc\tdef\nghi'), 'Abc Def Ghi')
self.assertEqual(string.capwords('abc\t def \nghi'), 'Abc Def Ghi')
self.assertEqual(string.capwords('ABC DEF GHI'), 'Abc Def Ghi')
self.assertEqual(string.capwords('ABC-DEF-GHI', '-'), 'Abc-Def-Ghi')
self.assertEqual(string.capwords('ABC-def DEF-ghi GHI'), 'Abc-def Def-ghi Ghi')
self.assertEqual(string.capwords(' aBc DeF '), 'Abc Def')
self.assertEqual(string.capwords('\taBc\tDeF\t'), 'Abc Def')
self.assertEqual(string.capwords('\taBc\tDeF\t', '\t'), '\tAbc\tDef\t')
def _processFormal(self, elem, sessionID):
"""Process a <formal> AIML element.
<formal> elements process their contents recursively, and then
capitalize the first letter of each word of the result.
"""
response = ""
for e in elem[2:]:
response += self._processElement(e, sessionID)
return string.capwords(response)
# <gender>
def __setitem__(self, i, y):
self._regexIsDirty = True
# for each entry the user adds, we actually add three entrys:
super(type(self),self).__setitem__(i.lower(),y.lower()) # key = value
super(type(self),self).__setitem__(string.capwords(i), string.capwords(y)) # Key = Value
super(type(self),self).__setitem__(i.upper(), y.upper()) # KEY = VALUE