コード例 #1
0
ファイル: proxy.py プロジェクト: ruiyanc/quartz
def encode_decode(headers, data):
    from records import Record, print_records, dump_records
    from io import StringIO, BytesIO

    if not data:
        return headers, data

    #print headers
    if 'X-WCF-Encode' in headers:
        from xml2records import Parser
        p = Parser()
        print data
        print '##################################'
        p.feed(data)
        data = dump_records(p.records)
        print data.encode('hex')
        del headers['X-WCF-Encode']
        headers['Content-Type'] = 'application/soap+msbin1'
    else:
        if 'Content-Type' not in headers or headers[
                'Content-Type'] != 'application/soap+msbin1':
            return headers, data
        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'
    return headers, data
コード例 #2
0
ファイル: proxy.py プロジェクト: LucaBongiorni/python-wcfbin
def encode_decode(headers, data):
    from records import Record, print_records, dump_records
    from io import StringIO, BytesIO

    if not data:
        return headers, data

    #print headers
    if 'X-WCF-Encode' in headers:
        from xml2records import Parser
        p = Parser()
        print data
        print '##################################'
        p.feed(data)
        data = dump_records(p.records)
        print data.encode('hex')
        del headers['X-WCF-Encode']
        headers['Content-Type'] = 'application/soap+msbin1'
    else:
        if 'Content-Type' not in headers or headers['Content-Type'] != 'application/soap+msbin1':
            return headers, data
        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'
    return headers, data
コード例 #3
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from urllib import request
import json
from records import print_records

url = "http://api.open-notify.org/astros.json"
response = request.urlopen(url)
data = json.loads(response.read())

print(f"There are {data['number']} people in space right now:\n")

print(print_records(data['people'], ['name', 'craft']))
コード例 #4
0
ファイル: 39_sort_record.py プロジェクト: e0en/57_exercises
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from records import print_records, init_db, load_db


def sort_records(records, key):
    return sorted(records, key=lambda x: x[key])


filename = "39_record.db"

init_db(filename)
records = load_db(filename)

sorted_records = sort_records(records, 'last_name')

result = []
for r in sorted_records:
    entry = {
        "Name": r["first_name"] + " " + r["last_name"],
        "Position": r["position"],
        "Separation Date": r["separation_date"]
    }
    result += [entry]

s = print_records(result, ["Name", "Position", "Separation Date"])
print(s)
コード例 #5
0
ファイル: 42_csv.py プロジェクト: e0en/57_exercises
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys

from records import print_records


def format_currency(x):
    return f'$ {x}'


fields = [x.strip().split(',') for x in sys.stdin.readlines()]
columns = ['Last', 'First', 'Salary']
records = [dict(zip(columns, x)) for x in fields]
print(print_records(records, columns, ''))
コード例 #6
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from records import print_records

names = [x.strip() for x in sys.stdin.readlines()]

names.sort()
column_name = f"Total of {len(names)} names"

records = [{column_name: x} for x in names]
print(print_records(records, [column_name]))