2222__license__ = "LGPL-3.0-or-later"
2323__version__ = "3.01b"
2424
25- import md5 , os , sys , tempfile , traceback
25+ import os , sys , tempfile , traceback
26+ try :
27+ from hashlib import md5
28+ except ImportError :
29+ from md5 import md5
2630from pysimplesoap .simplexml import SimpleXMLElement
2731
2832from pyafipws .utils import WebClient
@@ -122,30 +126,27 @@ def ConsultarContribuyentes(self, fecha_desde, fecha_hasta, cuit_contribuyente):
122126 self .xml .contribuyentes .contribuyente .cuitContribuyente = cuit_contribuyente
123127
124128 xml = self .xml .as_xml ()
125- self .CodigoHash = md5 . md5 (xml ).hexdigest ()
129+ self .CodigoHash = md5 (xml ).hexdigest ()
126130 nombre = "DFEServicioConsulta_%s.xml" % self .CodigoHash
127131
128132 # guardo el xml en el archivo a enviar y luego lo re-abro:
129- archivo = open (os .path .join (tempfile .gettempdir (), nombre ), "w" )
130- archivo .write (xml )
131- archivo .close ()
132- archivo = open (os .path .join (tempfile .gettempdir (), nombre ), "r" )
133+ with open (os .path .join (tempfile .gettempdir (), nombre ), "wb" ) as archivo :
134+ archivo .write (xml )
133135
134136 if not self .testing :
135- response = self . client (
136- user = self . Usuario , password = self .Password , file = archivo
137- )
137+ with open ( os . path . join ( tempfile . gettempdir (), nombre ), "r" ) as archivo :
138+ response = self .client (
139+ user = self . Usuario , password = self . Password , file = archivo )
138140 else :
139- response = open (self .testing ).read ()
141+ with open (self .testing ) as archivo :
142+ response = archivo .read ()
140143 self .XmlResponse = response
141144 self .xml = SimpleXMLElement (response )
142145 if "tipoError" in self .xml :
143146 self .TipoError = str (self .xml .tipoError )
144147 self .CodigoError = str (self .xml .codigoError )
145148 self .MensajeError = (
146149 str (self .xml .mensajeError )
147- .decode ("latin1" )
148- .encode ("ascii" , "replace" )
149150 )
150151 if "numeroComprobante" in self .xml :
151152 self .NumeroComprobante = str (self .xml .numeroComprobante )
@@ -327,4 +328,4 @@ def main():
327328 )
328329
329330if __name__ == "__main__" :
330- main ()
331+ main ()
0 commit comments