-
Notifications
You must be signed in to change notification settings - Fork 0
/
_deprecatedapi.py
547 lines (455 loc) · 20.6 KB
/
_deprecatedapi.py
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
#!/usr/bin/python
# -*- coding: utf-8 -*-
################################################################################
# _deprecated.py
#
# 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.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
################################################################################
# Imports.
import tempfile
from App.Common import package_home
# Product Imports.
import _fileutil
import _xmllib
import standard
def warn(self,old,new=None):
import warnings
warnings.warn('Using <%s@%s>.%s() is deprecated.'
' Use %s() instead.'%(self.meta_id,self.absolute_url(),old,[old,new][new is not None]),
DeprecationWarning,
stacklevel=2)
################################################################################
################################################################################
###
### class DeprecatedAPI:
###
################################################################################
################################################################################
class DeprecatedAPI:
f_bo_area = ''
f_eo_area = ''
f_submitBtn = ''
def f_bodyContent(self, *args, **kwargs):
warn(self,'f_bodyContent','None')
request = self.REQUEST
response = request.RESPONSE
return self.getBodyContent(request)
def zmi_form_section_begin(self, *args, **kwargs):
warn(self,'zmi_form_section_begin','None')
return ''
def zmi_form_section_end(self, *args, **kwargs):
warn(self,'zmi_form_section_end','None')
return ''
def f_selectInput(self, *args, **kwargs):
warn(self,'f_selectInput','getSelect')
return here.getSelect(fmName=kwargs['fmName'],elName=kwargs['elName'],value=kwargs['value'],inputtype=kwargs['inputtype'],lang_str=kwargs['lang_str'],required=kwargs['required'],optpl=kwargs['optpl'],enabled=kwargs['enabled'],REQUEST=self.REQUEST)
def f_headline(self, *args, **kwargs):
warn(self,'f_headline','None')
return '<h2>%s</h2><div>%s</div>'%(kwargs.get('headline',''),kwargs.get('extra',''))
def getTitleimage( self, REQUEST):
warn(self,'getTitleimage(REQUEST)','attr(\'titleimage\')')
return self.getObjProperty('titleimage',REQUEST)
def getImage(self,REQUEST):
warn(self,'getImage(REQUEST)','attr(\'img\')')
return self.getObjProperty('img',REQUEST)
def getFile(self,REQUEST):
warn(self,'getFile(REQUEST)','attr(\'file\')')
return self.getObjProperty('file',REQUEST)
def getFormat(self,REQUEST):
warn(self, 'getFormat', 'attr(\'format\')')
return self.getObjProperty('format',REQUEST)
def meta_id_or_type(self):
warn(self,'meta_id_or_type','meta_id')
return self.meta_id
def absolute_obj_path(self):
warn(self,'absolute_obj_path','None')
ob = self.getDocumentElement()
return '%s/%s/'%(ob.aq_parent.id,self.absolute_url()[len(ob.aq_parent.absolute_url())+1:])
"""
Resolves internal/external links and returns Html.
"""
def getLinkHtml( self, url, html='<a href="%s">»</a>', REQUEST=None):
warn(self,'getLinkHtml','@deprecated: use own implementation!')
REQUEST = standard.nvl( REQUEST, self.REQUEST)
s = ''
ob = self
while ob is not None:
if html in ob.getMetaobjIds() and 'getLinkHtml' in ob.getMetaobjAttrIds(html):
REQUEST.set( 'ref_id', url)
return ob.evalMetaobjAttr('%s.getLinkHtml'%html,ref_id=url)
ob = ob.getPortalMaster()
ob = self.getLinkObj(url)
if ob is not None:
if ob.isVisible(REQUEST):
url = ob.getHref2IndexHtml(REQUEST)
s = html%url
return s
# --------------------------------------------------------------------------
# DeprecatedAPI.ZCatalogItem:
# --------------------------------------------------------------------------
def search_quote(self, s, maxlen=255, tag='·'):
warn(self,'search_quote','Products.zms.standard.string_maxlen')
return standard.string_maxlen(s,maxlen,etc=tag*3)
def search_encode(self, s):
warn(self,'search_encode','Products.zms.standard.umlaut_quote')
return standard.umlaut_quote(s)
def getCatalogNavUrl(self, REQUEST):
warn(self,'getCatalogNavUrl','None')
return self.url_inherit_params(REQUEST['URL'],REQUEST,['qs'])
# --------------------------------------------------------------------------
# DeprecatedAPI.ZMSGlobals:
# --------------------------------------------------------------------------
"""
Replace special characters in string for javascript.
"""
def js_quote(self, text, charset=None):
warn(self,'js_quote','None')
if type(text) is unicode:
text= text.encode([charset, 'utf-8'][charset==None])
text = text.replace("\r", "\\r").replace("\n", "\\n")
text = text.replace('"', '\\"').replace("'", "\\'")
return text
"""
Parses default-stylesheet and returns elements.
@deprecated
@return: Elements
@rtype: C{dict}
"""
def parse_stylesheet(self):
warn(self,'parse_stylesheet','None')
stylesheet = self.getStylesheet()
if stylesheet.meta_type in ['DTML Document','DTML Method']:
data = stylesheet.raw
elif stylesheet.meta_type in ['File']:
data = stylesheet.data
data = re.sub( '/\*(.*?)\*/', '', data)
value = {}
for elmnt in data.split('}'):
i = elmnt.find('{')
keys = elmnt[:i].strip()
v = elmnt[i+1:].strip()
for key in keys.split(','):
key = key.strip()
if len(key) > 0:
value[key] = value.get(key,'') + v
colormap = {}
for key in value.keys():
if key.startswith('.') and \
key.find('Color') > 0 and \
key.find('.cms') < 0 and \
key.find('.zmi') < 0:
for elmnt in value[key].split(';'):
i = elmnt.find(':')
if i > 0:
elmntKey = elmnt[:i].strip().lower()
elmntValue = elmnt[i+1:].strip().lower()
if elmntKey == 'color' or elmntKey == 'background-color':
colormap[key[1:]] = elmntValue
self.setConfProperty('ZMS.colormap',colormap)
return colormap
def get_colormap(self):
warn(self,'get_colormap','None')
colormap = self.getConfProperty('ZMS.colormap',None)
if colormap is None:
try:
colormap = self.parse_stylesheet()
except:
# Destroy Colormap on Error
colormap = {}
self.setConfProperty('ZMS.colormap',colormap)
return colormap
"""
Returns parents for linked list.
@rtype: C{list}
"""
def tree_parents(self, l, i='id', r='idId', v='', deep=1, reverse=1):
warn(self,'tree_parents','None')
k = []
for x in l:
if x.get(i)==v:
k.append(x)
if deep:
k.extend(self.tree_parents(l,i,r,x[r],deep,0))
if reverse:
k.reverse()
return k
"""
Returns children for linked list.
@rtype: C{list}
"""
def tree_list(self, l, i='id', r='idId', v='', deep=0):
warn(self,'tree_list','None')
k = []
for x in l:
if x.get(r)==v:
k.append(x)
if deep:
k.extend(self.tree_list(l,i,r,x[i],deep))
return k
def string_maxlen(self, s, maxlen=20, etc='...', encoding=None):
warn(self,'string_maxlen','Products.zms.standard.string_maxlen')
return standard.string_maxlen(s,maxlen,etc,encoding)
def get_id_prefix(self, s):
warn(self,'get_id_prefix','Products.zms.standard.id_prefix')
return standard.id_prefix(s)
def id_quote(self, s, mapping={'\x20':'_','-':'_','/':'_',}):
warn(self,'id_quote','Products.zms.standard.id_quote')
return standard.id_quote(s,mapping)
def parseLangFmtDate(self, s, lang=None, fmt_str=None, recflag=None):
warn(self,'parseLangFmtDate','Products.zms.standard.parseLangFmtDate')
return standard.parseLangFmtDate(s)
def compareDate(self, t0, t1):
warn(self,'compareDate','Products.zms.standard.compareDate')
return standard.compareDate(t0, t1)
def daysBetween(self, t0, t1):
warn(self,'daysBetween','Products.zms.standard.daysBetween')
return standard.daysBetween(t0, t1)
def encrypt_ordtype(self, s):
warn(self,'encrypt_ordtype','Products.zms.standard.encrypt_ordtype')
return standard.encrypt_ordtype(s)
def encrypt_password(self, pw, algorithm='md5', hex=False):
warn(self,'encrypt_password','Products.zms.encrypt_password')
return standard.encrypt_password(pw,algorithm,hex)
def encrypt_schemes(self):
warn(self,'encrypt_schemes','Products.zms.encrypt_schemes')
return standard.encrypt_schemes()
def nvl(self, a1, a2, n=None):
warn(self,'nvl','Products.zms.standard.nvl')
return standard.nvl( a1, a2, n)
def rand_int(self, n):
warn(self,'rand_int','Products.zms.standard.rand_int')
return standard.rand_int(n)
def re_findall( self, pattern, text, ignorecase=False):
warn(self,'re_findall','Products.zms.standard.re_findall')
return standard.re_findall(pattern, text, ignorecase)
def re_search( self, pattern, subject, ignorecase=False):
warn(self,'re_search','Products.zms.standard.re_search')
return standard.re_search(pattern, subject, ignorecase)
def re_sub( self, pattern, replacement, subject, ignorecase=False):
warn(self,'re_sub','Products.zms.standard.re_sub')
return standard.re_sub(pattern, replacement, subject, ignorecase)
def operator_absattr(self, v):
warn(self,'operator_absattr','Products.zms.standard.operator_absattr')
return standard.operator_absattr(v)
def operator_gettype(self, v):
warn(self,'operator_gettype','Products.zms.standard.operator_gettype')
return standard.operator_gettype(v)
def operator_setitem(self, a, b, c):
warn(self,'operator_setitem','Products.zms.standard.operator_setitem')
return standard.operator_setitem(a, b, c)
def operator_getitem(self, a, b, c=None, ignorecase=True):
warn(self,'operator_getitem','Products.zms.standard.operator_getitem')
return standard.operator_getitem(a, b, c, ignorecase)
def operator_delitem(self, a, b):
warn(self,'operator_delitem','Products.zms.standard.operator_delitem')
return standard.operator_delitem(a, b)
def operator_setattr(self, a, b, c):
warn(self,'operator_setattr','Products.zms.standard.operator_setattr')
return standard.operator_setattr(a, b, c)
def operator_getattr(self, a, b, c=None):
warn(self,'operator_getattr','Products.zms.standard.operator_getattr')
return standard.operator_getattr(a, b, c)
def operator_delattr(self, a, b):
warn(self,'operator_absattr','Products.zms.standard.operator_delattr')
return standard.operator_delattr(a, b)
def intersection_list(self, l1, l2):
warn(self,'intersection_list','Products.zms.standard.intersection_list')
return standard.intersection_list(l1, l2)
def difference_list(self, l1, l2):
warn(self,'difference_list','Products.zms.standard.difference_list')
return standard.difference_list(l1, l2)
def concat_list(self, l1, l2):
warn(self,'concat_list','Products.zms.standard.concat_list')
return standard.concat_list(l1, l2)
def dict_list(self, l):
warn(self,'dict_list','Products.zms.standard.dict_list')
return standard.dict_list(l)
def distinct_list(self, l, i=None):
warn(self,'distinct_list','Products.zms.standard.distinct_list')
return standard.distinct_list(l, i)
def sort_list(self, l, qorder=None, qorderdir='asc', ignorecase=1):
warn(self,'sort_list','Products.zms.standard.sort_list')
return standard.sort_list(l, qorder, qorderdir, ignorecase)
def string_list(self, s, sep='\n', trim=True):
warn(self,'string_list','Products.zms.standard.string_list')
return standard.string_list(s, sep, trim)
def str_json(self, i, encoding='ascii', errors='xmlcharrefreplace', formatted=False, level=0):
warn(self,'str_json','Products.zms.standard.str_json')
return standard.str_json(i, encoding, errors, formatted, level)
def str_item(self, i):
warn(self,'str_item','Products.zms.standard.str_item')
return standard.str_item(i)
def filter_list(self, l, i, v, o='%'):
warn(self,'filter_list','Products.zms.standard.filter_list')
return standard.filter_list(l, i, v, o)
def copy_list(self, l):
warn(self,'copy_list','Products.zms.standard.copy_list')
return standard.copy_list(l)
def sync_list(self, l, nl, i):
warn(self,'sync_list','Products.zms.standard.sync_list')
return standard.sync_list(l, nl, i)
def aggregate_list(self, l, i):
warn(self,'aggregate_list','Products.zms.standard.aggregate_list')
return standard.aggregate_list(l, i)
def url_append_params(self, url, dict, sep='&'):
warn(self,'url_append_params','Products.zms.standard.url_append_params')
return standard.url_append_params(url, dict, sep)
def url_inherit_params(self, url, REQUEST, exclude=[], sep='&'):
warn(self,'url_inherit_params','Products.zms.standard.url_inherit_params')
return standard.url_inherit_params(url, REQUEST, exclude, sep)
def getZipArchive(self, f):
warn(self,'getZipArchive','None')
return _fileutil.getZipArchive(f)
def extractZipArchive(self, f):
warn(self,'extractZipArchive','None')
return _fileutil.extractZipArchive(f)
def buildZipArchive( self, files, get_data=True):
warn(self,'buildZipArchive','None')
return _fileutil.buildZipArchive( files, get_data)
def localfs_tempfile(self):
warn(self,'localfs_tempfile','None')
tempfolder = tempfile.mktemp()
return tempfolder
def localfs_read(self, filename, mode='b', cache='public, max-age=3600', REQUEST=None):
"""
Reads file from local file-system.
"""
warn(self,'localfs_read','Products.zms.standard.localfs_read')
# Get absolute filename.
filename = _fileutil.absoluteOSPath(filename)
# Check read permissions.
authorized = False
perms = self.getConfProperty('ZMS.localfs_read','').split(';')
perms.append(tempfile.gettempdir())
perms.append(package_home(globals()))
mediadb = self.getMediaDb()
if mediadb:
perms.append(mediadb.getLocation())
for perm in map(lambda x: x.strip(), perms):
authorized = authorized or ( len( perm) > 0 and filename.lower().startswith( _fileutil.absoluteOSPath(perm).lower()))
if not authorized:
raise zExceptions.Unauthorized
# Delegate to standard.
return standard.localfs_read(filename, mode, cache, REQUEST)
def localfs_write(self, filename, v, mode='b', REQUEST=None):
warn(self,'localfs_write','Products.zms.standard.localfs_write')
# Get absolute filename.
filename = _fileutil.absoluteOSPath(filename)
# Check write permissions.
authorized = False
perms = self.getConfProperty('ZMS.localfs_write','').split(';')
perms.append(tempfile.gettempdir())
perms.append(package_home(globals()))
mediadb = self.getMediaDb()
if mediadb:
perms.append(mediadb.getLocation())
for perm in map(lambda x: x.strip(), perms):
authorized = authorized or ( len( perm) > 0 and filename.lower().startswith( _fileutil.absoluteOSPath(perm).lower()))
if not authorized:
raise zExceptions.Unauthorized
# Delegate to standard.
return standard.localfs_write(filename, v, mode, REQUEST)
def localfs_remove(self, path, deep=0):
warn(self,'localfs_remove','Products.zms.standard.localfs_remove')
# Check write permissions.
authorized = False
perms = self.getConfProperty('ZMS.localfs_write','').split(';')
perms.append(tempfile.gettempdir())
perms.append(package_home(globals()))
mediadb = self.getMediaDb()
if mediadb:
perms.append(mediadb.getLocation())
for perm in map(lambda x: x.strip(), perms):
authorized = authorized or ( len( perm) > 0 and path.lower().startswith( _fileutil.absoluteOSPath(perm).lower()))
if not authorized:
raise zExceptions.Unauthorized
# Delegate to standard.
return standard.localfs_remove(path,deep)
def localfs_readPath(self, filename, data=False, recursive=False, REQUEST=None):
warn(self,'localfs_readPath','Products.zms.standard.localfs_readPath')
# Check read permissions.
authorized = False
perms = self.getConfProperty('ZMS.localfs_read','').split(';')
perms.append(tempfile.gettempdir())
perms.append(package_home(globals()))
mediadb = self.getMediaDb()
if mediadb:
perms.append(mediadb.getLocation())
for perm in map(lambda x: x.strip(), perms):
authorized = authorized or ( len( perm) > 0 and filename.lower().startswith( _fileutil.absoluteOSPath(perm).lower()))
if not authorized:
raise zExceptions.Unauthorized
# Delegate to standard.
return standard.localfs_readPath(filename,data,recursive,REQUEST)
def getXmlHeader(self, encoding='utf-8'):
warn(self,'getXmlHeader','Products.zms.standard.getXmlHeader')
return standard.getXmlHeader(encoding)
def toXmlString(self, v, xhtml=False, encoding='utf-8'):
warn(self,'toXmlString','Products.zms.standard.toXmlString')
return standard.toXmlString(self, v, xhtml, encoding)
def parseXmlString(self, xml, mediadbStorable=True):
warn(self,'parseXmlString','Products.zms.standard.parseXmlString')
return standard.parseXmlString(xml)
def xslProcess(self, xsl, xml):
warn(self,'xslProcess','None')
return self.processData('xslt', xml, xsl)
def processData(self, processId, data, trans=None):
warn(self,'processData','Products.zms.standard.processData')
return standard.processData(self, processId, data, trans)
def xmlParse(self, xml):
warn(self,'xmlParse','None')
return _xmllib.xmlParse(xml)
def xmlNodeSet(self, mNode, sTagName='', iDeep=0):
warn(self,'xmlNodeSet','Products.zms.standard.xmlNodeSet')
return _xmllib.xmlNodeSet( mNode, sTagName, iDeep)
def dt_executable(self, v):
warn(self,'dt_executable','Products.zms.standard.dt_executable')
return standard.dt_executable(self,v)
def dt_exec(self, v, o={}):
warn(self,'dt_exec','Products.zms.standard.dt_exec')
return standard.dt_exec(self,v,o)
def sendMail(self, mto, msubject, mbody, REQUEST=None, mattach=None):
warn(self,'sendMail','Products.zms.standard.sendMail')
return standard.sendMail(self, mto, msubject, mbody, REQUEST, mattach)
def getPRODUCT_HOME(self):
warn(self,'getPRODUCT_HOME','Products.zms.standard.getPRODUCT_HOME')
return standard.getPRODUCT_HOME()
def getPACKAGE_HOME(self):
warn(self,'getPACKAGE_HOME','Products.zms.standard.getPACKAGE_HOME')
return standard.getPACKAGE_HOME()
def getINSTANCE_HOME(self):
warn(self,'getINSTANCE_HOME','Products.zms.standard.getINSTANCE_HOME')
return standard.getINSTANCE_HOME()
def writeLog(self, info):
warn(self,'writeLog','Products.zms.standard.writeLog')
return standard.writeLog( self, info)
def writeBlock(self, info):
warn(self,'writeBlock','Products.zms.standard.writeBlock')
return standard.writeBlock( self, info)
def writeError(self, info):
warn(self,'writeError','Products.zms.standard.writeError')
return standard.writeError( self, info)
def getDataSizeStr(self, len):
warn(self,'getDataSizeStr','Products.zms.standard.getDataSizeStr')
return standard.getDataSizeStr(len)
def getMimeTypeIconSrc(self, mt):
warn(self,'getMimeTypeIconSrc','Products.zms.standard.getMimeTypeIconSrc')
return standard.getMimeTypeIconSrc(mt)
def http_import(self, url, method='GET', auth=None, parse_qs=0, timeout=10, headers={'Accept':'*/*'}):
warn(self,'http_import','Products.zms.standard.http_import')
return standard.http_import( self, url, method=method, auth=auth, parse_qs=parse_qs, timeout=timeout, headers=headers)
def getLangFmtDate(self, t, lang=None, fmt_str='SHORTDATETIME_FMT'):
warn(self,'getLangFmtDate','Products.zms.standard.getLangFmtDate')
return standard.getLangFmtDate(self, t, lang, fmt_str)