コード例 #1
0
    def encodeWCF(self, data):

        try:

            #data = dump_records(XMLParser.parse(self.extender.helpers.bytesToString(data)))

            fp = StringIO(self.extender.helpers.bytesToString(data))
            data = fp.getvalue()
            out = dump_records(XMLParser.parse(str(data)))

            return out

        except ValueError:
            tb = traceback.format_exc()
            return tb

        return "0"

        try:
            XML = self.extender.helpers.bytesToString(data)
            #XML = XML.replace("\n", '').replace("\t", '')
            parsedXML = XMLParser.parse(str(XML))
            serializedXml = dump_records(parsedXML)
            return serializedXml
        except ValueError:
            tb = traceback.format_exc()
            return tb
コード例 #2
0
    def runTest(self):
        from io import BytesIO

        bio = BytesIO(test_bin)
        new = dump_records(Record.parse(bio))

        self.assertEqual(test_bin, new)
コード例 #3
0
    def craw(self, action, data):
        res = StringIO()
        res.write('<'+action+' xmlns="http://tempuri.org/">'+data+'</'+action+'>')
        res.seek(0)

        # usage from wcfbin-python
        res_r = XMLParser.parse(res)
        req = dump_records(res_r)

        # request
        request = requests.post(url=self.url+action,
                                data=req,
                                headers = self.headers)

        records = Record.parse(BytesIO(request.content))

        print_records(records, fp=res)
        res.seek(0)

        temp = res.readlines()

        pat = re.compile('<[^>]+>')
        enc = pat.sub('', temp[1][1:])[:-1]
        # print(type(enc))

        enc = base64.b64decode(enc)
        enc = zlib.decompress(enc)

        dict = xmltodict.parse(enc)
        print(json.dumps(dict))
        return dict
コード例 #4
0
def encode_decode(headers, data):

    if not data:
        return headers, data


    if 'X-WCF-Encode' in headers:
        data = dump_records(XMLParser.parse(data))
        del headers['X-WCF-Encode']
        headers['Content-Type'] = 'application/soap+msbin1'
        headers['Content-Length'] = str(len(data))
    else:
        #print headers['Content-type']
        if 'Content-Type' not in headers or headers['Content-Type'] != 'application/soap+msbin1':
            return headers, data
        #print headers
        fp = StringIO(data)
        data = Record.parse(fp)
        fp.close()
        fp = StringIO()
        print_records(data, fp=fp)
        data = fp.getvalue()
        fp.close()
        headers['X-WCF-Encode'] = '1'
        headers['Content-Type'] = 'text/soap+xml'
        headers['Content-Length'] = str(len(data))
    return headers, data
コード例 #5
0
def encode_decode(headers, data):

    if not data:
        return headers, data


    if 'X-WCF-Encode' in headers:
        data = dump_records(XMLParser.parse(data))
        del headers['X-WCF-Encode']
        headers['Content-Type'] = 'application/soap+msbin1'
        headers['Content-Length'] = str(len(data))
    else:
        #print headers['Content-type']
        if 'Content-Type' not in headers or headers['Content-Type'] != 'application/soap+msbin1':
            return headers, data
        #print headers
        fp = BytesIO(data)
        data = Record.parse(fp)
        fp.close()
        fp = StringIO()
        print_records(data, fp=fp)
        data = fp.getvalue()
        fp.close()
        headers['X-WCF-Encode'] = '1'
        headers['Content-Type'] = 'text/soap+xml'
        headers['Content-Length'] = str(len(data))
    return headers, data
コード例 #6
0
ファイル: jmmclient.py プロジェクト: nettosama/py-jmmclient
 def send(self, request):
     self.addcredentials(request)
     r = XMLParser.parse(request.message.decode('ascii'))
     data = dump_records(r)
     request.message = data
     request.headers['Content-Type'] = 'application/soap+msbin1'
     # request.message = request.message()
     return HttpTransport.send(self, request)
コード例 #7
0
        """
        p = cls()
        xml = None
        if isinstance(data, str):
            xml = data
        elif hasattr(data, "read"):
            xml = data.read()
        else:
            raise ValueError("%s has an incompatible type %s" % (data, type(data)))

        p.feed(xml)

        return p.records


if __name__ == "__main__":
    import sys

    fp = sys.stdin

    if len(sys.argv) > 1:
        fp = open(sys.argv[1], "r")

    logging.basicConfig(level=logging.INFO)

    p = XMLParser()
    indata = fp.read()  # .strip()
    fp.close()
    p.feed(indata)
    sys.stdout.write(dump_records(p.records))
コード例 #8
0
#!/usr/bin/env python2
# vim: set ts=4 sw=4 tw=79 fileencoding=utf-8:

from __future__ import absolute_import, with_statement

from wcf.xml2records import XMLParser
from wcf.records import dump_records

import sys
import logging

if __name__ == '__main__':
    fp = sys.stdin

    if len(sys.argv) > 1:
        fp = open(sys.argv[1], 'r')

    logging.basicConfig(level=logging.INFO)

    with fp:
        r = XMLParser.parse(fp)
        data = dump_records(r)

    if sys.version_info >= (3, 0, 0):
        sys.stdout.buffer.write(data)
    else:
        sys.stdout.write(data)
コード例 #9
0
ファイル: xml2wcf.py プロジェクト: dannyquist/python-wcfbin
#!/usr/bin/env python2
# vim: set ts=4 sw=4 tw=79 fileencoding=utf-8:

from __future__ import absolute_import, with_statement

from wcf.xml2records import XMLParser
from wcf.records import dump_records

import sys
import logging

if __name__ == '__main__':
    fp = sys.stdin

    if len(sys.argv) > 1:
        fp = open(sys.argv[1], 'r')

    logging.basicConfig(level=logging.INFO)

    with fp:
        r = XMLParser.parse(fp)
        sys.stdout.write(dump_records(r))