[Python-checkins] python/dist/src/Tools/faqwiz faqwiz.py,1.27,1.28

doerwalter@users.sourceforge.net doerwalter@users.sourceforge.net
Wed, 11 Sep 2002 13:36:02 -0700


Update of /cvsroot/python/python/dist/src/Tools/faqwiz
In directory usw-pr-cvs1:/tmp/cvs-serv827/faqwiz

Modified Files:
	faqwiz.py 
Log Message:
Apply diff2.txt from SF patch http://www.python.org/sf/572113
(with one small bugfix in bgen/bgen/scantools.py)

This replaces string module functions with string methods
for the stuff in the Tools directory. Several uses of
string.letters etc. are still remaining.


Index: faqwiz.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/faqwiz/faqwiz.py,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** faqwiz.py	9 Aug 2002 16:37:36 -0000	1.27
--- faqwiz.py	11 Sep 2002 20:36:00 -0000	1.28
***************
*** 12,16 ****
  """
  
! import sys, string, time, os, stat, re, cgi, faqconf
  from faqconf import *                   # This imports all uppercase names
  now = time.time()
--- 12,16 ----
  """
  
! import sys, time, os, stat, re, cgi, faqconf
  from faqconf import *                   # This imports all uppercase names
  now = time.time()
***************
*** 34,45 ****
  
  def escape(s):
!     s = string.replace(s, '&', '&')
!     s = string.replace(s, '<', '&lt;')
!     s = string.replace(s, '>', '&gt;')
      return s
  
  def escapeq(s):
      s = escape(s)
!     s = string.replace(s, '"', '&quot;')
      return s
  
--- 34,45 ----
  
  def escape(s):
!     s = s.replace('&', '&amp;')
!     s = s.replace('<', '&lt;')
!     s = s.replace('>', '&gt;')
      return s
  
  def escapeq(s):
      s = escape(s)
!     s = s.replace('"', '&quot;')
      return s
  
***************
*** 96,100 ****
      j = len(text)
      list.append(escape(text[i:j]))
!     return string.join(list, '')
  
  def emphasize(line):
--- 96,100 ----
      j = len(text)
      list.append(escape(text[i:j]))
!     return ''.join(list)
  
  def emphasize(line):
***************
*** 110,114 ****
      if not m:
          return None
!     [major, minor] = map(string.atoi, m.group(1, 2))
      return major, minor
  
--- 110,114 ----
      if not m:
          return None
!     [major, minor] = map(int, m.group(1, 2))
      return major, minor
  
***************
*** 124,131 ****
          return {}
      raw = os.environ['HTTP_COOKIE']
!     words = map(string.strip, string.split(raw, ';'))
      cookies = {}
      for word in words:
!         i = string.find(word, '=')
          if i >= 0:
              key, value = word[:i], word[i+1:]
--- 124,131 ----
          return {}
      raw = os.environ['HTTP_COOKIE']
!     words = [s.strip() for s in raw.split(';')]
      cookies = {}
      for word in words:
!         i = word.find('=')
          if i >= 0:
              key, value = word[:i], word[i+1:]
***************
*** 141,148 ****
      import urllib
      value = urllib.unquote(value)
!     words = string.split(value, '/')
      while len(words) < 3:
          words.append('')
!     author = string.join(words[:-2], '/')
      email = words[-2]
      password = words[-1]
--- 141,148 ----
      import urllib
      value = urllib.unquote(value)
!     words = value.split('/')
      while len(words) < 3:
          words.append('')
!     author = '/'.join(words[:-2])
      email = words[-2]
      password = words[-1]
***************
*** 195,199 ****
              value = ''
          else:
!             value = string.strip(value)
          setattr(self, name, value)
          return value
--- 195,199 ----
              value = ''
          else:
!             value = value.strip()
          setattr(self, name, value)
          return value
***************
*** 210,214 ****
              import rfc822
              self.__headers = rfc822.Message(fp)
!             self.body = string.strip(fp.read())
          else:
              self.__headers = {'title': "%d.%d. " % sec_num}
--- 210,214 ----
              import rfc822
              self.__headers = rfc822.Message(fp)
!             self.body = fp.read().strip()
          else:
              self.__headers = {'title': "%d.%d. " % sec_num}
***************
*** 218,222 ****
          if name[0] == '_':
              raise AttributeError
!         key = string.join(string.split(name, '_'), '-')
          try:
              value = self.__headers[key]
--- 218,222 ----
          if name[0] == '_':
              raise AttributeError
!         key = '-'.join(name.split('_'))
          try:
              value = self.__headers[key]
***************
*** 238,242 ****
                  break
              if line[:5] == 'head:':
