Commit 149eb603 authored by Andreas Jung's avatar Andreas Jung

replace string module calls by string methods

parent 32635b7d
...@@ -12,19 +12,19 @@ ...@@ -12,19 +12,19 @@
############################################################################## ##############################################################################
"""Rendering object hierarchies as Trees """Rendering object hierarchies as Trees
""" """
__rcs_id__='$Id: TreeTag.py,v 1.49 2001/11/28 15:51:17 matt Exp $' __rcs_id__='$Id: TreeTag.py,v 1.50 2002/02/07 18:06:25 andreasjung Exp $'
__version__='$Revision: 1.49 $'[11:-2] __version__='$Revision: 1.50 $'[11:-2]
from DocumentTemplate.DT_Util import * from DocumentTemplate.DT_Util import *
from DocumentTemplate.DT_String import String from DocumentTemplate.DT_String import String
from string import join, split, rfind, find, translate, replace from string import translate
from urllib import quote, unquote from urllib import quote, unquote
from zlib import compress, decompress from zlib import compress, decompress
from binascii import b2a_base64, a2b_base64 from binascii import b2a_base64, a2b_base64
import re import re
tbl=join(map(chr, range(256)),'') tbl=''.join(map(chr, range(256))
tplus=tbl[:ord('+')]+'-'+tbl[ord('+')+1:] tplus=tbl[:ord('+')]+'-'+tbl[ord('+')+1:]
tminus=tbl[:ord('-')]+'+'+tbl[ord('-')+1:] tminus=tbl[:ord('-')]+'+'+tbl[ord('-')+1:]
...@@ -178,7 +178,7 @@ def tpRender(self, md, section, args, ...@@ -178,7 +178,7 @@ def tpRender(self, md, section, args,
url='' url=''
root=md['URL'] root=md['URL']
l=rfind(root,'/') l=root.rfind('/')
if l >= 0: root=root[l+1:] if l >= 0: root=root[l+1:]
treeData={'tree-root-url': root, treeData={'tree-root-url': root,
...@@ -188,7 +188,7 @@ def tpRender(self, md, section, args, ...@@ -188,7 +188,7 @@ def tpRender(self, md, section, args,
prefix = args.get('prefix') prefix = args.get('prefix')
if prefix: if prefix:
for k, v in treeData.items(): for k, v in treeData.items():
treeData[prefix + replace(k[4:], '-', '_')] = v treeData[prefix + k[4:].replace('-', '_')] = v
md._push(InstanceDict(self, md)) md._push(InstanceDict(self, md))
md._push(treeData) md._push(treeData)
...@@ -202,7 +202,7 @@ def tpRender(self, md, section, args, ...@@ -202,7 +202,7 @@ def tpRender(self, md, section, args,
state=encode_seq(state) state=encode_seq(state)
md['RESPONSE'].setCookie('tree-s',state) md['RESPONSE'].setCookie('tree-s',state)
return join(data,'') return ''.join(data)
def tpRenderTABLE(self, id, root_url, url, state, substate, diff, data, def tpRenderTABLE(self, id, root_url, url, state, substate, diff, data,
colspan, section, md, treeData, level=0, args=None, colspan, section, md, treeData, level=0, args=None,
...@@ -327,7 +327,7 @@ def tpRenderTABLE(self, id, root_url, url, state, substate, diff, data, ...@@ -327,7 +327,7 @@ def tpRenderTABLE(self, id, root_url, url, state, substate, diff, data,
if len(s) > 57: s=encode_str(s) if len(s) > 57: s=encode_str(s)
else: else:
s=b2a_base64(s)[:-1] s=b2a_base64(s)[:-1]
l=find(s,'=') l=s.find('=')
if l >= 0: s=s[:l] if l >= 0: s=s[:l]
s=translate(s, tplus) s=translate(s, tplus)
#################################### ####################################
...@@ -521,10 +521,10 @@ def encode_seq(state): ...@@ -521,10 +521,10 @@ def encode_seq(state):
states=[] states=[]
for i in range(0,l,57): for i in range(0,l,57):
states.append(b2a_base64(state[i:i+57])[:-1]) states.append(b2a_base64(state[i:i+57])[:-1])
state=join(states,'') state=''.join(states)
else: state=b2a_base64(state)[:-1] else: state=b2a_base64(state)[:-1]
l=find(state,'=') l=state.find('=')
if l >= 0: state=state[:l] if l >= 0: state=state[:l]
state=translate(state, tplus) state=translate(state, tplus)
...@@ -538,10 +538,10 @@ def encode_str(state): ...@@ -538,10 +538,10 @@ def encode_str(state):
states=[] states=[]
for i in range(0,l,57): for i in range(0,l,57):
states.append(b2a_base64(state[i:i+57])[:-1]) states.append(b2a_base64(state[i:i+57])[:-1])
state=join(states,'') state=''.join(states)
else: state=b2a_base64(state)[:-1] else: state=b2a_base64(state)[:-1]
l=find(state,'=') l=state.find('=')
if l >= 0: state=state[:l] if l >= 0: state=state[:l]
state=translate(state, tplus) state=translate(state, tplus)
...@@ -566,7 +566,7 @@ def decode_seq(state): ...@@ -566,7 +566,7 @@ def decode_seq(state):
k=l%4 k=l%4
if k: state=state+'='*(4-k) if k: state=state+'='*(4-k)
states.append(a2b_base64(state)) states.append(a2b_base64(state))
state=join(states,'') state=''.join(states)
else: else:
l=len(state) l=len(state)
k=l%4 k=l%4
...@@ -574,7 +574,7 @@ def decode_seq(state): ...@@ -574,7 +574,7 @@ def decode_seq(state):
state=a2b_base64(state) state=a2b_base64(state)
state=decompress(state) state=decompress(state)
if find(state,'*') >= 0: raise 'Illegal State', state if state.find('*') >= 0: raise 'Illegal State', state
try: return list(eval(state,{'__builtins__':{}})) try: return list(eval(state,{'__builtins__':{}}))
except: return [] except: return []
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment