Example #1
0
    def _prepara_doc_xml(self, xml):
        if isinstance(xml, str):
            xml = unicode(xml.encode('utf-8'))

        #
        # Determina o tipo de arquivo que vai ser assinado, procurando
        # pela tag correspondente
        #
        if u'infNFe' in xml:
            doctype = u'<!DOCTYPE NFe [<!ATTLIST infNFe Id ID #IMPLIED>]>'
        elif u'infCanc' in xml:
            doctype = u'<!DOCTYPE cancNFe [<!ATTLIST infCanc Id ID #IMPLIED>]>'
        elif u'infInut' in xml:
            doctype = u'<!DOCTYPE inutNFe [<!ATTLIST infInut Id ID #IMPLIED>]>'
        else:
            raise ValueError('Tipo de arquivo desconhecido para assinatura/validacao')

        #
        # Importantíssimo colocar o encode, pois do contário não é possível
        # assinar caso o xml tenha letras acentuadas
        #
        xml = tira_abertura(xml)
        xml = ABERTURA + xml
        xml = xml.replace(ABERTURA, ABERTURA + doctype)

        #
        # Remove todos os \n
        #
        xml = xml.replace(u'\n', u'')

        return xml
Example #2
0
    def set_xml(self, arquivo):
        if self._le_xml(arquivo):
            resposta = por_acentos(self._le_tag('//*/' + self.metodo + 'Return'))
            resposta = tira_abertura(resposta)
            self.resposta.xml = resposta

        return self.xml
Example #3
0
    def set_xml(self, arquivo):
        if self._le_xml(arquivo):
            resposta = por_acentos(
                self._le_tag('//*/' + self.metodo + 'Return'))
            resposta = tira_abertura(resposta)
            self.resposta.xml = resposta

        return self.xml
Example #4
0
    def set_xml(self, arquivo):
        if self._le_xml(arquivo):
            resposta = por_acentos(self._le_tag('//*/res:' + self.metodo + 'Result',  ns=('http://www.portalfiscal.inf.br/nfe/wsdl/' + self.webservice)))
            resposta = tira_abertura(resposta)
            #print resposta
            self.resposta.xml = resposta

        return self.xml
Example #5
0
    def get_xml(self):
        xml = XMLNFe.get_xml(self)
        xml += ABERTURA
        xml += self.versao.xml
        xml += self.idLote.xml

        for e in self.evento:
            xml += tira_abertura(e.xml)

        xml += '</envEvento>'
        return xml
Example #6
0
    def set_xml(self, arquivo):
        if self._le_xml(arquivo):
            resposta = por_acentos(
                self._le_tag('//*/res:' + self.metodo + 'Result',
                             ns=('http://www.portalfiscal.inf.br/nfe/wsdl/' +
                                 self.webservice)))
            resposta = tira_abertura(resposta)
            #print resposta
            self.resposta.xml = resposta

        return self.xml
Example #7
0
    def get_xml(self):
        xml = XMLNFe.get_xml(self)
        xml += ABERTURA
        xml += self.versao.xml
        xml += self.idLote.xml

        for e in self.evento:
            xml += tira_abertura(e.xml)

        xml += '</envEvento>'
        return xml
Example #8
0
    def get_xml(self):
        xml = XMLNFe.get_xml(self)
        xml += ABERTURA
        xml += self.versao.xml
        xml += self.idLote.xml

        for n in self.CTe:
            xml += tira_abertura(n.xml)

        xml += '</enviCTe>'
        return xml
Example #9
0
    def get_xml(self):
        xml = XMLNFe.get_xml(self)
        xml += ABERTURA
        xml += self.versao.xml
        xml += self.tpAmb.xml
        xml += self.verAplic.xml
        xml += self.cStat.xml
        xml += self.xMotivo.xml
        xml += self.cUF.xml
        xml += self.chNFe.xml

        if self.protNFe is not None:
            xml += self.protNFe.xml

        if self.retCancNFe is not None:
            xml += tira_abertura(self.retCancNFe.xml)

        if self.procEventoNFe is not None:
            for pen in self.procEventoNFe:
                xml += tira_abertura(pen.xml)

        xml += '</retConsSitNFe>'
        return xml
Example #10
0
    def get_xml(self):
        xml = XMLNFe.get_xml(self)
        xml += ABERTURA
        xml += self.versao.xml
        xml += self.tpAmb.xml
        xml += self.verAplic.xml
        xml += self.cStat.xml
        xml += self.xMotivo.xml
        xml += self.cUF.xml
        xml += self.chNFe.xml

        if self.protNFe is not None:
            xml += self.protNFe.xml

        if self.retCancNFe is not None:
            xml += tira_abertura(self.retCancNFe.xml)

        if self.procEventoNFe is not None:
            for pen in self.procEventoNFe:
                xml += tira_abertura(pen.xml)

        xml += '</retConsSitNFe>'
        return xml
