def serializar(regs): "Dado una lista de comprobantes (diccionarios), convierte a xml" xml = SimpleXMLElement(XML_BASE) comprobantes = [] for reg in regs: dic = {} for k, v in list(MAP_ENC.items()): dic[v] = reg[k] dic.update({ 'detalles': [{ 'detalle': mapear({}, det, MAP_DET, swap=True), } for det in reg['detalles']], 'tributos': [{ 'tributo': mapear({}, trib, MAP_TRIB, swap=True), } for trib in reg['tributos']], 'ivas': [{ 'iva': mapear({}, iva, MAP_IVA, swap=True), } for iva in reg['ivas']], 'formaspago': [{ 'formapago': { 'codigo': '', 'descripcion': reg['forma_pago'], }}] }) comprobantes.append(dic) for comprobante in comprobantes: xml.marshall("comprobante", comprobante) return xml.as_xml()
def serializar(regs): "Dado una lista de comprobantes (diccionarios), convierte a xml" xml = SimpleXMLElement(XML_BASE) comprobantes = [] for reg in regs: dic = {} for k, v in MAP_ENC.items(): dic[v] = reg[k] dic.update({ 'detalles': [{ 'detalle': mapear({}, det, MAP_DET, swap=True), } for det in reg['detalles']], 'tributos': [{ 'tributo': mapear({}, trib, MAP_TRIB, swap=True), } for trib in reg['tributos']], 'ivas': [{ 'iva': mapear({}, iva, MAP_IVA, swap=True), } for iva in reg['ivas']], 'formaspago': [{ 'formapago': { 'codigo': '', 'descripcion': reg['forma_pago'], }}] }) comprobantes.append(dic) for comprobante in comprobantes: xml.marshall("comprobante", comprobante) return xml.as_xml()
def get_bugs(*key_value): """Get list of bugs matching certain criteria. The conditions are defined by key value pairs. Possible keys are: * "package": bugs for the given package * "submitter": bugs from the submitter * "maint": bugs belonging to a maintainer * "src": bugs belonging to a source package * "severity": bugs with a certain severity * "status": can be either "done", "forwarded", or "open" * "tag": see http://www.debian.org/Bugs/Developer#tags for available tags * "owner": bugs which are assigned to `owner` * "bugs": takes single int or list of bugnumbers, filters the list according to given criteria * "correspondent": bugs where `correspondent` has sent a mail to Arguments --------- key_value : str Returns ------- bugs : list of ints the bugnumbers Examples -------- >>> get_bugs('package', 'gtk-qt-engine', 'severity', 'normal') [12345, 23456] """ # previous versions also accepted # get_bugs(['package', 'gtk-qt-engine', 'severity', 'normal']) # if key_value is a list in a one elemented tuple, remove the # wrapping list if len(key_value) == 1 and isinstance(key_value[0], list): key_value = tuple(key_value[0]) # pysimplesoap doesn't generate soap Arrays without using wsdl # I build body by hand, converting list to array and using standard # pysimplesoap marshalling for other types method_el = SimpleXMLElement('<get_bugs></get_bugs>') for arg_n, kv in enumerate(key_value): arg_name = 'arg' + str(arg_n) if isinstance(kv, (list, tuple)): _build_int_array_el(arg_name, method_el, kv) else: method_el.marshall(arg_name, kv) soap_client = _build_soap_client() reply = soap_client.call('get_bugs', method_el) items_el = reply('soapenc:Array') return [int(item_el) for item_el in items_el.children() or []]
def get_bugs(*key_value): """Get list of bugs matching certain criteria. The conditions are defined by key value pairs. Possible keys are: * "package": bugs for the given package * "submitter": bugs from the submitter * "maint": bugs belonging to a maintainer * "src": bugs belonging to a source package * "severity": bugs with a certain severity * "status": can be either "done", "forwarded", or "open" * "tag": see http://www.debian.org/Bugs/Developer#tags for available tags * "owner": bugs which are assigned to `owner` * "bugs": takes single int or list of bugnumbers, filters the list according to given criteria * "correspondent": bugs where `correspondent` has sent a mail to Arguments --------- key_value : str Returns ------- bugs : list of ints the bugnumbers Examples -------- >>> get_bugs('package', 'gtk-qt-engine', 'severity', 'normal') [12345, 23456] """ # previous versions also accepted # get_bugs(['package', 'gtk-qt-engine', 'severity', 'normal']) # if key_value is a list in a one elemented tuple, remove the # wrapping list if len(key_value) == 1 and isinstance(key_value[0], list): key_value = tuple(key_value[0]) # pysimplesoap doesn't generate soap Arrays without using wsdl # I build body by hand, converting list to array and using standard # pysimplesoap marshalling for other types method_el = SimpleXMLElement('<get_bugs></get_bugs>') for arg_n, kv in enumerate(key_value): arg_name = 'arg' + str(arg_n) if isinstance(kv, (list, tuple)): _build_int_array_el(arg_name, method_el, kv) else: method_el.marshall(arg_name, kv) soap_client = _build_soap_client() reply = soap_client.call('get_bugs', method_el) items_el = reply('soapenc:Array') return [int(item_el) for item_el in items_el.children() or []]
def serializar(regs): "Dado una lista de comprobantes (diccionarios), convierte a xml" xml = SimpleXMLElement(XML_BASE) comprobantes = [] for reg in regs: dic = {} for k, v in list(MAP_ENC.items()): dic[v] = reg[k] dic.update({ "detalles": [{ "detalle": mapear({}, det, MAP_DET, swap=True), } for det in reg["detalles"]], "tributos": [{ "tributo": mapear({}, trib, MAP_TRIB, swap=True), } for trib in reg["tributos"]], "cmpasociados": [{ "cmpasociado": mapear({}, iva, MAP_CBTE_ASOC, swap=True), } for iva in reg["cbtes_asoc"]], "opcionales": [{ "opcional": mapear({}, iva, MAP_OPCIONAL, swap=True), } for iva in reg["opcionales"]], "ivas": [{ "iva": mapear({}, iva, MAP_IVA, swap=True), } for iva in reg["ivas"]], "formaspago": [{ "formapago": { "codigo": "", "descripcion": reg["forma_pago"], } }], }) comprobantes.append(dic) for comprobante in comprobantes: xml.marshall("comprobante", comprobante) return xml.as_xml()
def get_bugs(*key_value, **kwargs): """Get list of bugs matching certain criteria. The conditions are defined by the keyword arguments. Arguments --------- key_value : str Deprecated! The positional arguments are treated as key-values. This is deprecated since 2.10.0, please use the `kwargs` parameters instead. kwargs : Possible keywords are: * "package": bugs for the given package * "submitter": bugs from the submitter * "maint": bugs belonging to a maintainer * "src": bugs belonging to a source package * "severity": bugs with a certain severity * "status": can be either "done", "forwarded", or "open" * "tag": see http://www.debian.org/Bugs/Developer#tags for available tags * "owner": bugs which are assigned to `owner` * "bugs": takes single int or list of bugnumbers, filters the list according to given criteria * "correspondent": bugs where `correspondent` has sent a mail to Returns ------- bugs : list of ints the bugnumbers Examples -------- >>> get_bugs(package='gtk-qt-engine', severity='normal') [12345, 23456] """ # flatten kwargs to list: # {'foo': 'bar', 'baz': 1} -> ['foo', 'bar','baz', 1] args = [] for k, v in kwargs.items(): args.extend([k, v]) # previous versions also accepted # get_bugs(['package', 'gtk-qt-engine', 'severity', 'normal']) # if key_value is a list in a one elemented tuple, remove the # wrapping list if len(key_value) == 1 and isinstance(key_value[0], list): key_value = tuple(key_value[0]) if key_value: logger.warning('Calling get_bugs with positional arguments is' ' deprecated, please use keyword arguments instead.') args.extend(key_value) # pysimplesoap doesn't generate soap Arrays without using wsdl # I build body by hand, converting list to array and using standard # pysimplesoap marshalling for other types method_el = SimpleXMLElement('<get_bugs></get_bugs>') for arg_n, kv in enumerate(args): arg_name = 'arg' + str(arg_n) if isinstance(kv, (list, tuple)): _build_int_array_el(arg_name, method_el, kv) else: method_el.marshall(arg_name, kv) soap_client = _build_soap_client() reply = soap_client.call('get_bugs', method_el) items_el = reply('soapenc:Array') return [int(item_el) for item_el in items_el.children() or []]