[Python-checkins] CVS: python/dist/src/Tools/modulator modulator.py,1.8,1.9 varsubst.py,1.2,1.3

Jack Jansen jackjansen@users.sourceforge.net
2001年12月27日 15:35:44 -0800


Update of /cvsroot/python/python/dist/src/Tools/modulator
In directory usw-pr-cvs1:/tmp/cvs-serv25168
Modified Files:
	modulator.py varsubst.py 
Log Message:
Patches by Jens B. Jorgensen with small mods by me:
- Converted the templates to use ANSI C prototypes (finally!)
- Use re in stead of deprecated regex
Index: modulator.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/modulator/modulator.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** modulator.py	2001年07月20日 18:57:32	1.8
--- modulator.py	2001年12月27日 23:35:42	1.9
***************
*** 31,36 ****
 oops = 'oops'
 
! IDENTSTARTCHARS = string.ascii_letters + '_'
! IDENTCHARS = string.ascii_letters + string.digits + '_'
 
 # Check that string is a legal C identifier
--- 31,36 ----
 oops = 'oops'
 
! IDENTSTARTCHARS = string.letters + '_'
! IDENTCHARS = string.letters + string.digits + '_'
 
 # Check that string is a legal C identifier
Index: varsubst.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/modulator/varsubst.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** varsubst.py	1998年04月10日 19:15:27	1.2
--- varsubst.py	2001年12月27日 23:35:42	1.3
***************
*** 3,8 ****
 #
 import string
! import regex
! import regsub
 
 error = 'varsubst.error'
--- 3,7 ----
 #
 import string
! import re
 
 error = 'varsubst.error'
***************
*** 11,15 ****
 def __init__(self, dict):
 self.dict = dict
! self.prog = regex.compile('\$[a-zA-Z0-9_]*\$')
 self.do_useindent = 0
 
--- 10,14 ----
 def __init__(self, dict):
 self.dict = dict
! self.prog = re.compile('\$([a-zA-Z0-9_]*)\$')
 self.do_useindent = 0
 
***************
*** 17,37 ****
 self.do_useindent = onoff
 
! def subst(self, str):
 rv = ''
 while 1:
! pos = self.prog.search(str)
! if pos < 0:
! return rv + str
! if pos:
! rv = rv + str[:pos]
! str = str[pos:]
! len = self.prog.match(str)
! if len == 2:
 # Escaped dollar
 rv = rv + '$'
! str = str[2:]
 continue
! name = str[1:len-1]
! str = str[len:]
 if not self.dict.has_key(name):
 raise error, 'No such variable: '+name
--- 16,33 ----
 self.do_useindent = onoff
 
! def subst(self, s):
 rv = ''
 while 1:
! m = self.prog.search(s)
! if not m:
! return rv + s
! rv = rv + s[:m.start()]
! s = s[m.end():]
! if m.end() - m.start() == 2:
 # Escaped dollar
 rv = rv + '$'
! s = s[2:]
 continue
! name = m.group(1)
 if not self.dict.has_key(name):
 raise error, 'No such variable: '+name
***************
*** 45,49 ****
 lastnl = len(old) - lastnl
 sub = '\n' + (' '*lastnl)
! return regsub.gsub('\n', sub, value)
 
 def _test():
--- 41,45 ----
 lastnl = len(old) - lastnl
 sub = '\n' + (' '*lastnl)
! return re.sub('\n', sub, value)
 
 def _test():

AltStyle によって変換されたページ (->オリジナル) /