You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.6 KiB
54 lines
1.6 KiB
try:
|
|
from lxml import etree
|
|
except ImportError:
|
|
try:
|
|
# Python 2.5 - cElementTree
|
|
import xml.etree.cElementTree as etree
|
|
except ImportError:
|
|
try:
|
|
# Python 2.5 - ElementTree
|
|
import xml.etree.ElementTree as etree
|
|
except ImportError:
|
|
try:
|
|
# Instalacao normal do cElementTree
|
|
import cElementTree as etree
|
|
except ImportError:
|
|
try:
|
|
# Instalacao normal do ElementTree
|
|
import elementtree.ElementTree as etree
|
|
except ImportError:
|
|
raise Exception('Falhou ao importar lxml/ElementTree')
|
|
|
|
class Interface(object):
|
|
"""Classe abstrata responsavel por fornecer as funcionalidades basicas para
|
|
exportacao e importacao de Notas Fiscais eletronicas para formatos serializados
|
|
de arquivos. Como XML, JSON, binario, etc.
|
|
|
|
Nao deve ser instanciada diretamente!"""
|
|
|
|
lista_de_nfs = None
|
|
|
|
def __new__(cls, *args, **kwargs):
|
|
if cls == Interface:
|
|
raise Exception('Esta classe nao pode ser instanciada diretamente!')
|
|
else:
|
|
return cls(*args, **kwargs)
|
|
|
|
def __init__(self, nf_ou_lista):
|
|
self.lista_de_nfs = isinstance(nf_ou_lista, list) and nf_ou_lista or [nf_ou_lista]
|
|
|
|
def exportar(self, destino):
|
|
"""Gera o(s) arquivo(s) de exportacao a partir da Nofa Fiscal eletronica
|
|
ou lista delas."""
|
|
|
|
raise Exception('Metodo nao implementado')
|
|
|
|
def importar(self, origem):
|
|
"""Fabrica que recebe o caminho ou objeto de origem e instancia os objetos
|
|
da PyNFe"""
|
|
|
|
raise Exception('Metodo nao implementado')
|
|
|
|
class InterfaceXML(Interface):
|
|
pass
|
|
|