[CalendarServer-changes] [14923] CalDAVClientLibrary/trunk/caldavclientlibrary/browser/commands
source_changes at macosforge.org
source_changes at macosforge.org
Fri Jun 26 13:18:45 PDT 2015
Revision: 14923
http://trac.calendarserver.org//changeset/14923
Author: cdaboo at apple.com
Date: 2015-06-26 13:18:44 -0700 (Fri, 26 Jun 2015)
Log Message:
-----------
Allow data in a POST request. PyPy clean-up.
Modified Paths:
--------------
CalDAVClientLibrary/trunk/caldavclientlibrary/browser/commands/attach.py
CalDAVClientLibrary/trunk/caldavclientlibrary/browser/commands/post.py
CalDAVClientLibrary/trunk/caldavclientlibrary/browser/commands/put.py
Modified: CalDAVClientLibrary/trunk/caldavclientlibrary/browser/commands/attach.py
===================================================================
--- CalDAVClientLibrary/trunk/caldavclientlibrary/browser/commands/attach.py 2015-06-26 18:57:39 UTC (rev 14922)
+++ CalDAVClientLibrary/trunk/caldavclientlibrary/browser/commands/attach.py 2015-06-26 20:18:44 UTC (rev 14923)
@@ -102,7 +102,8 @@
if fname:
fname = os.path.expanduser(fname)
try:
- data = open(fname, "r").read()
+ with open(fname, "r") as f:
+ data = f.read()
except IOError:
print "Unable to read data from file: %s" % (fname,)
print self.usage(cmdname)
Modified: CalDAVClientLibrary/trunk/caldavclientlibrary/browser/commands/post.py
===================================================================
--- CalDAVClientLibrary/trunk/caldavclientlibrary/browser/commands/post.py 2015-06-26 18:57:39 UTC (rev 14922)
+++ CalDAVClientLibrary/trunk/caldavclientlibrary/browser/commands/post.py 2015-06-26 20:18:44 UTC (rev 14923)
@@ -34,12 +34,15 @@
fname = None
content_type = "text/plain"
path = None
+ data = None
- opts, args = getopt.getopt(shlex.split(options), 'f:t:')
+ opts, args = getopt.getopt(shlex.split(options), 'd:f:t:')
for name, value in opts:
- if name == "-f":
+ if name == "-d":
+ data = value
+ elif name == "-f":
fname = value
elif name == "-t":
content_type = value
@@ -48,11 +51,10 @@
print self.usage(cmdname)
raise WrongOptions
- if not fname:
- print "File name must be provided"
+ if data and fname:
+ print "Only one of -d or -f is allowed"
print self.usage(cmdname)
raise WrongOptions
-
elif len(args) > 1:
print "Wrong number of arguments: %d" % (len(args),)
print self.usage(cmdname)
@@ -67,13 +69,15 @@
raise WrongOptions
# Read in data
- fname = os.path.expanduser(fname)
- try:
- data = open(fname, "r").read()
- except IOError:
- print "Unable to read data from file: %s" % (fname,)
- print self.usage(cmdname)
- raise WrongOptions
+ if fname:
+ fname = os.path.expanduser(fname)
+ try:
+ with open(fname, "r") as f:
+ data = f.read()
+ except IOError:
+ print "Unable to read data from file: %s" % (fname,)
+ print self.usage(cmdname)
+ raise WrongOptions
resource = URL(url=path)
self.shell.account.session.writeData(resource, data, content_type, method="POST")
@@ -86,8 +90,12 @@
PATH is a relative or absolute path.
Options:
--f file name of data to put [REQUIRED]
+-f file name of data to put [OPTIONAL]
+-d string containing data to send [OPTIONAL]
-t content-type of data being put [DEFAULT: text/plain]
+
+Notes:
+Only one of -f or -d is allowed.
""" % (name,)
Modified: CalDAVClientLibrary/trunk/caldavclientlibrary/browser/commands/put.py
===================================================================
--- CalDAVClientLibrary/trunk/caldavclientlibrary/browser/commands/put.py 2015-06-26 18:57:39 UTC (rev 14922)
+++ CalDAVClientLibrary/trunk/caldavclientlibrary/browser/commands/put.py 2015-06-26 20:18:44 UTC (rev 14923)
@@ -73,7 +73,8 @@
# Read in data
fname = os.path.expanduser(fname)
try:
- data = open(fname, "r").read()
+ with open(fname, "r") as f:
+ data = f.read()
except IOError:
print "Unable to read data from file: %s" % (fname,)
print self.usage(cmdname)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150626/64b8a69d/attachment.html>
More information about the calendarserver-changes
mailing list