1#!/usr/bin/env python 2 3import logging 4logger = logging.getLogger(__name__) 5 6import os 7logging.basicConfig(level=logging.DEBUG) 8logging.getLogger('spyne.protocol.xml').setLevel(logging.DEBUG) 9 10from spyne.application import Application 11from spyne.decorator import rpc 12from spyne.service import ServiceBase 13from spyne.model.complex import ComplexModel 14from spyne.model.binary import ByteArray 15from spyne.model.primitive import Unicode 16from spyne.server.wsgi import WsgiApplication 17from spyne.protocol.soap import Soap12 18 19 20tns = 'http://gib.gov.tr/vedop3/eFatura' 21 22 23class documentResponse(ComplexModel): 24 msg = Unicode 25 hash = ByteArray 26 27 28class GIBSoapService(ServiceBase): 29 @rpc(Unicode(sub_name="fileName"), ByteArray(sub_name='binaryData'), 30 ByteArray(sub_name="hash"), _returns=documentResponse) 31 def documentRequest(ctx, file_name, file_data, data_hash): 32 incoming_invoice_dir = os.getcwd() 33 34 logger.info("file_name %r" % file_name) 35 logger.info("file_hash: %r" % data_hash) 36 37 path = os.path.join(incoming_invoice_dir, file_name) 38 39 f = open(path, 'wb') 40 for data in file_data: 41 f.write(data) 42 logger.info("File written: %r" % file_name) 43 f.close() 44 45 resp = documentResponse() 46 resp.msg = "Document was written successfully" 47 resp.hash = data_hash 48 49 return resp 50 51 52application = Application([GIBSoapService], tns=tns, 53 in_protocol=Soap12(), 54 out_protocol=Soap12()) 55 56 57gib_application = WsgiApplication(application) 58 59 60from wsgiref.simple_server import make_server 61 62 63server = make_server('0.0.0.0', 8000, gib_application) 64server.serve_forever() 65