Commit b3fa9c1b authored by Nikolay Kim's avatar Nikolay Kim

micro optimization

parent cea3fed4
......@@ -346,7 +346,7 @@ class ApplicationManager(Folder,CacheManager):
def db_size(self):
s = self._p_jar.db().getSize()
if type(s) is type(''):
if type(s) is str:
return s
if s >= 1048576.0:
......
......@@ -52,7 +52,7 @@ class ImageFile(Explicit):
_prefix=getattr(getConfiguration(), 'softwarehome', None) or PREFIX
if not os.path.isabs(path):
warnings.warn(NON_PREFIX_WARNING, UserWarning, 2)
elif type(_prefix) is not type(''):
elif type(_prefix) is not str:
_prefix=package_home(_prefix)
# _prefix is ignored if path is absolute
path = os.path.join(_prefix, path)
......
......@@ -41,7 +41,7 @@ class ClassicHTMLFile(DocumentTemplate.HTMLFile,MethodObject.Method,):
def __init__(self, name, _prefix=None, **kw):
if _prefix is None:
_prefix = getattr(getConfiguration(), 'softwarehome', PREFIX)
elif type(_prefix) is not type(''):
elif type(_prefix) is not str:
_prefix = Common.package_home(_prefix)
args=(self, os.path.join(_prefix, name + '.dtml'))
if '__name__' not in kw:
......
......@@ -587,7 +587,7 @@ def import_product(product_dir, product_name, raise_exc=0, log_exc=1):
path_join=os.path.join
isdir=os.path.isdir
exists=os.path.exists
_st=type('')
_st=str
global_dict=globals()
silly=('__doc__',)
modules=sys.modules
......
......@@ -102,7 +102,7 @@ class CopyContainer(Base):
elif ids is None:
raise ValueError('ids must be specified')
if type(ids) is type(''):
if type(ids) is str:
ids=[ids]
oblist=[]
for id in ids:
......@@ -133,7 +133,7 @@ class CopyContainer(Base):
elif ids is None:
raise ValueError('ids must be specified')
if type(ids) is type(''):
if type(ids) is str:
ids=[ids]
oblist=[]
for id in ids:
......
......@@ -59,7 +59,7 @@ class DTMLDocument(PropertyManager, DTMLMethod):
raise ResourceLockedError(
'This document has been locked via WebDAV.')
if type(file) is not type(''):
if type(file) is not str:
if REQUEST and not file:
raise ValueError, 'No file specified'
file = file.read()
......@@ -103,7 +103,7 @@ class DTMLDocument(PropertyManager, DTMLMethod):
return result
r = apply(HTML.__call__, (self, (client, bself), REQUEST), kw)
if type(r) is not type('') or RESPONSE is None:
if type(r) is not str or RESPONSE is None:
if not self._cache_namespace_keys:
self.ZCacheable_set(r)
return r
......@@ -143,7 +143,7 @@ def addDTMLDocument(self, id, title='', file='', REQUEST=None, submit=None):
"""Add a DTML Document object with the contents of file. If
'file' is empty, default document text is used.
"""
if type(file) is not type(''):
if type(file) is not str:
file = file.read()
if not file:
file = default_dd_html
......
......@@ -144,7 +144,7 @@ class DTMLMethod(RestrictedDTML,
return result
r = apply(HTML.__call__, (self, client, REQUEST), kw)
if type(r) is not type('') or RESPONSE is None:
if type(r) is not str or RESPONSE is None:
if not self._cache_namespace_keys:
self.ZCacheable_set(r)
return r
......@@ -305,7 +305,7 @@ class DTMLMethod(RestrictedDTML,
if self.wl_isLocked():
raise ResourceLockedError('This DTML Method is locked via WebDAV')
if type(file) is not type(''):
if type(file) is not str:
if REQUEST and not file:
raise ValueError('No file specified')
file = file.read()
......@@ -459,7 +459,7 @@ def addDTMLMethod(self, id, title='', file='', REQUEST=None, submit=None):
"""Add a DTML Method object with the contents of file. If
'file' is empty, default document text is used.
"""
if type(file) is not type(''):
if type(file) is not str:
file = file.read()
if not file:
file = default_dm_html
......
......@@ -411,7 +411,7 @@ class ObjectManager(CopyContainer,
# If 'spec' is specified, returns objects whose meta_type
# matches 'spec'.
if spec is not None:
if type(spec)==type('s'):
if type(spec) is str:
spec=[spec]
set=[]
for ob in self._objects:
......@@ -471,7 +471,7 @@ class ObjectManager(CopyContainer,
def superValues(self, t):
# Return all of the objects of a given type located in
# this object and containing objects.
if type(t)==type('s'): t=(t,)
if type(t) is str: t=(t,)
obj=self
seen={}
vals=[]
......@@ -507,7 +507,7 @@ class ObjectManager(CopyContainer,
The objects specified in 'ids' get deleted.
"""
if type(ids) is type(''): ids=[ids]
if type(ids) is str: ids=[ids]
if not ids:
return MessageDialog(title='No items specified',
message='No items were specified!',
......
......@@ -202,7 +202,7 @@ class PropertyManager(Base, ElementWithAttributes):
self._wrapperCheck(value)
if not self.hasProperty(id):
raise BadRequest, 'The property %s does not exist' % escape(id)
if type(value)==type(''):
if type(value) is str:
proptype=self.getPropertyType(id) or 'string'
if proptype in type_converters:
value=type_converters[proptype](value)
......
......@@ -231,7 +231,7 @@ class PropertySheet(Traversable, Persistent, Implicit):
propinfo=self.propertyInfo(id)
if not 'w' in propinfo.get('mode', 'wd'):
raise BadRequest, '%s cannot be changed.' % escape(id)
if type(value)==type(''):
if type(value) is str:
proptype=propinfo.get('type', 'string')
if proptype in type_converters:
value=type_converters[proptype](value)
......
......@@ -189,9 +189,9 @@ class Item(Base,
# allow for a few different traceback options
if tb is None and error_tb is None:
tb=sys.exc_info()[2]
if type(tb) is not type('') and (error_tb is None):
if type(tb) is not str and (error_tb is None):
error_tb = pretty_tb(error_type, error_value, tb)
elif type(tb) is type('') and not error_tb:
elif type(tb) is str and not error_tb:
error_tb = tb
if hasattr(self, '_v_eek'):
......
......@@ -264,7 +264,7 @@ class BrowserIdManager(Item, Persistent, Implicit, RoleManager, Owned, Tabs):
o Enforce "valid" values.
"""
if not (type(k) is type('') and k and not badidnamecharsin(k)):
if not (type(k) is str and k and not badidnamecharsin(k)):
raise BrowserIdManagerErr(
'Bad id name string %s' % escape(repr(k)))
self.browserid_name = k
......@@ -288,7 +288,7 @@ class BrowserIdManager(Item, Persistent, Implicit, RoleManager, Owned, Tabs):
security.declareProtected(CHANGE_IDMGR_PERM, 'setCookiePath')
def setCookiePath(self, path=''):
""" sets cookie 'path' element for id cookie """
if not (type(path) is type('') and not badcookiecharsin(path)):
if not (type(path) is str and not badcookiecharsin(path)):
raise BrowserIdManagerErr(
'Bad cookie path %s' % escape(repr(path)))
self.cookie_path = path
......@@ -315,7 +315,7 @@ class BrowserIdManager(Item, Persistent, Implicit, RoleManager, Owned, Tabs):
security.declareProtected(CHANGE_IDMGR_PERM, 'setCookieDomain')
def setCookieDomain(self, domain):
""" sets cookie 'domain' element for id cookie """
if type(domain) is not type(''):
if type(domain) is not str:
raise BrowserIdManagerErr(
'Cookie domain must be string: %s'
% escape(repr(domain)))
......
......@@ -158,7 +158,7 @@ class SessionDataManager(Item, Implicit, Persistent, RoleManager, Owned, Tabs):
""" """
if not path:
self.obpath = None # undefined state
elif type(path) is type(''):
elif type(path) is str:
if bad_path_chars_in(path):
raise SessionDataManagerErr(
'Container path contains characters invalid in a Zope '
......
......@@ -222,7 +222,7 @@ class HTTPRequest(BaseRequest):
def setVirtualRoot(self, path, hard=0):
""" Treat the current publishing object as a VirtualRoot """
other = self.other
if isinstance(path, str) or isinstance(path, unicode):
if isinstance(path, basestring):
path = path.split('/')
self._script[:] = map(quote, filter(None, path))
del self._steps[:]
......@@ -241,7 +241,7 @@ class HTTPRequest(BaseRequest):
def physicalPathToVirtualPath(self, path):
""" Remove the path to the VirtualRoot from a physical path """
if type(path) is type(''):
if isinstance(path, basestring):
path = path.split( '/')
rpp = self.other.get('VirtualRootPhysicalPath', ('',))
i = 0
......
......@@ -163,7 +163,7 @@ class ZServerHTTPResponse(HTTPResponse):
"""
if type(data) != type(''):
if type(data) is not str:
raise TypeError('Value must be a string')
stdout = self.stdout
......@@ -174,7 +174,7 @@ class ZServerHTTPResponse(HTTPResponse):
l = self.headers.get('content-length', None)
if l is not None:
try:
if type(l) is type(''): l = int(l)
if type(l) is str: l = int(l)
if l > 128000:
self._tempfile = tempfile.TemporaryFile()
self._templock = thread.allocate_lock()
......
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