[Zope3-checkins] SVN: Zope3/trunk/src/zope/ do not use
os.path.split() when only the dirname or basename is needed
Fred L. Drake, Jr.
fdrake at gmail.com
Fri Aug 6 12:33:35 EDT 2004
Log message for revision 26937:
do not use os.path.split() when only the dirname or basename is needed
os.path.dirname() and .basename() provide better readability when only
part of a path is needed
Changed:
U Zope3/trunk/src/zope/app/apidoc/classmodule/__init__.py
U Zope3/trunk/src/zope/app/demo/passwdauth/tests.py
U Zope3/trunk/src/zope/app/form/browser/tests/test_directives.py
U Zope3/trunk/src/zope/app/publisher/browser/tests/test_directives.py
U Zope3/trunk/src/zope/app/publisher/browser/tests/test_directoryresource.py
U Zope3/trunk/src/zope/app/publisher/browser/tests/test_fileresource.py
U Zope3/trunk/src/zope/app/publisher/browser/tests/test_pagetemplateresource.py
U Zope3/trunk/src/zope/app/publisher/browser/tests/testi18nfileresource.py
U Zope3/trunk/src/zope/configuration/config.py
U Zope3/trunk/src/zope/configuration/name.py
U Zope3/trunk/src/zope/configuration/stxdocs.py
U Zope3/trunk/src/zope/configuration/tests/test_xmlconfig.py
U Zope3/trunk/src/zope/configuration/xmlconfig.py
U Zope3/trunk/src/zope/configuration/zopeconfigure.py
U Zope3/trunk/src/zope/event/tests.py
U Zope3/trunk/src/zope/i18n/tests/test_gettextmessagecatalog.py
U Zope3/trunk/src/zope/index/text/tests/hs-tool.py
U Zope3/trunk/src/zope/interface/tests/docfilesuite.py
U Zope3/trunk/src/zope/structuredtext/tests.py
U Zope3/trunk/src/zope/testing/doctestunit.py
-=-
Modified: Zope3/trunk/src/zope/app/apidoc/classmodule/__init__.py
===================================================================
--- Zope3/trunk/src/zope/app/apidoc/classmodule/__init__.py 2004-08-06 15:51:24 UTC (rev 26936)
+++ Zope3/trunk/src/zope/app/apidoc/classmodule/__init__.py 2004-08-06 16:33:35 UTC (rev 26937)
@@ -203,7 +203,7 @@
if hasattr(self.__module, '__file__') and \
(self.__module.__file__.endswith('__init__.py') or
self.__module.__file__.endswith('__init__.pyc')):
- dir = os.path.split(self.__module.__file__)[0]
+ dir = os.path.dirname(self.__module.__file__)
for file in os.listdir(dir):
if file in IGNORE_FILES:
continue
Modified: Zope3/trunk/src/zope/app/demo/passwdauth/tests.py
===================================================================
--- Zope3/trunk/src/zope/app/demo/passwdauth/tests.py 2004-08-06 15:51:24 UTC (rev 26936)
+++ Zope3/trunk/src/zope/app/demo/passwdauth/tests.py 2004-08-06 16:33:35 UTC (rev 26937)
@@ -23,7 +23,7 @@
class PasswdPrincipalSourceTest(TestCase):
def setUp(self):
- dir = os.path.split(passwdauth.__file__)[0]
+ dir = os.path.dirname(passwdauth.__file__)
self.source = passwdauth.PasswdPrincipalSource(
os.path.join(dir, 'passwd.sample'))
Modified: Zope3/trunk/src/zope/app/form/browser/tests/test_directives.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/tests/test_directives.py 2004-08-06 15:51:24 UTC (rev 26936)
+++ Zope3/trunk/src/zope/app/form/browser/tests/test_directives.py 2004-08-06 16:33:35 UTC (rev 26937)
@@ -37,7 +37,7 @@
from zope.app.form.browser import TextWidget
tests_path = os.path.join(
- os.path.split(zope.app.publisher.browser.__file__)[0],
+ os.path.dirname(zope.app.publisher.browser.__file__),
'tests')
template = """<configure
Modified: Zope3/trunk/src/zope/app/publisher/browser/tests/test_directives.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/tests/test_directives.py 2004-08-06 15:51:24 UTC (rev 26936)
+++ Zope3/trunk/src/zope/app/publisher/browser/tests/test_directives.py 2004-08-06 16:33:35 UTC (rev 26937)
@@ -50,7 +50,7 @@
from zope.app.security.interfaces import IPermission
tests_path = os.path.join(
- os.path.split(zope.app.publisher.browser.__file__)[0],
+ os.path.dirname(zope.app.publisher.browser.__file__),
'tests')
template = """<configure
Modified: Zope3/trunk/src/zope/app/publisher/browser/tests/test_directoryresource.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/tests/test_directoryresource.py 2004-08-06 15:51:24 UTC (rev 26936)
+++ Zope3/trunk/src/zope/app/publisher/browser/tests/test_directoryresource.py 2004-08-06 16:33:35 UTC (rev 26937)
@@ -36,7 +36,7 @@
from zope.app.traversing.interfaces import IContainmentRoot
from zope.app.site.interfaces import ISite
-test_directory = os.path.split(p.__file__)[0]
+test_directory = os.path.dirname(p.__file__)
checker = NamesChecker(
('get', '__getitem__', 'request', 'publishTraverse')
Modified: Zope3/trunk/src/zope/app/publisher/browser/tests/test_fileresource.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/tests/test_fileresource.py 2004-08-06 15:51:24 UTC (rev 26936)
+++ Zope3/trunk/src/zope/app/publisher/browser/tests/test_fileresource.py 2004-08-06 16:33:35 UTC (rev 26937)
@@ -38,7 +38,7 @@
('__call__', 'HEAD', 'request', 'publishTraverse', 'GET')
)
-test_directory = os.path.split(p.__file__)[0]
+test_directory = os.path.dirname(p.__file__)
class Test(PlacelessSetup, TestCase):
Modified: Zope3/trunk/src/zope/app/publisher/browser/tests/test_pagetemplateresource.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/tests/test_pagetemplateresource.py 2004-08-06 15:51:24 UTC (rev 26936)
+++ Zope3/trunk/src/zope/app/publisher/browser/tests/test_pagetemplateresource.py 2004-08-06 16:33:35 UTC (rev 26937)
@@ -30,7 +30,7 @@
from zope.app.traversing.adapters import DefaultTraversable
import zope.app.publisher.browser.tests as p
-test_directory = os.path.split(p.__file__)[0]
+test_directory = os.path.dirname(p.__file__)
checker = NamesChecker(
('__call__', 'request', 'publishTraverse')
Modified: Zope3/trunk/src/zope/app/publisher/browser/tests/testi18nfileresource.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/tests/testi18nfileresource.py 2004-08-06 15:51:24 UTC (rev 26936)
+++ Zope3/trunk/src/zope/app/publisher/browser/tests/testi18nfileresource.py 2004-08-06 16:33:35 UTC (rev 26937)
@@ -39,7 +39,7 @@
from zope.i18n.tests.testii18naware import TestII18nAware
-test_directory = os.path.split(p.__file__)[0]
+test_directory = os.path.dirname(p.__file__)
class Test(PlacelessSetup, TestII18nAware):
Modified: Zope3/trunk/src/zope/configuration/config.py
===================================================================
--- Zope3/trunk/src/zope/configuration/config.py 2004-08-06 15:51:24 UTC (rev 26936)
+++ Zope3/trunk/src/zope/configuration/config.py 2004-08-06 16:33:35 UTC (rev 26937)
@@ -228,7 +228,7 @@
>>> import zope.configuration
>>> c.package = zope.configuration
>>> import os
- >>> d = os.path.split(zope.configuration.__file__)[0]
+ >>> d = os.path.dirname(zope.configuration.__file__)
>>> c.path("y/z") == d + os.path.normpath("/y/z")
1
>>> c.path("y/./z") == d + os.path.normpath("/y/z")
@@ -251,7 +251,7 @@
if self.package is None:
basepath = os.getcwd()
else:
- basepath = os.path.split(self.package.__file__)[0]
+ basepath = os.path.dirname(self.package.__file__)
self.basepath = basepath
return os.path.join(basepath, filename)
@@ -276,7 +276,7 @@
>>> import zope.configuration
>>> c.package = zope.configuration
>>> import os
- >>> d = os.path.split(zope.configuration.__file__)[0]
+ >>> d = os.path.dirname(zope.configuration.__file__)
>>> c.checkDuplicate('bar.zcml')
>>> try:
... c.checkDuplicate(d + os.path.normpath('/bar.zcml'))
@@ -310,7 +310,7 @@
>>> import zope.configuration
>>> c.package = zope.configuration
>>> import os
- >>> d = os.path.split(zope.configuration.__file__)[0]
+ >>> d = os.path.dirname(zope.configuration.__file__)
>>> c.processFile('bar.zcml')
True
>>> c.processFile('bar.zcml')
Modified: Zope3/trunk/src/zope/configuration/name.py
===================================================================
--- Zope3/trunk/src/zope/configuration/name.py 2004-08-06 15:51:24 UTC (rev 26936)
+++ Zope3/trunk/src/zope/configuration/name.py 2004-08-06 16:33:35 UTC (rev 26937)
@@ -79,7 +79,7 @@
return file
raise
- path = os.path.split(package.__file__)[0]
+ path = os.path.dirname(package.__file__)
if file:
path = os.path.join(path, file)
return path
Modified: Zope3/trunk/src/zope/configuration/stxdocs.py
===================================================================
--- Zope3/trunk/src/zope/configuration/stxdocs.py 2004-08-06 15:51:24 UTC (rev 26936)
+++ Zope3/trunk/src/zope/configuration/stxdocs.py 2004-08-06 16:33:35 UTC (rev 26937)
@@ -53,7 +53,7 @@
if isinstance(info, xmlconfig.ParserInfo):
# We do not want to specify the whole path; starting at the 'zope'
# package is enough.
- base_dir = os.path.split(zope.__file__)[0][:-4]
+ base_dir = os.path.dirname(zope.__file__)[:-4]
file = info.file.replace(base_dir, '')
info_text = 'File %s, lines %i - %i.' %(file, info.line, info.eline)
Modified: Zope3/trunk/src/zope/configuration/tests/test_xmlconfig.py
===================================================================
--- Zope3/trunk/src/zope/configuration/tests/test_xmlconfig.py 2004-08-06 15:51:24 UTC (rev 26936)
+++ Zope3/trunk/src/zope/configuration/tests/test_xmlconfig.py 2004-08-06 16:33:35 UTC (rev 26937)
@@ -46,7 +46,7 @@
self.end_called = 1
def path(*p):
- return os.path.join(os.path.split(__file__)[0], *p)
+ return os.path.join(os.path.dirname(__file__), *p)
def test_ConfigurationHandler_normal():
"""
@@ -245,7 +245,7 @@
"""
>>> context = config.ConfigurationMachine()
>>> xmlconfig.registerCommonDirectives(context)
- >>> here = os.path.split(__file__)[0]
+ >>> here = os.path.dirname(__file__)
>>> path = os.path.join(here, "samplepackage", "foo.zcml")
>>> xmlconfig.include(context, path)
>>> context.execute_actions()
@@ -275,7 +275,7 @@
"""
>>> context = config.ConfigurationMachine()
>>> xmlconfig.registerCommonDirectives(context)
- >>> here = os.path.split(__file__)[0]
+ >>> here = os.path.dirname(__file__)
>>> path = os.path.join(here, "samplepackage/baz*.zcml")
>>> xmlconfig.include(context, files=path)
>>> context.execute_actions()
@@ -363,7 +363,7 @@
>>> context = config.ConfigurationMachine()
>>> xmlconfig.registerCommonDirectives(context)
- >>> here = os.path.split(__file__)[0]
+ >>> here = os.path.dirname(__file__)
>>> path = os.path.join(here, "samplepackage", "bar.zcml")
>>> xmlconfig.include(context, path)
@@ -498,7 +498,7 @@
We'll use the same example from test_includeOverrides:
- >>> here = os.path.split(__file__)[0]
+ >>> here = os.path.dirname(__file__)
>>> path = os.path.join(here, "samplepackage", "baro.zcml")
First, process the configuration file:
Modified: Zope3/trunk/src/zope/configuration/xmlconfig.py
===================================================================
--- Zope3/trunk/src/zope/configuration/xmlconfig.py 2004-08-06 15:51:24 UTC (rev 26936)
+++ Zope3/trunk/src/zope/configuration/xmlconfig.py 2004-08-06 16:33:35 UTC (rev 26937)
@@ -140,7 +140,7 @@
file = self.file
if file == 'tests//sample.zcml':
# special case for testing
- file = os.path.join(os.path.split(__file__)[0],
+ file = os.path.join(os.path.dirname(__file__),
'tests', 'sample.zcml')
try:
@@ -262,7 +262,7 @@
If we open configure.zcml, we'll get that file:
- >>> here = os.path.split(__file__)[0]
+ >>> here = os.path.dirname(__file__)
>>> path = os.path.join(here, 'tests', 'samplepackage', 'configure.zcml')
>>> f = openInOrPlain(path)
>>> f.name[-14:]
@@ -377,7 +377,7 @@
f = openInOrPlain(path)
logger.debug("include %s" % f.name)
- context.basepath = os.path.split(path)[0]
+ context.basepath = os.path.dirname(path)
context.includepath = _context.includepath + (f.name, )
_context.stack.append(config.GroupingStackItem(context))
Modified: Zope3/trunk/src/zope/configuration/zopeconfigure.py
===================================================================
--- Zope3/trunk/src/zope/configuration/zopeconfigure.py 2004-08-06 15:51:24 UTC (rev 26936)
+++ Zope3/trunk/src/zope/configuration/zopeconfigure.py 2004-08-06 16:33:35 UTC (rev 26937)
@@ -143,5 +143,5 @@
if 'package' in kw:
# if we have a package, we want to also define basepath
# so we don't acquire one
- self.basepath = os.path.split(self.package.__file__)[0]
+ self.basepath = os.path.dirname(self.package.__file__)
Modified: Zope3/trunk/src/zope/event/tests.py
===================================================================
--- Zope3/trunk/src/zope/event/tests.py 2004-08-06 15:51:24 UTC (rev 26936)
+++ Zope3/trunk/src/zope/event/tests.py 2004-08-06 16:33:35 UTC (rev 26937)
@@ -30,7 +30,7 @@
# that failed.
t = doctest.Tester(globs={'__name__': '__main__'})
suite = unittest.TestSuite()
- dir = os.path.split(__file__)[0]
+ dir = os.path.dirname(__file__)
for path in paths:
path = os.path.join(dir, path)
source = open(path).read()
Modified: Zope3/trunk/src/zope/i18n/tests/test_gettextmessagecatalog.py
===================================================================
--- Zope3/trunk/src/zope/i18n/tests/test_gettextmessagecatalog.py 2004-08-06 15:51:24 UTC (rev 26936)
+++ Zope3/trunk/src/zope/i18n/tests/test_gettextmessagecatalog.py 2004-08-06 16:33:35 UTC (rev 26937)
@@ -24,7 +24,7 @@
def _getMessageCatalog(self):
from zope.i18n import tests
- path = os.path.split(tests.__file__)[0]
+ path = os.path.dirname(tests.__file__)
self._path = os.path.join(path, 'en-default.mo')
catalog = GettextMessageCatalog('en', 'default', self._path)
return catalog
Modified: Zope3/trunk/src/zope/index/text/tests/hs-tool.py
===================================================================
--- Zope3/trunk/src/zope/index/text/tests/hs-tool.py 2004-08-06 15:51:24 UTC (rev 26936)
+++ Zope3/trunk/src/zope/index/text/tests/hs-tool.py 2004-08-06 16:33:35 UTC (rev 26937)
@@ -36,7 +36,7 @@
try:
return cache[path]
except KeyError:
- fn = os.path.split(path)[1]
+ fn = os.path.basename(path)
cache[path] = fn
return fn
Modified: Zope3/trunk/src/zope/interface/tests/docfilesuite.py
===================================================================
--- Zope3/trunk/src/zope/interface/tests/docfilesuite.py 2004-08-06 15:51:24 UTC (rev 26936)
+++ Zope3/trunk/src/zope/interface/tests/docfilesuite.py 2004-08-06 16:33:35 UTC (rev 26937)
@@ -30,7 +30,7 @@
# that failed.
t = doctest.Tester(globs={'__name__': '__main__'})
suite = unittest.TestSuite()
- dir = os.path.split(__file__)[0]
+ dir = os.path.dirname(__file__)
for path in paths:
path = os.path.join(dir, path)
source = open(path).read()
Modified: Zope3/trunk/src/zope/structuredtext/tests.py
===================================================================
--- Zope3/trunk/src/zope/structuredtext/tests.py 2004-08-06 15:51:24 UTC (rev 26936)
+++ Zope3/trunk/src/zope/structuredtext/tests.py 2004-08-06 16:33:35 UTC (rev 26937)
@@ -23,7 +23,7 @@
from zope.structuredtext.document import Document
from zope.structuredtext.html import HTML
-package_dir = os.path.split(stng.__file__)[0]
+package_dir = os.path.dirname(stng.__file__)
regressions = os.path.join(package_dir, 'regressions')
files = ['index.stx','Acquisition.stx','ExtensionClass.stx',
Modified: Zope3/trunk/src/zope/testing/doctestunit.py
===================================================================
--- Zope3/trunk/src/zope/testing/doctestunit.py 2004-08-06 15:51:24 UTC (rev 26936)
+++ Zope3/trunk/src/zope/testing/doctestunit.py 2004-08-06 16:33:35 UTC (rev 26937)
@@ -111,7 +111,7 @@
package = _normalizeModule(package)
name = path.split('/')[-1]
- dir = os.path.split(package.__file__)[0]
+ dir = os.path.dirname(package.__file__)
path = os.path.join(dir, *(path.split('/')))
doc = open(path).read()
tester = doctest.Tester(globs=(globs or {}))
More information about the Zope3-Checkins
mailing list