cgicli.py :  » Business-Application » PDB2PQR » pdb2pqr-1.6 » contrib » ZSI-2.1-a1 » test » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Business Application » PDB2PQR 
PDB2PQR » pdb2pqr 1.6 » contrib » ZSI 2.1 a1 » test » cgicli.py
#! /usr/bin/env python
import getopt, socket, sys

try:
    (opts, args) = getopt.getopt(sys.argv[1:],
                    'h:p:s',
                    ( 'host=', 'port=',
                        'statusonly', 'help'))
except getopt.GetoptError, e:
    print >>sys.stderr, sys.argv[0] + ': ' + str(e)
    sys.exit(1)
if args:
    print sys.argv[0] + ': Usage error; try --help.'
    sys.exit(1)

hostname, portnum, verbose = 'localhost', 80, 1
for opt, val in opts:
    if opt in [ '--help' ]:
        print '''Options include:
    --host HOST (-h HOST)       Name of server host
    --port PORT (-p PORT)       Port server is listening on
    --statusonly (-s)           Do not output reply packets; just status code
Default is -h%s -p%d -t%s''' % \
    (hostname, portnum, ','.join([str(x) for x in tests]))
        sys.exit(0)
    if opt in [ '-h', '--host' ]:
        hostname = val
    elif opt in [ '-p', '--port' ]:
        portnum = int(val)
    elif opt in [ '-s', '--statusonly' ]:
        verbose = 0


IN = '''<SOAP-ENV:Envelope
 xmlns="http://www.example.com/schemas/TEST"
 xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
    <hello/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
'''

IN = '''<SOAP-ENV:Envelope
 xmlns="http://www.example.com/schemas/TEST"
 xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
    <echo>
        <SOAP-ENC:int>1</SOAP-ENC:int>
        <SOAP-ENC:int>2</SOAP-ENC:int>
    </echo>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
'''

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((hostname, portnum))
f = s.makefile('r+')

f.write('POST /cgi-bin/x HTTP/1.0\r\n')
f.write('Content-type: text/xml; charset="utf-8"\r\n')
f.write('Content-Length: %d\r\n\r\n' % len(IN))
f.write(IN)
f.flush()

status = f.readline()
print status,
while 1:
    l = f.readline()
    if l == '': break
    if verbose: print l,

f.close()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.