From 9219ec424310c0d39750fdf319847166228bf53c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Luna?= Date: Wed, 8 Nov 2017 17:43:05 -0200 Subject: [PATCH] [FIX] Corrige erro 225 na NF-e, devido a caracteres especiais. --- pytrustnfe/xml/__init__.py | 16 ++++++++++++++-- setup.py | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/pytrustnfe/xml/__init__.py b/pytrustnfe/xml/__init__.py index bef5a53..99cd580 100644 --- a/pytrustnfe/xml/__init__.py +++ b/pytrustnfe/xml/__init__.py @@ -2,7 +2,6 @@ # © 2016 Danimar Ribeiro, Trustcode # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -import unicodedata from lxml import etree from lxml import objectify @@ -17,6 +16,7 @@ def recursively_empty(e): def render_xml(path, template_name, remove_empty, **nfe): + nfe = recursively_normalize(nfe) env = Environment( loader=FileSystemLoader(path), extensions=['jinja2.ext.with_']) @@ -53,6 +53,18 @@ def sanitize_response(response): continue i = elem.tag.find('}') if i >= 0: - elem.tag = elem.tag[i+1:] + elem.tag = elem.tag[i + 1:] objectify.deannotate(tree, cleanup_namespaces=True) return response, objectify.fromstring(etree.tostring(tree)) + + +def recursively_normalize(vals): + for item in vals: + if type(vals[item]) is str: + vals[item] = filters.normalize_str(vals[item]) + elif type(vals[item]) is dict: + recursively_normalize(vals[item]) + elif type(vals[item]) is list: + for a in vals[item]: + recursively_normalize(a) + return vals diff --git a/setup.py b/setup.py index 89374c1..a1add7c 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ # coding=utf-8 from setuptools import setup, find_packages -VERSION = "0.9.1" +VERSION = "0.9.2" setup( name="PyTrustNFe3",