Commit ed2a4345 authored by Jim Fulton's avatar Jim Fulton

Enhanced file-upload.

parent c2a5b145
...@@ -71,7 +71,7 @@ that allows one to simply make a single web request. ...@@ -71,7 +71,7 @@ that allows one to simply make a single web request.
The module also provides a command-line interface for calling objects. The module also provides a command-line interface for calling objects.
""" """
__version__='$Revision: 1.16 $'[11:-2] __version__='$Revision: 1.17 $'[11:-2]
import sys, regex, socket, mimetools import sys, regex, socket, mimetools
from httplib import HTTP from httplib import HTTP
...@@ -555,6 +555,14 @@ The -u option may be used to provide a user name and password. ...@@ -555,6 +555,14 @@ The -u option may be used to provide a user name and password.
Optional arguments may be provides as name=value pairs. Optional arguments may be provides as name=value pairs.
In a name value pair, if a name ends in ":file", then the value is
treated as a file name and the file is send using the file-upload
protocol. If the file name is "-", then data are taken from standard
input.
The body of the response is written to standard output.
The headers of the response are written to standard error.
""" % sys.argv[0] """ % sys.argv[0]
def main(): def main():
...@@ -573,19 +581,24 @@ def main(): ...@@ -573,19 +581,24 @@ def main():
kw={} kw={}
for arg in args[1:]: for arg in args[1:]:
[name,v]=split(arg,'=') [name,v]=split(arg,'=')
if name[:2]=='-f': if name[-5:]==':file':
name=name[2:] name=name[:-5]
v=open(v) if v=='-': v=sys.stdin
else: v=open(v)
kw[name]=v kw[name]=v
except: except:
print "%s: %s\n%s" % (sys.exc_type, sys.exc_value, usage) # print "%s: %s\n%s" % (sys.exc_type, sys.exc_value, usage)
print usage
sys.exit(1) sys.exit(1)
# The "main" program for this module # The "main" program for this module
f=Function(url) f=Function(url)
if user: f.username, f.password = user, pw if user: f.username, f.password = user, pw
print apply(f,(),kw) headers, body = apply(f,(),kw)
sys.stderr.write(join(map(lambda h: "%s: %s\n" % h, headers.items()),"")
+"\n\n")
print body
if __name__ == "__main__": if __name__ == "__main__":
......
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