Example #11
0
    def get_xml(self):
        xml = XMLNFe.get_xml(self)
        xml += ABERTURA
        xml += self.versao.xml
        xml += self.idLote.xml
        xml += self.tpAmb.xml
        xml += self.verAplic.xml
        xml += self.cOrgao.xml
        xml += self.cStat.xml
        xml += self.xMotivo.xml

        for r in self.retEvento:
            xml += tira_abertura(r.xml)

        xml += '</retEnvEvento>'
        return xml
Example #12
0
    def get_xml(self):
        xml = XMLNFe.get_xml(self)
        xml += ABERTURA
        xml += self.versao.xml
        xml += self.idLote.xml
        xml += self.tpAmb.xml
        xml += self.verAplic.xml
        xml += self.cOrgao.xml
        xml += self.cStat.xml
        xml += self.xMotivo.xml

        for r in self.retEvento:
            xml += tira_abertura(r.xml)

        xml += '</retEnvEvento>'
        return xml
Example #13
0
    def get_xml(self):
        xml = XMLNFe.get_xml(self)
        xml += ABERTURA
        xml += self.versao.xml
        xml += self.tpAmb.xml
        xml += self.verAplic.xml
        xml += self.cStat.xml
        xml += self.xMotivo.xml
        xml += self.cUF.xml

        if self.protCTe is not None:
            xml += self.protCTe.xml

        if self.retCancCTe is not None:
            xml += tira_abertura(self.retCancCTe.xml)

        xml += '</retConsSitCTe>'
        return xml
Example #14
0
    def _prepara_doc_xml(self, xml):
        if isinstance(xml, str):
            xml = unicode(xml.encode('utf-8'))

        #
        # Determina o tipo de arquivo que vai ser assinado, procurando
        # pela tag correspondente
        #

        #
        # XML da NF-e nacional
        #
        if u'infNFe' in xml:
            doctype = u'<!DOCTYPE NFe [<!ATTLIST infNFe Id ID #IMPLIED>]>'
        elif u'infCanc' in xml:
            doctype = u'<!DOCTYPE cancNFe [<!ATTLIST infCanc Id ID #IMPLIED>]>'
        elif u'infInut' in xml:
            doctype = u'<!DOCTYPE inutNFe [<!ATTLIST infInut Id ID #IMPLIED>]>'

        #
        # XML da NFS-e
        #
        elif u'ReqEnvioLoteRPS' in xml:
            doctype = u'<!DOCTYPE Lote [<!ATTLIST Lote Id ID #IMPLIED>]>'

        else:
            raise ValueError(
                'Tipo de arquivo desconhecido para assinatura/validacao')

        #
        # Importantíssimo colocar o encode, pois do contário não é possível
        # assinar caso o xml tenha letras acentuadas
        #
        xml = tira_abertura(xml)
        xml = ABERTURA + xml
        xml = xml.replace(ABERTURA, ABERTURA + doctype)

        #
        # Remove todos os \n
        #
        xml = xml.replace(u'\n', u'')

        return xml
Example #15
0
    def _prepara_doc_xml(self, xml):
        if isinstance(xml, str):
            xml = unicode(xml.encode('utf-8'))

        doctype = self._obtem_doctype(xml)

        #
        # Importantíssimo colocar o encode, pois do contário não é possível
        # assinar caso o xml tenha letras acentuadas
        #
        xml = tira_abertura(xml)
        xml = ABERTURA + xml
        xml = xml.replace(ABERTURA, ABERTURA + doctype)

        #
        # Remove todos os \n
        #
        xml = xml.replace('\n', '')
        xml = xml.replace('\r', '')

        return xml
Example #16
0
def valida_codificacao(arq_xml):
    try:
        xml = open(arq_xml).read()
        xml = xml.decode('utf-8')

        #
        # Remove caracteres desnecessários
        #
        xml = xml.replace('\r', '')
        xml = xml.replace('\n', '')

        #
        # Remove espaços entre as tags
        #
        xml = LIMPA_ESPACO_ENTRE_TAGS.sub(r'\1\2', xml)

        #
        # Tira tag de abertura com a codificação
        #
        xml = tira_abertura(xml)
    except:
        return ''

    return xml
Example #17
0
 def get_xml(self):
     xml = XMLNFe.get_xml(self)
     xml += '<nfeDadosMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/' + self.webservice + '">'
     xml += tira_abertura(self.dados.xml)
     xml += '</nfeDadosMsg>'
     return xml
Example #18
0
 def get_xml(self):
     xml = XMLNFe.get_xml(self)
     xml += '<nfeDadosMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/' + self.webservice + '">'
     xml += tira_abertura(self.dados.xml)
     xml += '</nfeDadosMsg>'
     return xml