Skip to content
Browse files

Quick save of version that's able to post large contents

  • Loading branch information...
1 parent b4fa4df commit cb7e62f3d8d9a743164647a697fcfffed1786b3d @timtebeek timtebeek committed Dec 23, 2011
Showing with 17 additions and 14 deletions.
  1. +17 −14 src/py_etherpad.py
View
31 src/py_etherpad.py
@@ -1,9 +1,14 @@
+#!/usr/bin/env python
+"""Module to talk to EtherpadLite API."""
+
+import json
import urllib
import urllib2
-import json
+
class EtherpadLiteClient:
- API_VERSION = 1
+ """Client to talk to EtherpadLite API."""
+ API_VERSION = 1 # TODO probably 1.1 sometime soon
CODE_OK = 0
CODE_INVALID_PARAMETERS = 1
@@ -15,32 +20,30 @@ class EtherpadLiteClient:
apiKey = ""
baseUrl = "http://localhost:9001/api"
- def __init__(self, apiKey=None, baseUrl=None):
+ def __init__(self, apiKey=None, baseUrl=None, opener=None):
if apiKey:
self.apiKey = apiKey
if baseUrl:
self.baseUrl = baseUrl
- # No validation of url
- #raise Exception("[:self.baseUrl] is not a valid URL")
+ self.opener = opener if opener else urllib2.build_opener()
def call(self, function, arguments=None):
"""Create a dictionary of all parameters"""
+ url = '%s/%d/%s' % (self.baseUrl, self.API_VERSION, function)
+
params = arguments or {}
params.update({'apikey': self.apiKey})
- query = urllib.urlencode(params, True)
- url = '%s/%d/%s?%s' % (self.baseUrl, self.API_VERSION, function, query)
+ data = urllib.urlencode(params, True)
try:
- opener = urllib2.build_opener()
- request = urllib2.Request(url=url)
- response = opener.open(request, timeout=self.TIMEOUT)
+ request = urllib2.Request(url=url, data=data)
+ response = self.opener.open(request, timeout=self.TIMEOUT)
result = response.read()
response.close()
except urllib2.HTTPError:
raise
- #raise RequestError("Failed to send request: %e" str(e))
result = json.loads(result)
if result is None:
@@ -70,7 +73,7 @@ def handleResult(self, result):
raise Exception("An unexpected error occurred whilst handling the response")
# GROUPS
- # Pads can belong to a group. There will always be public pads that doesnt belong to a group (or we give this group the id 0)
+ # Pads can belong to a group. There will always be public pads that do not belong to a group (or we give this group the id 0)
def createGroup(self):
"""creates a new group"""
@@ -126,7 +129,7 @@ def createAuthorIfNotExistsFor(self, authorMapper, name=''):
# SESSIONS
# Sessions can be created between a group and a author. This allows
# an author to access more than one group. The sessionID will be set as
- # a cookie to the client and is valid until a certian date.
+ # a cookie to the client and is valid until a certain date.
def createSession(self, groupID, authorID, validUntil):
"""creates a new session"""
@@ -241,4 +244,4 @@ def isPasswordProtected(self, padID):
"""returns true or false"""
return self.call("isPasswordProtected", {
"padID": padID
- })
+ })

0 comments on commit cb7e62f

Please sign in to comment.
Something went wrong with that request. Please try again.