Commit b3fa9c1b authored by Nikolay Kim's avatar Nikolay Kim

micro optimization

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