Пример #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 getResponse(self, action, data):
        output = StringIO.StringIO()
        output.write('<' + action + ' xmlns="http://tempuri.org/">' + data +
                     '</' + action + '>')
        output.seek(0)

        r = XMLParser.parse(output)
        req = dump_records(r)

        r = requests.post(
            url=
            'http://106.37.208.233:20035/ClientBin/Env-CnemcPublish-RiaServices-EnvCnemcPublishDomainService.svc/binary/'
            + action,
            data=req,
            headers={'Content-Type': 'application/msbin1'})
        res = r.content

        buf = BytesIO(res)
        r = Record.parse(buf)

        print_records(r, fp=output)
        output.seek(0)

        pat = re.compile('<[^>]+>')
        enc = pat.sub('', output.readlines()[1][1:])[:-1]

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

        convertedDict = xmltodict.parse(enc)
        return json.dumps(convertedDict)
Пример #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 getAllStationsData():
    #print action
    #print data
    output = StringIO.StringIO()
    output.write('<GetAllAQIPublishLive xmlns="http://tempuri.org/"></GetAllAQIPublishLive>')
    output.seek(0)

    r = XMLParser.parse(output)
    req = dump_records(r)

    r = requests.post(
        url='http://106.37.208.233:20035/ClientBin/Env-CnemcPublish-RiaServices-EnvCnemcPublishDomainService.svc/binary/GetAllAQIPublishLive',
        data=req,
        headers={'Content-Type': 'application/msbin1'})
    res = r.content

    buf = BytesIO(res)
    r = Record.parse(buf)

    print_records(r, fp=output)
    output.seek(0)

    pat = re.compile('<[^>]+>')
    enc = pat.sub('', output.readlines()[1][1:])[:-1]

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

    convertedDict = xmltodict.parse(enc)
    return convertedDict["ArrayOfAQIDataPublishLive"]["AQIDataPublishLive"]
Пример #6
0
    def getResponse(self, service, action, data):
        output = StringIO()
        output.write('<' + action + ' xmlns="http://tempuri.org/">' + data +
                     '</' + action + '>')
        output.seek(0)

        r = XMLParser.parse(output)
        req = dump_records(r)

        r = requests.post(
            url='http://113.108.142.147:20047/ClientBin/Env-GPRD-BLL-Services-'
            + service + '.svc/binary/' + action,
            data=req,
            headers={
                'Content-Type':
                'application/msbin1',
                'User-Agent':
                'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36'
            })
        r.encoding = "utf-8"
        res = r.content

        buf = BytesIO(res)
        r = Record.parse(buf)

        print_records(r, fp=output)
        output.seek(0)
        #print(output.getvalue())
        output = output.readlines()[1:-1]
        output = ''.join(output)

        convertedDict = xmltodict.parse(output.replace('&', ''),
                                        xml_attribs=False)
        return json.dumps(convertedDict)
Пример #7
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
Пример #8
0
 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)
Пример #9
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)