!                 version = string.strip(line[5:])
          p.close()
          self.version = version
--- 238,242 ----
                  break
              if line[:5] == 'head:':
!                 version = line[5:].strip()
          p.close()
          self.version = version
***************
*** 263,270 ****
          pre = 0
          raw = 0
!         for line in string.split(self.body, '\n'):
              # Allow the user to insert raw html into a FAQ answer
              # (Skip Montanaro, with changes by Guido)
!             tag = string.lower(string.rstrip(line))
              if tag == '<html>':
                  raw = 1
--- 263,270 ----
          pre = 0
          raw = 0
!         for line in self.body.split('\n'):
              # Allow the user to insert raw html into a FAQ answer
              # (Skip Montanaro, with changes by Guido)
!             tag = line.rstrip().lower()
              if tag == '<html>':
                  raw = 1
***************
*** 276,280 ****
                  print line
                  continue
!             if not string.strip(line):
                  if pre:
                      print '</PRE>'
--- 276,280 ----
                  print line
                  continue
!             if not line.strip():
                  if pre:
                      print '</PRE>'
***************
*** 283,287 ****
                      print '<P>'
              else:
!                 if line[0] not in string.whitespace:
                      if pre:
                          print '</PRE>'
--- 283,287 ----
                      print '<P>'
              else:
!                 if not line[0].isspace():
                      if pre:
                          print '</PRE>'
***************
*** 336,340 ****
              return None
          sec, num = m.group(1, 2)
!         return string.atoi(sec), string.atoi(num)
  
      def list(self):
--- 336,340 ----
              return None
          sec, num = m.group(1, 2)
!         return int(sec), int(num)
  
      def list(self):
***************
*** 433,437 ****
              words = map(lambda w: r'\b%s\b' % w, words)
              if self.ui.querytype[:3] == 'any':
!                 queries = [string.join(words, '|')]
              else:
                  # Each of the individual queries must match
--- 433,437 ----
              words = map(lambda w: r'\b%s\b' % w, words)
              if self.ui.querytype[:3] == 'any':
!                 queries = ['|'.join(words)]
              else:
                  # Each of the individual queries must match
***************
*** 552,556 ****
              days = 1
          else:
!             days = string.atof(self.ui.days)
          try:
              cutoff = now - days * 24 * 3600
--- 552,556 ----
              days = 1
          else:
!             days = float(self.ui.days)
          try:
              cutoff = now - days * 24 * 3600
***************
*** 624,628 ****
          sys.stdout.write('<PRE>')
          athead = 0
!         lines = string.split(output, '\n')
          while lines and not lines[-1]:
              del lines[-1]
--- 624,628 ----
          sys.stdout.write('<PRE>')
          athead = 0
!         lines = output.split('\n')
          while lines and not lines[-1]:
              del lines[-1]
***************
*** 635,639 ****
          for line in lines:
              if entry and athead and line[:9] == 'revision ':
!                 rev = string.strip(line[9:])
                  mami = revparse(rev)
                  if not mami:
--- 635,639 ----
          for line in lines:
              if entry and athead and line[:9] == 'revision ':
!                 rev = line[9:].split()
                  mami = revparse(rev)
                  if not mami:
***************
*** 691,695 ****
  
      def do_new(self):
!         entry = self.dir.new(section=string.atoi(self.ui.section))
          entry.version = '*new*'
          self.prologue(T_EDIT)
--- 691,695 ----
  
      def do_new(self):
!         entry = self.dir.new(section=int(self.ui.section))
          entry.version = '*new*'
          self.prologue(T_EDIT)
***************
*** 724,728 ****
              entry.load_version()
          # Check that the FAQ entry number didn't change
!         if string.split(self.ui.title)[:1] != string.split(entry.title)[:1]:
              self.error("Don't change the entry number please!")
              return
--- 724,728 ----
              entry.load_version()
          # Check that the FAQ entry number didn't change
!         if self.ui.title.split()[:1] != entry.title.split()[:1]:
              self.error("Don't change the entry number please!")
              return
***************
*** 780,784 ****
              self.ui.body = re.sub('\r\n?', '\n', self.ui.body)
          # Normalize whitespace in title
!         self.ui.title = string.join(string.split(self.ui.title))
          # Check that there were any changes
          if self.ui.body == entry.body and self.ui.title == entry.title:
--- 780,784 ----
              self.ui.body = re.sub('\r\n?', '\n', self.ui.body)
          # Normalize whitespace in title
!         self.ui.title = ' '.join(self.ui.title.split())
          # Check that there were any changes
          if self.ui.body == entry.body and self.ui.title == entry.title: