def check_eu_vat_id(vatid): """Check an EU VAT ID string (of the form: FI01234567) and return True if it is currently valid. """ from twisted.internet import defer def _success(res): vat_valid = False if hasattr(res, 'valid'): if res.valid == 1: return True return False def _failure(reason): _log.warning('Warning: VAT ID check failed, reason: %s' % reason) return False try: vat_cc, vat_no = split_eu_vat_id(vatid) # FIXME: should Proxy be reused??? soap_uri = 'http://ec.europa.eu/taxation_customs/vies/api/checkVatPort' p = soap.Proxy(soap_uri) d = p.callRemote('checkVat', countryCode=vat_cc, vatNumber=vat_no) d.addCallbacks(_success, _failure) return d except: # XXX: we don't want to catch import failures at least... _log.exception('VAT ID check failed') return defer.succeed(False)
def setupClient(self, url=None, encrypt=False): """Sets up a simple twisted soap client. Server has to be started. If url is not given, encrypt can be set for connecting through https.""" if not url: host = self.server.port.getHost() if encrypt: proto = 'https' else: proto = 'http' url = '%s://%s:%d/SOAP/?wsdl' % (proto, host.host, host.port) return soap.Proxy(url)
def proxy(self): return soap.Proxy("http://localhost:%d/" % self.port)
def proxy(self): return soap.Proxy("http://127.0.0.1:%d/" % self.port)