Commit 00ac8dc4 authored by Jim Fulton's avatar Jim Fulton

Added logic to usef GET when no query parameters.

parent 35d0a67c
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
# #
############################################################################## ##############################################################################
__doc__="""Bobo call interface""" __doc__="""Bobo call interface"""
__version__='$Revision: 1.12 $'[11:-2] __version__='$Revision: 1.13 $'[11:-2]
import sys,regex,socket,mimetools import sys,regex,socket,mimetools
from httplib import HTTP, replyprog from httplib import HTTP, replyprog
...@@ -141,6 +141,7 @@ exceptmap ={'AccessError' :AccessError, ...@@ -141,6 +141,7 @@ exceptmap ={'AccessError' :AccessError,
class RemoteException: class RemoteException:
def __init__(self,etype=None,evalue=None,efile=None,eline=None,url=None, def __init__(self,etype=None,evalue=None,efile=None,eline=None,url=None,
query=None,http_code=None,http_msg=None, http_resp=None): query=None,http_code=None,http_msg=None, http_resp=None):
"""Contains information about an exception which """Contains information about an exception which
...@@ -164,7 +165,9 @@ class RemoteException: ...@@ -164,7 +165,9 @@ class RemoteException:
class RemoteMethod: class RemoteMethod:
username=password='' username=password=''
def __init__(self,url,*args): def __init__(self,url,*args):
while url[-1:]=='/': url=url[:-1] while url[-1:]=='/': url=url[:-1]
self.url=url self.url=url
...@@ -198,20 +201,25 @@ class RemoteMethod: ...@@ -198,20 +201,25 @@ class RemoteMethod:
try: q=type2marshal[type(v)](k,v) try: q=type2marshal[type(v)](k,v)
except KeyError: q='%s=%s' % (k,quote(v)) except KeyError: q='%s=%s' % (k,quote(v))
query.append(q) query.append(q)
if query:
method='POST'
query=join(query,'&') query=join(query,'&')
else: method='GET'
try: try:
h=HTTP() h=HTTP()
h.connect(self.host, self.port) h.connect(self.host, self.port)
h.putrequest('POST', self.rurl) h.putrequest(method, self.rurl)
h.putheader('Content-Type', 'application/x-www-form-urlencoded') h.putheader('Content-Type', 'application/x-www-form-urlencoded')
h.putheader('Content-Length', str(len(query))) if query: h.putheader('Content-Length', str(len(query)))
for hn,hv in self.headers.items(): h.putheader(hn,hv) for hn,hv in self.headers.items(): h.putheader(hn,hv)
if self.username and self.password: if self.username and self.password:
credentials=gsub('\012','',encodestring('%s:%s' % ( credentials=gsub('\012','',encodestring('%s:%s' % (
self.username,self.password))) self.username,self.password)))
h.putheader('Authorization',"Basic %s" % credentials) h.putheader('Authorization',"Basic %s" % credentials)
h.endheaders() h.endheaders()
h.send(query) if query: h.send(query)
ec,em,headers=h.getreply() ec,em,headers=h.getreply()
response =h.getfile().read() response =h.getfile().read()
except: except:
...@@ -563,6 +571,9 @@ if __name__ == "__main__": main() ...@@ -563,6 +571,9 @@ if __name__ == "__main__": main()
# #
# $Log: Client.py,v $ # $Log: Client.py,v $
# Revision 1.13 1997/09/11 22:27:27 jim
# Added logic to usef GET when no query parameters.
#
# Revision 1.12 1997/07/09 15:03:08 jim # Revision 1.12 1997/07/09 15:03:08 jim
# Fixed usage info. # Fixed usage info.
# #
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment