text
stringlengths
0
828
self._to_xml(xml, value, key)
xml.endElement(key)
else:
xml.characters(smart_unicode(data))"
4690,"def startElement(self, name, attrs):
"""""" Initialize new node and store current node into stack. """"""
self.stack.append((self.current, self.chardata))
self.current = {}
self.chardata = []"
4691,"def endElement(self, name):
"""""" End current xml element, parse and add to to parent node. """"""
if self.current:
# we have nested elements
obj = self.current
else:
# text only node
text = ''.join(self.chardata).strip()
obj = self._parse_node_data(text)
newcurrent, self.chardata = self.stack.pop()
self.current = self._element_to_node(newcurrent, name, obj)"
4692,"def _parse_node_data(self, data):
"""""" Parse the value of a node. Override to provide your own parsing. """"""
data = data or ''
if self.numbermode == 'basic':
return self._try_parse_basic_number(data)
elif self.numbermode == 'decimal':
return self._try_parse_decimal(data)
else:
return data"
4693,"def _try_parse_basic_number(self, data):
"""""" Try to convert the data into ``int`` or ``float``.
:returns: ``Decimal`` or ``data`` if conversion fails.
""""""
# try int first
try:
return int(data)
except ValueError:
pass
# try float next
try:
return float(data)
except ValueError:
pass
# no luck, return data as it is
return data"
4694,"def _element_to_node(self, node, name, value):
"""""" Insert the parsed element (``name``, ``value`` pair) into the node.
You should always use the returned node and forget the one
that was given in parameter.
:param node: the node where the is added to
:returns: the node. Note that this may be a new node instance.
""""""
# is the target node a list?
try:
node.append(value)
except AttributeError:
pass
else:
return node
# target node is a dict
if name in node:
# there's already an element with same name -> convert the node into list
node = node.values() + [value]
else:
# just add the value into the node
node[name] = value
return node"
4695,"def _get_programs_dict(pkgname_only, flag_protected, flag_no_pfant=False):
""""""Returns dictionary {(package description): [ExeInfo0, ...], ...}""""""
allinfo = f311.get_programs_dict(pkgname_only, flag_protected)
if not flag_no_pfant and ""pyfant"" in allinfo:
_add_PFANT(allinfo)
return allinfo"
4696,"def apize_raw(url, method='GET'):
""""""
Convert data and params dict -> json.
""""""
def decorator(func):
def wrapper(*args, **kwargs):
elem = func(*args, **kwargs)
if type(elem) is not dict:
raise BadReturnVarType(func.__name__)
response = send_request(url, method,
elem.get('data', {}),
elem.get('args', {}),
elem.get('params', {}),
elem.get('headers', {}),
elem.get('cookies', {}),
elem.get('timeout', 8),
elem.get('is_json', False),
elem.get('verify_cert', True)