def test_batch_error(self): fobj = self.find_group(self.gid) con0 = GCContact(fobj) con0.set_firstname('Namo Narayananaya') gce0 = con0.get_gce() con = GCContact(fobj) con.set_firstname('Ayeshwarya') con.set_birthday('abcd"ef') # con.set_anniv('1978-05-31 %s est n il y a %d ans') # con.set_birthday('1980-08-10') gce = con.get_gce() feed = self.pimdb.new_feed() feed.add_insert(entry=gce0, batch_id_string="DeadBeef") feed.add_insert(entry=gce0, batch_id_string="DeadBeef") feed.add_insert(entry=gce, batch_id_string="DeadBeef") b = BatchState(1, feed, op='insert', sync_tag="asynk:testgcex:ex") print 'Request: ', utils.pretty_xml(str(feed)) rr = self.pimdb.exec_batch(feed) print 'Response: ', utils.pretty_xml(str(rr)) for entry in rr.entry: print entry.batch_status if entry.batch_status: print 'Code: ', entry.batch_status.code print 'Reason: ', entry.batch_status.reason else: self.handle_interrupted_feed(feed, str(rr))
def to_xml(self): rs = self.to_dict() report = ElementTree.Element('report') attrs = { 'pos': None, 'name': None, 'detail': None, 'level': None } total = { 'Warning': 0, 'Error': 0, 'Info': 0 } for (file, module_name), records in rs.items(): module = ElementTree.Element('module', {'name': module_name, 'file': file}) for record in sorted(records): attrs['pos'] = str(record.pos) attrs['name'] = str(record.check_item).upper() level = str(record.check_item.level) attrs['level'] = level total[level] += 1 attrs['detail'] = record.check_item.notice % record.extra ElementTree.SubElement(module, 'item', attrs) # reset attrs for k, v in attrs.items(): attrs[k] = None for key, value in total.items(): module.set(key, str(value)) total[key] = 0 report.append(module) utils.pretty_xml(report, indent=' ' * 4, newline='\n') return report
def test_batch_error (self): fobj = self.find_group(self.gid) con0 = GCContact(fobj) con0.set_firstname('Namo Narayananaya') gce0 = con0.get_gce() con = GCContact(fobj) con.set_firstname('Ayeshwarya') con.set_birthday('abcd"ef') # con.set_anniv('1978-05-31 %s est n il y a %d ans') # con.set_birthday('1980-08-10') gce = con.get_gce() feed = self.pimdb.new_feed() feed.add_insert(entry=gce0, batch_id_string="DeadBeef") feed.add_insert(entry=gce0, batch_id_string="DeadBeef") feed.add_insert(entry=gce, batch_id_string="DeadBeef") b = BatchState(1, feed, op='insert', sync_tag="asynk:testgcex:ex") print 'Request: ', utils.pretty_xml(str(feed)) rr = self.pimdb.exec_batch(feed) print 'Response: ', utils.pretty_xml(str(rr)) for entry in rr.entry: print entry.batch_status if entry.batch_status: print 'Code: ',entry.batch_status.code print 'Reason: ', entry.batch_status.reason else: self.handle_interrupted_feed(feed, str(rr))
def __call__(self, parser, namespace, value, option_string=None): config = read_config_file() format = namespace.format if namespace.format else config.get('DEFAULT','format') oauth = config.getboolean('DEFAULT','oauth') # Checking ig OAuth params are defined if oauth : oauth = YOAuth(None, None, from_file=config.get('auth','from_file')) attr = { 'community': True, 'format': format, #'jsonCompact': namespace.jsonCompact if namespace.jsonCompact else config.getboolean(format, 'jsonCompact'), 'debug': namespace.debug if namespace.debug else config.getboolean(format, 'debug'), 'oauth': oauth } yql = MYQL(**attr) yql.diagnostics = namespace.diagnostics if namespace.diagnostics else config.getboolean(format, 'diagnostics') for v in value: response = yql.rawQuery(v) if not response.status_code == 200: print(response.content) sys.exit(1) if format == 'json': print(pretty_json(response.content)) else: print(pretty_xml(response.content)) sys.exit(0)
def Show(self, *args, **kwargs): typ = args[0] s = args[1] action = args[2] if action in ["got", "sent"]: try: xml_s = utils.pretty_xml(s) except: xml_s = s log_string = "[%s/%s] %s stanza(s):\n%s" % (typ, action, action, xml_s) logger.debug(log_string) elif typ not in ["nodebuilder", "dispatcher"]: logger.debug("[%s/%s] %s" % (typ, action, s))
def Show(self, *args, **kwargs): typ = args[0] s = args[1] action = args[2] if action in ['got', 'sent']: try: xml_s = utils.pretty_xml(s) except: xml_s = s log_string = '[%s/%s] %s stanza(s):\n%s' % (typ, action, action, xml_s) logger.debug(log_string) elif typ not in ['nodebuilder', 'dispatcher']: logger.debug('[%s/%s] %s' % (typ, action, s))
def handle_interrupted_feed (self, resp_xml): resp = ET.fromstring(resp_xml) ffc = utils.find_first_child resp_title = ffc(resp, utils.QName_GNS0('title'), ret='node').text resp_intr = ffc(resp, utils.QName_GNS3('interrupted'), ret='node') parsed = int(resp_intr.attrib['parsed']) reason = resp_intr.attrib['reason'] entry = self.f.entry[parsed] logging.error('The server encountered a %s while processing ' + 'the feed. The reason given is: %s', resp_title, resp_intr) logging.error('The problematic entry is likely this one: %s', utils.pretty_xml(str(entry)))
def handle_interrupted_feed(self, feed, resp_xml): resp = ET.fromstring(resp_xml) ffc = utils.find_first_child resp_title = ffc(resp, utils.QName_GNS0('title'), ret='node').text resp_intr = ffc(resp, utils.QName_GNS3('interrupted'), ret='node') parsed = int(resp_intr.attrib['parsed']) reason = resp_intr.attrib['reason'] entry = feed.entry[parsed] logging.error( 'The server encountered a %s while processing ' + 'the feed. The reason given is: %s', resp_title, resp_intr) logging.error('The problematic entry is likely this one: %s', utils.pretty_xml(str(entry)))
def to_sld(self): sld = ET.Element("StyledLayerDescriptor") sld.attrib["version"] = "1.0.0" sld.attrib["xsi:schemaLocation"] = "http://www.opengis.net/sld StyledLayerDescriptor.xsd" sld.attrib["xmlns"] = "http://www.opengis.net/sld" sld.attrib["xmlns:ogc"] = "http://www.opengis.net/ogc" sld.attrib["xmlns:xlink"] = "http://www.w3.org/1999/xlink" sld.attrib["xmlns:xsi"] = "http://www.w3.org/2001/XMLSchema-instance" named_layer = ET.SubElement(sld, "NamedLayer") name = ET.SubElement(named_layer, "Name") name.text = self.layer_name user_style = ET.SubElement(named_layer, "UserStyle") feature_type_style = ET.SubElement(user_style, "FeatureTypeStyle") for renderer in self.renderers: feature_type_style.extend(list(renderer.to_sld())) return pretty_xml(sld)
def send (self, request, debug=False): """ Send the given rquest to the server, and return the response text as well as a parsed node object as a (resp.text, node) tuple. The response text is the raw xml including the soap headers and stuff. """ try: r = requests.post(self.url, auth=self.auth, data=request, headers={'Content-Type':'text/xml; charset=utf-8', "Accept": "text/xml"}, verify=self.cert) except requests.exceptions.ConnectionError as e: raise SoapConnectionError(e) if debug: logging.debug('%s', pretty_xml(r.text)) return SoapClient.parse_xml(r.text.encode('utf-8'))
def send(self, request, debug=False): """ Send the given rquest to the server, and return the response text as well as a parsed node object as a (resp.text, node) tuple. The response text is the raw xml including the soap headers and stuff. """ try: r = requests.post(self.url, auth=self.auth, data=request, headers={ 'Content-Type': 'text/xml; charset=utf-8', "Accept": "text/xml" }) except requests.exceptions.ConnectionError as e: raise SoapConnectionError(e) if debug: logging.debug('%s', pretty_xml(r.text)) return SoapClient.parse_xml(r.text)
def to_axl(self): return pretty_xml(self.layer_node)