Permalink
Browse files

code style

  • Loading branch information...
1 parent 9c1d479 commit 03ab72b240e84dd90be23fe6a42b3c5a8ae23449 @emirotin emirotin committed Nov 1, 2011
Showing with 6 additions and 28 deletions.
  1. +6 −28 src/py_etherpad.py
View
@@ -29,10 +29,9 @@ def call(self, function, arguments=None):
#Create a dictionary of all parameters
params = arguments or {}
params.update({'apikey': self.apiKey})
-
query = urllib.urlencode(params, True)
-
- url = self.baseUrl + "/" + str(self.API_VERSION) + "/" + function + "?" + query
+ url = '%s/%d/%s?%s' % (self.baseUrl, self.API_VERSION, function, query)
+ result = None
try:
opener = urllib2.build_opener()
@@ -51,11 +50,12 @@ def call(self, function, arguments=None):
return self.handleResult(result)
def handleResult(self, result):
- if not 'code' in result:
+ if 'code' not in result:
raise Exception("API response has no code")
- if not 'message' in result:
+ if 'message' not in result:
raise Exception("API response has no message")
- if not 'data' in result:
+
+ if 'data' not in result:
result['data'] = None
if result['code'] == self.CODE_OK:
@@ -69,36 +69,31 @@ def handleResult(self, result):
else:
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)
# creates a new group
def createGroup(self):
return self.call("createGroup")
-
# this functions helps you to map your application group ids to etherpad lite group ids
def createGroupIfNotExistsFor(self, groupMapper):
return self.call("createGroupIfNotExistsFor", {
"groupMapper": groupMapper
})
-
# deletes a group
def deleteGroup(self, groupID):
return self.call("deleteGroup", {
"groupID": groupID
})
-
# returns all pads of this group
def listPads(self, groupID):
return self.call("listPads", {
"groupID": groupID
})
-
# creates a new pad in this group
def createGroupPad(self, groupID, padName, text):
return self.call("createGroupPad", {
@@ -107,7 +102,6 @@ def createGroupPad(self, groupID, padName, text):
"text": text
})
-
# AUTHORS
# Theses authors are bind to the attributes the users choose (color and name).
@@ -117,15 +111,13 @@ def createAuthor(self, name):
"name": name
})
-
# this functions helps you to map your application author ids to etherpad lite author ids
def createAuthorIfNotExistsFor(self, authorMapper, name):
return self.call("createAuthorIfNotExistsFor", {
"authorMapper": authorMapper,
"name": 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
@@ -139,35 +131,30 @@ def createSession(self, groupID, authorID, validUntil):
"validUntil": validUntil
})
-
# deletes a session
def deleteSession(self, sessionID):
return self.call("deleteSession", {
"sessionID": sessionID
})
-
# returns informations about a session
def getSessionInfo(self, sessionID):
return self.call("getSessionInfo", {
"sessionID": sessionID
})
-
# returns all sessions of a group
def listSessionsOfGroup(self, groupID):
return self.call("listSessionsOfGroup", {
"groupID": groupID
})
-
# returns all sessions of an author
def listSessionsOfAuthor(self, authorID):
return self.call("listSessionsOfAuthor", {
"authorID": authorID
})
-
# PAD CONTENT
# Pad content can be updated and retrieved through the API
@@ -178,15 +165,13 @@ def getText(self, padID):
"padID": padID
})
-
# sets the text of a pad
def setText(self, padID, text):
return self.call("setText", {
"padID": padID,
"text": text
})
-
# PAD
# Group pads are normal pads, but with the name schema
# GROUPIDPADNAME. A security manager controls access of them and its
@@ -199,51 +184,44 @@ def createPad(self, padID, text):
"text": text
})
-
# returns the number of revisions of this pad
def getRevisionsCount(self, padID):
return self.call("getRevisionsCount", {
"padID": padID
})
-
# deletes a pad
def deletePad(self, padID):
return self.call("deletePad", {
"padID": padID
})
-
# returns the read only link of a pad
def getReadOnlyID(self, padID):
return self.call("getReadOnlyID", {
"padID": padID
})
-
# sets a boolean for the public status of a pad
def setPublicStatus(self, padID, publicStatus):
return self.call("setPublicStatus", {
"padID": padID,
"publicStatus": publicStatus
})
-
# return true of false
def getPublicStatus(self, padID):
return self.call("getPublicStatus", {
"padID": padID
})
-
# returns ok or a error message
def setPassword(self, padID, password):
return self.call("setPassword", {
"padID": padID,
"password": password
})
-
# returns true or false
def isPasswordProtected(self, padID):
return self.call("isPasswordProtected", {

0 comments on commit 03ab72b

Please sign in to comment.