本文整理匯總了Python中weboob.tools.ordereddict.OrderedDict.keys方法的典型用法代碼示例。如果您正苦於以下問題:Python OrderedDict.keys方法的具體用法?Python OrderedDict.keys怎麽用?Python OrderedDict.keys使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類weboob.tools.ordereddict.OrderedDict
的用法示例。
在下文中一共展示了OrderedDict.keys方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: format
# 需要導入模塊: from weboob.tools.ordereddict import OrderedDict [as 別名]
# 或者: from weboob.tools.ordereddict.OrderedDict import keys [as 別名]
def format(self, obj, selected_fields=None):
"""
Format an object to be human-readable.
An object has fields which can be selected.
If the object provides an iter_fields() method, the formatter will
call it. It can be used to specify the fields order.
@param obj [object] object to format
@param selected_fields [tuple] fields to display. If None, all fields are selected
@return a string of the formatted object
"""
assert isinstance(obj, (dict, CapBaseObject, tuple))
if isinstance(obj, dict):
item = obj
elif isinstance(obj, tuple):
item = OrderedDict([(k, v) for k, v in obj])
else:
item = self.to_dict(obj, selected_fields)
if item is None:
return None
if self.MANDATORY_FIELDS:
missing_fields = set(self.MANDATORY_FIELDS) - set(item.keys())
if missing_fields:
raise MandatoryFieldsNotFound(missing_fields)
formatted = self.format_dict(item=item)
if formatted:
self.after_format(formatted)
return formatted
示例2: on_loaded
# 需要導入模塊: from weboob.tools.ordereddict import OrderedDict [as 別名]
# 或者: from weboob.tools.ordereddict.OrderedDict import keys [as 別名]
def on_loaded(self):
for script in self.document.xpath('//script'):
text = script.text
if text is None:
continue
m = re.search("window.location.replace\('([^']+)'\);", text)
if m:
self.browser.location(m.group(1))
try:
self.browser.select_form(name='banque')
except FormNotFoundError:
pass
else:
self.browser.set_all_readonly(False)
accounts = OrderedDict()
for tr in self.document.getroot().cssselect('table.compteTable > tbody > tr'):
if len(tr.findall('td')) == 0:
continue
attr = tr.xpath('.//a')[0].attrib.get('onclick', '')
m = re.search("value = '(\w+)';(checkAndSubmit\('\w+','(\w+)','(\w+)'\))?", attr)
if m:
typeCompte = m.group(1)
tagName = m.group(3)
if tagName is not None:
value = self.document.xpath('//input[@name="%s"]' % m.group(3))[int(m.group(4))].attrib['value']
else:
value = typeCompte
accounts[value] = (typeCompte, tagName)
try:
typeCompte, tagName = accounts[self.browser.accnum]
value = self.browser.accnum
except KeyError:
accnums = ', '.join(accounts.keys())
if self.browser.accnum != '00000000000':
self.logger.warning(u'Unable to find account "%s". Available ones: %s' % (self.browser.accnum, accnums))
elif len(accounts) > 1:
self.logger.warning('There are several accounts, please use "accnum" backend parameter to force the one to use (%s)' % accnums)
value, (typeCompte, tagName) = accounts.popitem(last=False)
self.browser['typeCompte'] = typeCompte
if tagName is not None:
self.browser[tagName] = [value]
self.browser.submit()