[Python-checkins] CVS: python/dist/src/Lib cgi.py,1.59,1.60

Eric S. Raymond esr@users.sourceforge.net
Fri, 09 Feb 2001 01:59:12 -0800


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv2858

Modified Files:
	cgi.py 
Log Message:
String method conversion.


Index: cgi.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/cgi.py,v
retrieving revision 1.59
retrieving revision 1.60
diff -C2 -r1.59 -r1.60
*** cgi.py	2001/01/20 19:54:20	1.59
--- cgi.py	2001/02/09 09:59:10	1.60
***************
*** 26,30 ****
  # =======
  
- import string
  import sys
  import os
--- 26,29 ----
***************
*** 126,130 ****
              return parse_multipart(fp, pdict)
          elif ctype == 'application/x-www-form-urlencoded':
!             clength = string.atoi(environ['CONTENT_LENGTH'])
              if maxlen and clength > maxlen:
                  raise ValueError, 'Maximum content length exceeded'
--- 125,129 ----
              return parse_multipart(fp, pdict)
          elif ctype == 'application/x-www-form-urlencoded':
!             clength = int(environ['CONTENT_LENGTH'])
              if maxlen and clength > maxlen:
                  raise ValueError, 'Maximum content length exceeded'
***************
*** 204,209 ****
              continue
          if len(nv[1]) or keep_blank_values:
!             name = urllib.unquote(string.replace(nv[0], '+', ' '))
!             value = urllib.unquote(string.replace(nv[1], '+', ' '))
              r.append((name, value))
  
--- 203,208 ----
              continue
          if len(nv[1]) or keep_blank_values:
!             name = urllib.unquote(nv[0].replace('+', ' '))
!             value = urllib.unquote(nv[1].replace('+', ' '))
              r.append((name, value))
  
***************
*** 250,255 ****
              if clength:
                  try:
!                     bytes = string.atoi(clength)
!                 except string.atoi_error:
                      pass
              if bytes > 0:
--- 249,254 ----
              if clength:
                  try:
!                     bytes = int(clength)
!                 except ValueError:
                      pass
              if bytes > 0:
***************
*** 267,271 ****
                  break
              if line[:2] == "--":
!                 terminator = string.strip(line)
                  if terminator in (nextpart, lastpart):
                      break
--- 266,270 ----
                  break
              if line[:2] == "--":
!                 terminator = line.strip()
                  if terminator in (nextpart, lastpart):
                      break
***************
*** 283,287 ****
                      line = line[:-1]
                  lines[-1] = line
!                 data = string.joinfields(lines, "")
          line = headers['content-disposition']
          if not line:
--- 282,286 ----
                      line = line[:-1]
                  lines[-1] = line
!                 data = "".join(lines)
          line = headers['content-disposition']
          if not line:
***************
*** 308,320 ****
  
      """
!     plist = map(string.strip, string.splitfields(line, ';'))
!     key = string.lower(plist[0])
      del plist[0]
      pdict = {}
      for p in plist:
!         i = string.find(p, '=')
          if i >= 0:
!             name = string.lower(string.strip(p[:i]))
!             value = string.strip(p[i+1:])
              if len(value) >= 2 and value[0] == value[-1] == '"':
                  value = value[1:-1]
--- 307,319 ----
  
      """
!     plist = map(lambda x: x.strip(), line.split(';'))
!     key = plist[0].lower()
      del plist[0]
      pdict = {}
      for p in plist:
!         i = p.find('=')
          if i >= 0:
!             name = p[:i].strip().lower()
!             value = p[i+1:].strip()
              if len(value) >= 2 and value[0] == value[-1] == '"':
                  value = value[1:-1]
***************
*** 427,431 ****
          self.strict_parsing = strict_parsing
          if environ.has_key('REQUEST_METHOD'):
!             method = string.upper(environ['REQUEST_METHOD'])
          if method == 'GET' or method == 'HEAD':
              if environ.has_key('QUERY_STRING'):
--- 426,430 ----
          self.strict_parsing = strict_parsing
          if environ.has_key('REQUEST_METHOD'):
!             method = environ['REQUEST_METHOD'].upper()
          if method == 'GET' or method == 'HEAD':
              if environ.has_key('QUERY_STRING'):
***************
*** 491,495 ****
          if self.headers.has_key('content-length'):
              try:
!                 clen = string.atoi(self.headers['content-length'])
              except:
                  pass
--- 490,494 ----
          if self.headers.has_key('content-length'):
              try:
!                 clen = int(self.headers['content-length'])
              except:
                  pass
***************
*** 648,652 ****
                  break
              if line[:2] == "--":
!                 strippedline = string.strip(line)
                  if strippedline == next:
                      break
--- 647,651 ----
                  break
              if line[:2] == "--":
!                 strippedline = line.strip()
                  if strippedline == next:
                      break
***************
*** 677,681 ****
                  break
              if line[:2] == "--":
!                 strippedline = string.strip(line)
                  if strippedline == next:
                      break
--- 676,680 ----
                  break
              if line[:2] == "--":
!                 strippedline = line.strip()
                  if strippedline == next:
                      break
***************
*** 772,781 ****
      def __getitem__(self, key):
          v = SvFormContentDict.__getitem__(self, key)
!         if v[0] in string.digits + '+-.':
!             try: return string.atoi(v)
              except ValueError:
!                 try: return string.atof(v)
                  except ValueError: pass
!         return string.strip(v)
      def values(self):
          result = []
--- 771,780 ----
      def __getitem__(self, key):
          v = SvFormContentDict.__getitem__(self, key)
!         if v[0] in '0123456789+-.':
!             try: return int(v)
              except ValueError:
!                 try: return float(v)
                  except ValueError: pass
!         return v.strip()
      def values(self):
          result = []
***************
*** 813,817 ****
          return len(self.dict[key])
      def stripped(self, key):
!         if self.dict.has_key(key): return string.strip(self.dict[key][0])
          else: return None
      def pars(self):
--- 812,816 ----
          return len(self.dict[key])
      def stripped(self, key):
!         if self.dict.has_key(key): return self.dict[key][0].strip()
          else: return None
      def pars(self):
***************
*** 871,875 ****
             traceback.format_exception_only(type, value)
      print "<PRE>%s<B>%s</B></PRE>" % (
!         escape(string.join(list[:-1], "")),
          escape(list[-1]),
          )
--- 870,874 ----
             traceback.format_exception_only(type, value)
      print "<PRE>%s<B>%s</B></PRE>" % (
!         escape("".join(list[:-1])),
          escape(list[-1]),
          )
***************
*** 973,981 ****
  def escape(s, quote=None):
      """Replace special characters '&', '<' and '>' by SGML entities."""
!     s = string.replace(s, "&", "&amp;") # Must be done first!
!     s = string.replace(s, "<", "&lt;")
!     s = string.replace(s, ">", "&gt;",)
      if quote:
!         s = string.replace(s, '"', "&quot;")
      return s
  
--- 972,980 ----
  def escape(s, quote=None):
      """Replace special characters '&', '<' and '>' by SGML entities."""
!     s = s.replace("&", "&amp;") # Must be done first!
!     s = s.replace("<", "&lt;")
!     s = s.replace(">", "&gt;")
      if quote:
!         s = s.replace('"', "&quot;")
      return s