[Zope-Checkins] CVS: Zope3/lib/python/Zope/Publisher - BaseRequest.py:1.1.2.23 Converters.py:1.1.2.3 DefaultPublication.py:1.1.2.9
Martijn Pieters
mj@zope.com
Wed, 13 Feb 2002 00:03:39 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/Publisher
In directory cvs.zope.org:/tmp/cvs-serv14206/Publisher
Modified Files:
Tag: Zope-3x-branch
BaseRequest.py Converters.py DefaultPublication.py
Log Message:
Optimizations and code style updates:
- Use isinstance on type checks
- Test UnicodeType and StringType through StringTypes
- Remove use of the string module
- Use startswith and endswith instead of slices.
- Fix weird tests where isinstance suffices.
=== Zope3/lib/python/Zope/Publisher/BaseRequest.py 1.1.2.22 => 1.1.2.23 ===
def splitPath(self, path):
# Split and clean up the path.
- if path[:1] == '/': path = path[1:]
- if path[-1:] == '/': path = path[:-1]
+ if path.startswith('/'): path = path[1:]
+ if path.endswith('/'): path = path[:-1]
clean = []
for item in path.split('/'):
if not item or item == '.':
=== Zope3/lib/python/Zope/Publisher/Converters.py 1.1.2.2 => 1.1.2.3 ===
import re
-from string import atoi, atol, atof, join, split, strip
from types import ListType, TupleType
+__ArrayTypes = (ListType, TupleType)
+
def field2string(v):
if hasattr(v,'read'): v=v.read()
else: v=str(v)
@@ -34,21 +35,21 @@
r.append(v[s:])
- return join(r,'\n')
+ return '\n'.join(r)
def field2required(v):
if hasattr(v,'read'): v=v.read()
else: v=str(v)
- if strip(v): return v
+ if v.strip(): return v
raise ValueError, 'No input for required field<p>'
def field2int(v):
- if type(v) in (ListType, TupleType):
+ if isinstance(v, __ArrayTypes):
return map(field2int, v)
if hasattr(v,'read'): v=v.read()
else: v=str(v)
if v:
- try: return atoi(v)
+ try: return int(v)
except ValueError:
raise ValueError, (
"An integer was expected in the value '%s'" % v
@@ -56,12 +57,12 @@
raise ValueError, 'Empty entry when <strong>integer</strong> expected'
def field2float(v):
- if type(v) in (ListType, TupleType):
+ if isinstance(v, __ArrayTypes):
return map(field2float, v)
if hasattr(v,'read'): v=v.read()
else: v=str(v)
if v:
- try: return atof(v)
+ try: return float(v)
except ValueError:
raise ValueError, (
"A floating-point number was expected in the value '%s'" % v
@@ -70,16 +71,16 @@
'Empty entry when <strong>floating-point number</strong> expected')
def field2long(v):
- if type(v) in (ListType, TupleType):
+ if isinstance(v, __ArrayTypes):
return map(field2long, v)
if hasattr(v,'read'): v=v.read()
else: v=str(v)
# handle trailing 'L' if present.
- if v[-1:] in ('L', 'l'):
+ if v.lower().endswith('l'):
v = v[:-1]
if v:
- try: return atol(v)
+ try: return long(v)
except ValueError:
raise ValueError, (
"A long integer was expected in the value '%s'" % v
@@ -89,15 +90,15 @@
def field2tokens(v):
if hasattr(v,'read'): v=v.read()
else: v=str(v)
- return split(v)
+ return v.split()
def field2lines(v):
- if type(v) in (ListType, TupleType):
+ if isinstance(v, __ArrayTypes):
result=[]
for item in v:
result.append(str(item))
return result
- return split(field2text(v),'\n')
+ return field2text(v).split('\n')
def field2date(v):
from DateTime import DateTime
=== Zope3/lib/python/Zope/Publisher/DefaultPublication.py 1.1.2.8 => 1.1.2.9 ===
def traverseName(self, request, ob, name, check_auth=1):
- if name[:1] == '_':
+ if name.startswith('_'):
raise Unauthorized("Name %s begins with an underscore" % `name`)
if hasattr(ob, name):
subob = getattr(ob, name)