44 |
import sys |
import sys |
45 |
|
|
46 |
class Appserver_Connector: |
class Appserver_Connector: |
47 |
def __init__(self, connectData, unicodeMode=0): |
def __init__(self, connectData): |
48 |
|
|
49 |
user = connectData['_username'] |
user = connectData['_username'] |
50 |
passwd = connectData['_password'] |
passwd = connectData['_password'] |
62 |
GDebug.printMesg(1,"Appserver's dbdriver doesn't 'encoding' parameter, as the transport"+\ |
GDebug.printMesg(1,"Appserver's dbdriver doesn't 'encoding' parameter, as the transport"+\ |
63 |
" encoding has to be 'utf-8'.") |
" encoding has to be 'utf-8'.") |
64 |
|
|
|
self._unicodeMode=unicodeMode |
|
|
|
|
65 |
#GDebug.printMesg(3,"Get the status of the session manager") |
#GDebug.printMesg(3,"Get the status of the session manager") |
66 |
#GDebug.printMesg(3,"Status: "+sessionManager.Status()) |
#GDebug.printMesg(3,"Status: "+sessionManager.Status()) |
67 |
|
|
82 |
def cursor(self): |
def cursor(self): |
83 |
return self._updateCursor |
return self._updateCursor |
84 |
|
|
85 |
def request(self,table,filter,sort,fieldlist): |
def request(self,table,filter,sort,fieldlist,unicodeMode=0): |
86 |
listid = self._sm.request(self._sess_id,table,filter,sort,fieldlist) |
listid = self._sm.request(self._sess_id,table,filter,sort,fieldlist) |
87 |
return Appserver_ListCursor(self,listid,fieldlist) |
return Appserver_ListCursor(self,listid,fieldlist,unicodeMode) |
88 |
|
|
89 |
def call(self,classname,obj_id_list,methodname,parameters): |
def call(self,classname,obj_id_list,methodname,parameters): |
90 |
self._sm.call(self._sess_id,classname,obj_id_list,methodname,parameters) |
self._sm.call(self._sess_id,classname,obj_id_list,methodname,parameters) |
101 |
self._sm.close(self._sess_id,commit) |
self._sm.close(self._sess_id,commit) |
102 |
|
|
103 |
class Appserver_ListCursor: |
class Appserver_ListCursor: |
104 |
def __init__(self,dataCon,listid,fieldlist): |
def __init__(self,dataCon,listid,fieldlist,unicodeMode=0): |
105 |
self._dataCon=dataCon |
self._dataCon=dataCon |
106 |
self._listid=listid |
self._listid=listid |
107 |
self._fieldlist=fieldlist |
self._fieldlist=fieldlist |
108 |
self._stackpos=0 |
self._stackpos=0 |
109 |
|
self._unicodeMode=unicodeMode |
110 |
|
|
111 |
def fetch(self,count=5): |
def fetch(self,count=5): |
112 |
if self._stackpos == -1: |
if self._stackpos == -1: |
136 |
|
|
137 |
# recode unicode strings to standart encoding |
# recode unicode strings to standart encoding |
138 |
if (type(value) == types.UnicodeType) and \ |
if (type(value) == types.UnicodeType) and \ |
139 |
(not self._dataCon._unicodeMode): |
(not self._unicodeMode): |
140 |
value = value.encode(gConfig('textEncoding')) |
value = value.encode(gConfig('textEncoding')) |
141 |
|
|
142 |
dict[fieldName] = value |
dict[fieldName] = value |
157 |
# TODO: Implement List Close command |
# TODO: Implement List Close command |
158 |
|
|
159 |
class Appserver_UpdateCursor: |
class Appserver_UpdateCursor: |
160 |
def __init__(self,dataCon): |
def __init__(self,dataCon,unicodeMode=0): |
161 |
self._dataCon=dataCon |
self._dataCon=dataCon |
162 |
self._deleteList={} |
self._deleteList={} |
163 |
self._updateList={} |
self._updateList={} |
164 |
self._updateKeyList={} |
self._updateKeyList={} |
165 |
|
self._unicodeMode=unicodeMode |
166 |
|
|
167 |
def delete(self,classname,id): |
def delete(self,classname,id): |
168 |
if not self._deleteList.has_key(classname): |
if not self._deleteList.has_key(classname): |
174 |
if not self._updateList.has_key(classname): |
if not self._updateList.has_key(classname): |
175 |
self._updateList[classname]=[] |
self._updateList[classname]=[] |
176 |
self._updateKeyList[classname]=[] |
self._updateKeyList[classname]=[] |
177 |
|
|
178 |
|
# convert data to transfer encoding (utf-8) |
179 |
for key in fieldDict.keys(): |
for key in fieldDict.keys(): |
180 |
value=fieldDict[key] |
value=fieldDict[key] |
181 |
|
|
182 |
|
# convert Strings from local encoding to 'utf-8' |
183 |
if type(value) == types.StringType: |
if type(value) == types.StringType: |
184 |
if not self._dataCon._unicodeMode: |
fieldDict[key] = unicode(value,gConfig('textEncoding')).encode('utf-8') |
185 |
fieldDict[key] = unicode(value,gConfig('textEncoding')).encode('utf-8') |
|
186 |
else: |
# raise Warning if running in unicode mode |
187 |
fieldDict[key] = value.encode('utf-8') |
if self._unicodeMode: |
188 |
|
GDebug.printMesg(0,'WARNING: non-unicode passed to the dbdriver (%s)' % value) |
189 |
|
|
190 |
|
# recode unicode strings to 'utf-8' |
191 |
|
elif type(value) == types.UnicodeType: |
192 |
|
fieldDict[key] = value.encode('utf-8') |
193 |
|
|
194 |
self._updateList[classname].append(fieldDict) |
self._updateList[classname].append(fieldDict) |
195 |
self._updateKeyList[classname].append(id) |
self._updateKeyList[classname].append(id) |
371 |
raise GDataObjects.ConnectionError, err |
raise GDataObjects.ConnectionError, err |
372 |
|
|
373 |
try: |
try: |
374 |
listcursor = self._dataConnection.request(self.table,filter,sort,fieldlist) |
listcursor = self._dataConnection.request(self.table,filter,sort,fieldlist,\ |
375 |
|
self._unicodeMode) |
376 |
except Exception, msg: |
except Exception, msg: |
377 |
tmsg = _("Error during creation of object list \n\n --- %s ---)") % msg |
tmsg = _("Error during creation of object list \n\n --- %s ---)") % msg |
378 |
raise GDataObjects.ConnectionError, tmsg |
raise GDataObjects.ConnectionError, tmsg |