[IMP]SOporte para acentos

Con esto, se permite que :
1.- se puedan emitir xml, sin tener que transformar a entity
2.- Soporte para que los emisores que tengan carácteres especiales,
puedan utilizarlo sin tener que cambiar la razón social
Relacionado al bug l10n_cl_fe#20
parent df07bea9
......@@ -20,7 +20,7 @@ class Caf(object):
decodifica y guarda."""
self.decodedCafs = []
for caf in cafList:
decodedCaf = base64.b64decode(caf).decode()
decodedCaf = base64.b64decode(caf).decode('ISO-8859-1')
self.decodedCafs.append(decodedCaf)
def get_caf_file(self, folio, TipoDTE):
......
......@@ -83,10 +83,7 @@ class Conexion(object):
return False
xml_seed = u'<getToken><Semilla>%s</Semilla></getToken>' \
% (self._seed)
signed_node = self.firma.firmar(xml_seed, type="token")
msg = etree.tostring(
signed_node, pretty_print=True).decode()
return msg
return self.firma.firmar(xml_seed, type="token")
@seed.setter
def seed(self, val):
......
......@@ -11,6 +11,8 @@ from facturacion_electronica import clase_util as util
from datetime import datetime
import collections
import re
import logging
_logger = logging.getLogger(__name__)
class Documento(DTE):
......
......@@ -55,9 +55,8 @@ class DTE(object):
def caf_file(self, vals):
try:
self._cafs = Caf(vals)
except:
pass
#print("Caf no Soportado o vacío")
except Exception as e:
print("Caf no Soportado o vacío: %s" % str(e))
@property
def firma(self):
......@@ -244,9 +243,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</RSR><MNT>10000</MNT><IT1>IIIIIII\
timestamp = util.time_stamp()
etree.SubElement(result.find('DD'), 'TSTED').text = timestamp
keypriv = resultcaf.find('RSASK').text.replace('\t', '')
ddxml = etree.tostring(result.find('DD')).decode('ISO-8859-1')\
.replace('\n', '').replace('\t', '').replace('<item>', '')\
.replace('</item>', '')
ddxml = etree.tostring(result.find('DD'), encoding="ISO-8859-1", xml_declaration=False).replace(b'\n', b'')
firma_caf = Firma({
'priv_key': keypriv,
'init_signature': False,
......@@ -257,7 +254,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</RSR><MNT>10000</MNT><IT1>IIIIIII\
ted_xml = etree.SubElement(result, 'FRMT')
ted_xml.set("algoritmo", "SHA1withRSA")
ted_xml.text = frmt
ted = etree.tostring(result)
ted = etree.tostring(result, encoding="ISO-8859-1", xml_declaration=False)
self.sii_barcode = ted
image = False
if ted:
......@@ -320,8 +317,9 @@ folio: %s" % (
xml.set('ID', doc_id_number)
xml_pret = etree.tostring(
xml,
pretty_print=True).decode()
pretty_print=True, encoding="ISO-8859-1", xml_declaration=False).decode('ISO-8859-1')
dte_xml = self.crear_DTE(xml_pret)
type = 'doc'
if self.es_boleta():
type = 'bol'
......
# -#- coding: utf-8 -#-
from facturacion_electronica.cesion import Cesion as AEC
#from facturacion_electronica.cesion import Cesion as AEC
from facturacion_electronica.conexion import Conexion
from facturacion_electronica.consumo_folios import ConsumoFolios as CF
from facturacion_electronica.documento import Documento as Doc
......@@ -564,7 +564,8 @@ xsi:schemaLocation="http://www.sii.cl/SiiDte RespuestaEnvioDTE_v10.xsd" >
xml_pret = etree.tostring(
root,
pretty_print=True,
).decode('iso-8859-1')
encoding="ISO-8859-1", xml_declaration=False
).decode('ISO-8859-1')
self.sii_xml_request = xml_pret
self.firmar(
self.doc_id,
......
......@@ -13,6 +13,8 @@ import struct
import base64
import hashlib
import sys
import logging
_logger = logging.getLogger(__name__)
type_ = crypto.FILETYPE_PEM
USING_PYTHON2 = True if sys.version_info < (3, 0) else False
......@@ -164,7 +166,8 @@ class Firma(object):
if type == 'token':
string_to_canon = etree.tostring(el)
else:
string_to_canon = etree.tostring(el[0])
''' @mejorar esto, se supone es document con xmlns="http://www.sii.cl/SiiDte" '''
string_to_canon = etree.tostring(el[0], encoding='ISO-8859-1', xml_declaration=False).decode('ISO-8859-1')
mess = etree.tostring(etree.fromstring(string_to_canon), method="c14n")
digest = base64.b64encode(self.digest(mess))
reference_uri = '#'+uri if uri else ''
......@@ -273,8 +276,10 @@ class Firma(object):
sha_algo = SHA1
if algo == 'sha256':
sha_algo = SHA256
if type(texto) is not bytes:
texto=texto.encode()
signature = self.key.sign(
texto.encode(),
texto,
padding=PKCS1v15(),
algorithm=sha_algo()
)
......
......@@ -3,7 +3,7 @@ from setuptools import setup, find_packages
setup(
name='facturacion_electronica',
version='0.6.7',
version='0.7.0',
packages=find_packages(),
package_data={'facturacion_electronica': ['xsd/*.xsd']},
install_requires=[
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment