Skip to content

Commit 7e60ce5

Browse files
Atualização pyxb -> PyXB-X (#402)
* Atualização pyxb -> PyXB-X * Atualização de XSD bindings * Testes unitários * Dependências NFSe * Refatoração de testes unitários * Correção de teste unitário * Refatoração de testes unitários
1 parent 1316958 commit 7e60ce5

24 files changed

+10643
-26221
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
run: |
2525
python -m pip install --upgrade pip
2626
pip install -r requirements.txt
27+
pip install -r requirements-nfse.txt
2728
pip install ruff pytest
2829
- name: Lint
2930
run: ruff check --output-format=github .

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Dependências
7676
- Biblioteca para a comunicação com os webservices da SEFAZ
7777
- suds-community (*apenas para NFS-e)
7878
- Biblioteca para a comunicação com os webservices via wsdl
79-
- pyxb (*apenas para NFS-e)
79+
- PyXB-X (*apenas para NFS-e)
8080
- Biblioteca para geração de bindings a partir de XML Schema(xsd)
8181
- brazilfiscalreport (*apenas para Impressão)
8282
- Biblioteca para impressão de DANFE e DAMDFE

pynfe/utils/nfse/betha/_dsig.py

Lines changed: 1207 additions & 2720 deletions
Large diffs are not rendered by default.

pynfe/utils/nfse/betha/nfse_v202.py

Lines changed: 4083 additions & 11015 deletions
Large diffs are not rendered by default.

pynfe/utils/nfse/ginfes/_dsig.py

Lines changed: 1209 additions & 3382 deletions
Large diffs are not rendered by default.

pynfe/utils/nfse/ginfes/_tipos.py

Lines changed: 2486 additions & 6556 deletions
Large diffs are not rendered by default.
Lines changed: 62 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
# ./cabecalho_v03.py
1+
# flake8: noqa
2+
# pynfe/utils/nfse/ginfes/cabecalho_v03.py
23
# -*- coding: utf-8 -*-
34
# PyXB bindings for NM:1981a932e981e99644ad0c4bcf57cfb2bf9f2e12
4-
# Generated 2015-12-21 11:05:54.422726 by PyXB version 1.2.4 using Python 3.5.1.final.0
5+
# Generated 2025-04-06 00:00:40.741528 by PyXB version 1.2.6 using Python 3.12.9.final.0
56
# Namespace http://www.ginfes.com.br/cabecalho_v03.xsd
67

78
from __future__ import unicode_literals
@@ -11,57 +12,58 @@
1112
import io
1213
import pyxb.utils.utility
1314
import pyxb.utils.domutils
15+
import sys
1416
import pyxb.utils.six as _six
17+
# Unique identifier for bindings created at the same time
18+
_GenerationUID = pyxb.utils.utility.UniqueIdentifier('urn:uuid:0e2620f4-a7e2-497f-ac67-2bf21c9dfe3d')
19+
20+
# Version of PyXB used to generate the bindings
21+
_PyXBVersion = '1.2.6'
22+
23+
# A holder for module-level binding classes so we can access them from
24+
# inside class definitions where property names may conflict.
25+
_module_typeBindings = pyxb.utils.utility.Object()
1526

1627
# Import bindings for namespaces imported into schema
1728
from pynfe.utils.nfse.ginfes import _tipos as _ImportedBinding__tipos
1829
import pyxb.binding.datatypes
1930

20-
# Unique identifier for bindings created at the same time
21-
_GenerationUID = pyxb.utils.utility.UniqueIdentifier(
22-
"urn:uuid:9150f830-a7e3-11e5-9c9b-b8ee65084bc8"
23-
)
24-
25-
# Version of PyXB used to generate the bindings
26-
_PyXBVersion = "1.2.4"
27-
# Generated bindings are not compatible across PyXB versions
28-
if pyxb.__version__ != _PyXBVersion:
29-
raise pyxb.PyXBVersionError(_PyXBVersion)
30-
3131
# NOTE: All namespace declarations are reserved within the binding
32-
Namespace = pyxb.namespace.NamespaceForURI(
33-
"http://www.ginfes.com.br/cabecalho_v03.xsd", create_if_missing=True
34-
)
35-
Namespace.configureCategories(["typeBinding", "elementBinding"])
36-
32+
Namespace = pyxb.namespace.NamespaceForURI('http://www.ginfes.com.br/cabecalho_v03.xsd', create_if_missing=True)
33+
Namespace.configureCategories(['typeBinding', 'elementBinding'])
3734

38-
def CreateFromDocument(xml_text, default_namespace=None, location_base=None):
35+
def CreateFromDocument (xml_text, fallback_namespace=None, location_base=None, default_namespace=None):
3936
"""Parse the given XML and use the document element to create a
4037
Python instance.
4138
4239
@param xml_text An XML document. This should be data (Python 2
4340
str or Python 3 bytes), or a text (Python 2 unicode or Python 3
4441
str) in the L{pyxb._InputEncoding} encoding.
4542
46-
@keyword default_namespace The L{pyxb.Namespace} instance to use as the
47-
default namespace where there is no default namespace in scope.
48-
If unspecified or C{None}, the namespace of the module containing
49-
this function will be used.
43+
@keyword fallback_namespace An absent L{pyxb.Namespace} instance
44+
to use for unqualified names when there is no default namespace in
45+
scope. If unspecified or C{None}, the namespace of the module
46+
containing this function will be used, if it is an absent
47+
namespace.
5048
5149
@keyword location_base: An object to be recorded as the base of all
5250
L{pyxb.utils.utility.Location} instances associated with events and
5351
objects handled by the parser. You might pass the URI from which
5452
the document was obtained.
53+
54+
@keyword default_namespace An alias for @c fallback_namespace used
55+
in PyXB 1.1.4 through 1.2.6. It behaved like a default namespace
56+
only for absent namespaces.
5557
"""
5658

5759
if pyxb.XMLStyle_saxer != pyxb._XMLStyle:
5860
dom = pyxb.utils.domutils.StringToDOM(xml_text)
59-
return CreateFromDOM(dom.documentElement, default_namespace=default_namespace)
60-
if default_namespace is None:
61-
default_namespace = Namespace.fallbackNamespace()
62-
saxer = pyxb.binding.saxer.make_parser(
63-
fallback_namespace=default_namespace, location_base=location_base
64-
)
61+
return CreateFromDOM(dom.documentElement)
62+
if fallback_namespace is None:
63+
fallback_namespace = default_namespace
64+
if fallback_namespace is None:
65+
fallback_namespace = Namespace.fallbackNamespace()
66+
saxer = pyxb.binding.saxer.make_parser(fallback_namespace=fallback_namespace, location_base=location_base)
6567
handler = saxer.getContentHandler()
6668
xmld = xml_text
6769
if isinstance(xmld, _six.text_type):
@@ -70,90 +72,61 @@ def CreateFromDocument(xml_text, default_namespace=None, location_base=None):
7072
instance = handler.rootObject()
7173
return instance
7274

73-
74-
def CreateFromDOM(node, default_namespace=None):
75+
def CreateFromDOM (node, fallback_namespace=None, default_namespace=None):
7576
"""Create a Python instance from the given DOM node.
7677
The node tag must correspond to an element declaration in this module.
7778
78-
@deprecated: Forcing use of DOM interface is unnecessary; use L{CreateFromDocument}.
79-
"""
80-
if default_namespace is None:
81-
default_namespace = Namespace.fallbackNamespace()
82-
return pyxb.binding.basis.element.AnyCreateFromDOM(node, default_namespace)
79+
@deprecated: Forcing use of DOM interface is unnecessary; use L{CreateFromDocument}."""
80+
if fallback_namespace is None:
81+
fallback_namespace = default_namespace
82+
if fallback_namespace is None:
83+
fallback_namespace = Namespace.fallbackNamespace()
84+
return pyxb.binding.basis.element.AnyCreateFromDOM(node, fallback_namespace)
8385

8486

8587
# Complex type [anonymous] with content type ELEMENT_ONLY
86-
class CTD_ANON(pyxb.binding.basis.complexTypeDefinition):
88+
class CTD_ANON (pyxb.binding.basis.complexTypeDefinition):
8789
"""Complex type [anonymous] with content type ELEMENT_ONLY"""
88-
8990
_TypeDefinition = None
9091
_ContentTypeTag = pyxb.binding.basis.complexTypeDefinition._CT_ELEMENT_ONLY
9192
_Abstract = False
9293
_ExpandedName = None
93-
_XSDLocation = pyxb.utils.utility.Location(
94-
"/home/leonardo/Downloads/cabecalho_v03.xsd", 8, 2
95-
)
94+
_XSDLocation = pyxb.utils.utility.Location('/workspaces/PyNFe/pynfe/data/XSDs/NFS-e/Ginfes/cabecalho_v03.xsd', 8, 2)
9695
_ElementMap = {}
9796
_AttributeMap = {}
9897
# Base type is pyxb.binding.datatypes.anyType
99-
98+
10099
# Element versaoDados uses Python identifier versaoDados
101-
__versaoDados = pyxb.binding.content.ElementDeclaration(
102-
pyxb.namespace.ExpandedName(None, "versaoDados"),
103-
"versaoDados",
104-
"__httpwww_ginfes_com_brcabecalho_v03_xsd_CTD_ANON_versaoDados",
105-
False,
106-
pyxb.utils.utility.Location(
107-
"/home/leonardo/Downloads/cabecalho_v03.xsd", 10, 4
108-
),
109-
)
100+
__versaoDados = pyxb.binding.content.ElementDeclaration(pyxb.namespace.ExpandedName(None, 'versaoDados'), 'versaoDados', '__httpwww_ginfes_com_brcabecalho_v03_xsd_CTD_ANON_versaoDados', False, pyxb.utils.utility.Location('/workspaces/PyNFe/pynfe/data/XSDs/NFS-e/Ginfes/cabecalho_v03.xsd', 10, 4), )
110101

102+
111103
versaoDados = property(__versaoDados.value, __versaoDados.set, None, None)
112104

105+
113106
# Attribute versao uses Python identifier versao
114-
__versao = pyxb.binding.content.AttributeUse(
115-
pyxb.namespace.ExpandedName(None, "versao"),
116-
"versao",
117-
"__httpwww_ginfes_com_brcabecalho_v03_xsd_CTD_ANON_versao",
118-
_ImportedBinding__tipos.tsVersao,
119-
required=True,
120-
)
121-
__versao._DeclarationLocation = pyxb.utils.utility.Location(
122-
"/home/leonardo/Downloads/cabecalho_v03.xsd", 13, 3
123-
)
124-
__versao._UseLocation = pyxb.utils.utility.Location(
125-
"/home/leonardo/Downloads/cabecalho_v03.xsd", 13, 3
126-
)
127-
107+
__versao = pyxb.binding.content.AttributeUse(pyxb.namespace.ExpandedName(None, 'versao'), 'versao', '__httpwww_ginfes_com_brcabecalho_v03_xsd_CTD_ANON_versao', _ImportedBinding__tipos.tsVersao, required=True)
108+
__versao._DeclarationLocation = pyxb.utils.utility.Location('/workspaces/PyNFe/pynfe/data/XSDs/NFS-e/Ginfes/cabecalho_v03.xsd', 13, 3)
109+
__versao._UseLocation = pyxb.utils.utility.Location('/workspaces/PyNFe/pynfe/data/XSDs/NFS-e/Ginfes/cabecalho_v03.xsd', 13, 3)
110+
128111
versao = property(__versao.value, __versao.set, None, None)
129112

130-
_ElementMap.update({__versaoDados.name(): __versaoDados})
131-
_AttributeMap.update({__versao.name(): __versao})
113+
_ElementMap.update({
114+
__versaoDados.name() : __versaoDados
115+
})
116+
_AttributeMap.update({
117+
__versao.name() : __versao
118+
})
119+
_module_typeBindings.CTD_ANON = CTD_ANON
132120

133121

134-
cabecalho = pyxb.binding.basis.element(
135-
pyxb.namespace.ExpandedName(Namespace, "cabecalho"),
136-
CTD_ANON,
137-
location=pyxb.utils.utility.Location(
138-
"/home/leonardo/Downloads/cabecalho_v03.xsd", 7, 1
139-
),
140-
)
141-
Namespace.addCategoryObject("elementBinding", cabecalho.name().localName(), cabecalho)
122+
cabecalho = pyxb.binding.basis.element(pyxb.namespace.ExpandedName(Namespace, 'cabecalho'), CTD_ANON, location=pyxb.utils.utility.Location('/workspaces/PyNFe/pynfe/data/XSDs/NFS-e/Ginfes/cabecalho_v03.xsd', 7, 1))
123+
Namespace.addCategoryObject('elementBinding', cabecalho.name().localName(), cabecalho)
142124

143125

144-
CTD_ANON._AddElement(
145-
pyxb.binding.basis.element(
146-
pyxb.namespace.ExpandedName(None, "versaoDados"),
147-
_ImportedBinding__tipos.tsVersao,
148-
scope=CTD_ANON,
149-
location=pyxb.utils.utility.Location(
150-
"/home/leonardo/Downloads/cabecalho_v03.xsd", 10, 4
151-
),
152-
)
153-
)
154126

127+
CTD_ANON._AddElement(pyxb.binding.basis.element(pyxb.namespace.ExpandedName(None, 'versaoDados'), _ImportedBinding__tipos.tsVersao, scope=CTD_ANON, location=pyxb.utils.utility.Location('/workspaces/PyNFe/pynfe/data/XSDs/NFS-e/Ginfes/cabecalho_v03.xsd', 10, 4)))
155128

156-
def _BuildAutomaton():
129+
def _BuildAutomaton ():
157130
# Remove this helper function from the namespace after it is invoked
158131
global _BuildAutomaton
159132
del _BuildAutomaton
@@ -162,22 +135,11 @@ def _BuildAutomaton():
162135
counters = set()
163136
states = []
164137
final_update = set()
165-
symbol = pyxb.binding.content.ElementUse(
166-
CTD_ANON._UseForTag(pyxb.namespace.ExpandedName(None, "versaoDados")),
167-
pyxb.utils.utility.Location(
168-
"/home/leonardo/Downloads/cabecalho_v03.xsd", 10, 4
169-
),
170-
)
171-
st_0 = fac.State(
172-
symbol,
173-
is_initial=True,
174-
final_update=final_update,
175-
is_unordered_catenation=False,
176-
)
138+
symbol = pyxb.binding.content.ElementUse(CTD_ANON._UseForTag(pyxb.namespace.ExpandedName(None, 'versaoDados')), pyxb.utils.utility.Location('/workspaces/PyNFe/pynfe/data/XSDs/NFS-e/Ginfes/cabecalho_v03.xsd', 10, 4))
139+
st_0 = fac.State(symbol, is_initial=True, final_update=final_update, is_unordered_catenation=False)
177140
states.append(st_0)
178141
transitions = []
179142
st_0._set_transitionSet(transitions)
180143
return fac.Automaton(states, counters, False, containing_state=None)
181-
182-
183144
CTD_ANON._Automaton = _BuildAutomaton()
145+

0 commit comments

Comments
 (0)