/usr/share/pyshared/pycocumalib/CoCuMa_Client.py is in pycocuma 0.4.5-6-7.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | #!/usr/bin/python
# Copyright (C) 2004 Henning Jacobs <henning@srcco.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# $Id: CoCuMa_Client.py 82 2004-07-11 13:01:44Z henning $
from __version__ import __version__
import debug
class CoCuMa_AbstractClient:
"Abstract Base Client"
def __init__(self):
self.server = None
self.connected = False
self.errorstring = ""
def getErrorString(self):
return self.errorstring
def Connect(self, connect_str):
"Connect to Server and start Session"
raise NotImplementedError
def Disconnect(self):
"Disconnect from Server = Exit Session"
raise NotImplementedError
def ListHandles(self, sortby):
"Returns List of Handles"
raise NotImplementedError
def QueryAttributes(self, handles, attributes):
"Returns a list of a list of attributes"
raise NotImplementedError
def GetContact(self, handle):
"Returns Contact in vCard Format"
raise NotImplementedError
def PutContact(self, handle, data):
"Store Contact and overwrite previous one"
raise NotImplementedError
def NewContact(self, initdict={}):
"Create new Contact and return Handle"
raise NotImplementedError
def DelContact(self, handle):
"Remove Contact"
raise NotImplementedError
def ListJournalHandles(self, sortby):
"Returns List of Handles"
raise NotImplementedError
def QueryJournalAttributes(self, handles, attributes):
"Returns a list of a list of attributes"
raise NotImplementedError
def GetJournal(self, handle):
"Returns Contact in vEvent Format"
raise NotImplementedError
def PutJournal(self, handle, data):
"Store Journal and overwrite previous one"
raise NotImplementedError
def NewJournal(self, initdict={}):
"Create new Contact and return Handle"
raise NotImplementedError
def DelJournal(self, handle):
"Remove Contact"
raise NotImplementedError
class CoCuMa_XMLRPCClient(CoCuMa_AbstractClient):
"Client to the XMLRPC Server (CoCuMa_Server.py)"
def __init__(self):
CoCuMa_AbstractClient.__init__(self)
self.cache_handles = {}
self.cache_contacts = {}
self.cache_journalhandles = {}
self.cache_journals = {}
def Connect(self, connect_str="http://localhost:8810"):
"Connect to Server and start Session"
self.errorstring = ""
import xmlrpclib, socket
retries = 4 # four connection retries
for i in range(retries):
try:
self.server = xmlrpclib.ServerProxy(connect_str)
ver = self.server.SessionInit()
if ver == "CoCuMa_Server "+__version__:
self.connected = True
return True # Alright, we made it!
else:
self.errorstring = "Version Mismatch"
debug.echo("CoCuMa_XMLRPCClient.Connect(): Could not connect to server: %s" % self.errorstring)
# We don't need to retry,
# because the server's version won't change ;-)
return False
except socket.error, detail:
errno, self.errorstring = detail
if errno != 111: return False
except Exception, detail:
self.errorstring = detail
debug.echo("CoCuMa_XMLRPCClient.Connect(): Retrying connection to server..")
import time
# Exponential Backoff (wait up to 1.6 sec):
time.sleep(0.2*(2**i))
return False
def Disconnect(self):
"Disconnect from Server = Exit Session"
self.server.SessionQuit()
self.server = None
self.connected = False
def ListHandles(self, sortby):
"Returns List of Handles"
if self.connected:
if not self.cache_handles.has_key(sortby):
self.cache_handles[sortby] = self.server.ListHandles(sortby)
return self.cache_handles[sortby]
else:
return None
def QueryAttributes(self, handles, attributes):
"Returns a list of a list of attributes"
if self.connected:
return self.server.QueryAttributes(handles, attributes)
else: return None
def GetContact(self, handle):
"Returns Contact in vCard Format"
try:
return self.cache_contacts[handle]
except:
if self.connected:
data = self.server.GetContact(handle)
self.cache_contacts[handle] = data
return data
else:
return None
def PutContact(self, handle, data):
"Store Contact and overwrite previous one"
if self.connected:
try:
self.cache_handles.clear()
del self.cache_contacts[handle]
except:
pass
return self.server.PutContact(handle, data)
else: return None
def NewContact(self, initdict={}):
"Create new Contact and return Handle"
if self.connected:
self.cache_handles.clear()
return self.server.NewContact(initdict)
else: return None
def DelContact(self, handle):
"Remove Contact"
if self.connected:
try:
del self.cache_contacts[handle]
except:
pass
self.cache_handles.clear()
return self.server.DelContact(handle)
else:
return None
def ListJournalHandles(self, sortby):
"Returns List of Handles"
if self.connected:
if not self.cache_journalhandles.has_key(sortby):
self.cache_journalhandles[sortby] = self.server.ListJournalHandles(sortby)
return self.cache_journalhandles[sortby]
else:
return None
def QueryJournalAttributes(self, handles, attributes):
"Returns a list of a list of attributes"
if self.connected:
return self.server.QueryJournalAttributes(handles, attributes)
else: return None
def GetJournal(self, handle):
"Returns Contact in vEvent Format"
try:
return self.cache_journals[handle]
except:
if self.connected:
data = self.server.GetJournal(handle)
self.cache_journals[handle] = data
return data
else:
return None
def PutJournal(self, handle, data):
"Store Journal and overwrite previous one"
if self.connected:
try:
self.cache_journalhandles.clear()
del self.cache_journals[handle]
except:
pass
return self.server.PutJournal(handle, data)
else: return None
def NewJournal(self, initdict={}):
"Create new Journal and return Handle"
if self.connected:
self.cache_journalhandles.clear()
return self.server.NewJournal(initdict)
else: return None
def DelJournal(self, handle):
"Remove Journal"
if self.connected:
try:
del self.cache_journals[handle]
except:
pass
self.cache_journalhandles.clear()
return self.server.DelJournal(handle)
else:
return None
class CoCuMa_FileClient(CoCuMa_AbstractClient):
"Ordinary Filesystem Backend"
def __init__(self):
CoCuMa_AbstractClient.__init__(self)
def Connect(self, connect_str):
"Connect to Server and start Session"
try:
try:
import os.path
from CoCuMa_Server import CoCuMa_Server
# XXX: Not very nice to use '<abook-fname>.ics':
root, ext = os.path.splitext(connect_str)
self.server = CoCuMa_Server(addressbook_fname = connect_str,
calendar_fname = root+'.ics')
self.server.SessionInit()
self.connected = True
except Exception, detail:
self.errorstring = detail
finally:
return self.connected
def Disconnect(self):
"Disconnect from Server = Exit Session"
self.server.SessionQuit()
self.server = None
self.connected = False
def ListHandles(self, sortby):
"Returns List of Handles"
if self.connected:
return self.server.ListHandles(sortby)
else: return None
def QueryAttributes(self, handles, attributes):
"Returns a list of a list of attributes"
if self.connected:
return self.server.QueryAttributes(handles, attributes)
else: return None
def GetContact(self, handle):
"Returns Contact in vCard Format"
if self.connected:
return self.server.GetContact(handle)
else: return None
def PutContact(self, handle, data):
"Store Contact and overwrite previous one"
if self.connected:
return self.server.PutContact(handle, data)
else: return None
def NewContact(self, initdict={}):
"Create new Contact and return Handle"
if self.connected:
return self.server.NewContact(initdict)
else: return None
def DelContact(self, handle):
"Remove Contact"
if self.connected:
return self.server.DelContact(handle)
else: return None
def ListJournalHandles(self, sortby):
"Returns List of Handles"
if self.connected:
return self.server.ListJournalHandles(sortby)
else: return None
def QueryJournalAttributes(self, handles, attributes):
"Returns a list of a list of attributes"
if self.connected:
return self.server.QueryJournalAttributes(handles, attributes)
else: return None
def GetJournal(self, handle):
"Returns Journal in vCard Format"
if self.connected:
return self.server.GetJournal(handle)
else: return None
def PutJournal(self, handle, data):
"Store Journal and overwrite previous one"
if self.connected:
return self.server.PutJournal(handle, data)
else: return None
def NewJournal(self, initdict={}):
"Create new Journal and return Handle"
if self.connected:
return self.server.NewJournal(initdict)
else: return None
def DelJournal(self, handle):
"Remove Journal"
if self.connected:
return self.server.DelJournal(handle)
else: return None
def Instantiate(con_type):
"Instantiate Client Object depending on Connection Type"
if con_type == 'xmlrpc':
return CoCuMa_XMLRPCClient()
elif con_type == 'file':
return CoCuMa_FileClient()
else:
return None
|