示例#1
0
def dt_docxml_to_text(self, filename):

    texts = ""

    document = zipfile.ZipFile(filename)

    xml_content = document.read('word/document.xml')

    root = ET(xml_content)

    sections = []

    for section in root.getiterator(self.PARA):
        texts = ''
        for node in section.getiterator(self.TEXT):
            if node.text:
                texts += node.text

        sections.append(''.join(texts))

    texts = '\n\n'.join(sections)

    document.close()

    return texts
示例#2
0
def handle_ClientHello(sess, pdx, rx):
    rb = e64bs(number.long_to_bytes(random.getrandbits(16 * 8))).rstrip()
    if sess is None:
        sess = hexlify(number.long_to_bytes(random.getrandbits(
            17 * 8))).decode() + '-' + e64bs(
                number.long_to_bytes(random.getrandbits(56 * 8)) +
                b'\0').rstrip()

    return ET.tostring(pdx).decode(), '''<?xml version="1.0" encoding="UTF-8"?>
<ServerHello xmlns="http://www.rsasecurity.com/rsalabs/otps/schemas/2005/12/ct-kip#" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SessionID="{sess}" Status="Continue" Version="1.0">
  <KeyType xmlns="">http://www.rsasecurity.com/rsalabs/otps/schemas/2005/09/otps-wst#SecurID-AES</KeyType>
  <EncryptionAlgorithm xmlns="">http://www.w3.org/2001/04/xmlenc#rsa-1_5</EncryptionAlgorithm>
  <EncryptionKey xmlns="" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <ds:KeyValue xmlns="http://www.rsasecurity.com/rsalabs/otps/schemas/2005/12/ct-kip#" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <ds:RSAKeyValue xmlns="http://www.rsasecurity.com/rsalabs/otps/schemas/2005/12/ct-kip#" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <ds:Modulus>{mod}</ds:Modulus>
        <ds:Exponent>{exp}</ds:Exponent>
      </ds:RSAKeyValue>
    </ds:KeyValue>
  </EncryptionKey>
  <Payload xmlns="" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <Nonce xmlns="">{rb}</Nonce>
  </Payload>
  <Extensions xmlns="" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <Extension xmlns:ct-kip="http://www.rsasecurity.com/rsalabs/otps/schemas/2005/12/ct-kip#" xmlns="" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <Data>{rb}</Data>
    </Extension>
  </Extensions>
  <MacAlgorithm xmlns="">http://www.rsasecurity.com/rsalabs/otps/schemas/2005/11/ct-kip#ct-kip-prf-aes</MacAlgorithm>
</ServerHello>'''.format(sess=sess,
                         rb=rb,
                         mod=e64bs(number.long_to_bytes(pubk.n)).rstrip(),
                         exp=e64bs(number.long_to_bytes(pubk.e)).rstrip())
示例#3
0
def create_node(tag, property_map, content):
    '''新造一个节点
       tag:节点标签
       property_map:属性及属性值map
       content: 节点闭合标签里的文本内容
       return 新节点'''
    element = ET(tag, property_map)
    element.text = content
    return element
示例#4
0
def csc_to_graph(name):
    tree = ET(name)
    mote_id = [
        int(t.text) for t in tree.findall(".//mote/interface_config/id")
    ]
    mote_type = [t.text for t in tree.findall(".//mote/motetype_identifier")]
    x = [float(t.text) for t in tree.findall(".//mote/interface_config/x")]
    y = [float(t.text) for t in tree.findall(".//mote/interface_config/y")]
    z = [float(t.text) for t in tree.findall(".//mote/interface_config/z")]
示例#5
0
def unsoap():
    auth = request.headers.get('Authorization')
    assert request.content_type == 'application/vnd.otps.ct-kip'

    try:
        x = ET.fromstring(request.data.decode())
        assert x.tag == '{http://schemas.xmlsoap.org/soap/envelope/}Envelope'

        cr = x.find('.//ctkip:ClientRequest', ns)
        ad = cr.find('ctkip:AuthData', ns)
        assert ad.text == auth
        pd = cr.find('ctkip:ProvisioningData', ns)
        r = cr.find('ctkip:Request', ns)

        pdx = ET.fromstring(d64b(pd.text))
        rx = ET.fromstring(d64b(r.text))

        print("""
Client sent:
  Authorization:
  ====================
  {}

  ProvisioningData:
  ====================
  {}

  Request:
  ====================
  {}""".format(auth,
               ET.tostring(pdx).decode(),
               ET.tostring(rx).decode()))

        # respond to client
        sess = rx.attrib.get('SessionID')
        if rx.tag == '{http://www.rsasecurity.com/rsalabs/otps/schemas/2005/11/ct-kip#}ClientHello':
            res_pd, res_r = handle_ClientHello(sess, pdx, rx)
            compr = False
        elif rx.tag == '{http://www.rsasecurity.com/rsalabs/otps/schemas/2005/11/ct-kip#}ClientNonce':
            res_pd, res_r = handle_ClientNonce(sess, pdx, rx)
            compr = True

        r = Response(mimetype='text/xml',
                     response='''<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Body>
    <ServerResponse xmlns="http://ctkipservice.rsasecurity.com">
      <AuthData>{auth}</AuthData>
      <ProvisioningData>{pd}</ProvisioningData>
      <Response>{res}</Response>
    </ServerResponse>
  </soapenv:Body>
</soapenv:Envelope>'''.format(auth=auth, pd=e64s(res_pd), res=e64s(res_r)))
        r.headers['X-Powered-By'] = 'Servlet/3.0 JSP/2.2'
        setattr(r, 'allow_compression', compr)

        print("""
Server will send:
  ProvisioningData:
  ====================
  {}

  Response:
  ====================
  {}

  SOAPified:
  ====================
  {}""".format(res_pd, res_r, r.data.decode()))

        return r

    except Exception as e:
        print(e)
        abort(500)
示例#6
0
 def fromstring(cls, string):
     root = ET.fromstring(string)
     tree = ET(element=root)
     return cls(tree)
示例#7
0
def input_information():
    for node in note.getiterator('student'):
        node = Element("name")
        node.text = input("이름을 입력하세요(종료는 'Enter' 입력): ")
        node.append(node)
        ET().write('students_info2.xml')
示例#8
0
import xmltodict, json
import requests
import xml.etree.ElementTree as ET

url = "http://www.colourlovers.com/api/palettes/top"
r = requests.get(url)
root = ET(r.content)
print("results: ", root.attrib["numResults"])
for palette in root.iter("palette"):
    pass

# o = xmltodict.parse('<e> <a>text</a> <a>text</a> </e>')

# with open('jsonfiles/palettes/top.json', 'w') as outfile:
#     json.dump(r.content,outfile)