[Checkins] SVN: ZConfig/trunk/ Initial port to Python 3. For some reason tox really acts up on Python
Stephen Richter
cvs-admin at zope.org
Tue Feb 12 21:55:43 UTC 2013
Log message for revision 129322:
Initial port to Python 3. For some reason tox really acts up on Python
2.6 with the XML parser, so I removed its support.
Changed:
_U ZConfig/trunk/
A ZConfig/trunk/MANIFEST.in
U ZConfig/trunk/NEWS.txt
U ZConfig/trunk/ZConfig/__init__.py
U ZConfig/trunk/ZConfig/cfgparser.py
U ZConfig/trunk/ZConfig/cmdline.py
U ZConfig/trunk/ZConfig/components/basic/tests/test_mapping.py
U ZConfig/trunk/ZConfig/components/logger/datatypes.py
U ZConfig/trunk/ZConfig/components/logger/handlers.py
U ZConfig/trunk/ZConfig/components/logger/tests/test_logger.py
U ZConfig/trunk/ZConfig/datatypes.py
U ZConfig/trunk/ZConfig/info.py
U ZConfig/trunk/ZConfig/loader.py
U ZConfig/trunk/ZConfig/matcher.py
U ZConfig/trunk/ZConfig/schema.py
U ZConfig/trunk/ZConfig/schemaless.py
U ZConfig/trunk/ZConfig/schemaless.txt
U ZConfig/trunk/ZConfig/tests/support.py
U ZConfig/trunk/ZConfig/tests/test_cfgimports.py
U ZConfig/trunk/ZConfig/tests/test_cmdline.py
U ZConfig/trunk/ZConfig/tests/test_config.py
U ZConfig/trunk/ZConfig/tests/test_datatypes.py
U ZConfig/trunk/ZConfig/tests/test_loader.py
U ZConfig/trunk/ZConfig/tests/test_schema.py
U ZConfig/trunk/ZConfig/url.py
U ZConfig/trunk/bootstrap.py
U ZConfig/trunk/setup.py
A ZConfig/trunk/tox.ini
-=-
Property changes on: ZConfig/trunk
___________________________________________________________________
Modified: svn:ignore
- bin
build
develop-eggs
dist
eggs
parts
.installed.cfg
*.egg-info
+ bin
build
develop-eggs
dist
eggs
parts
.installed.cfg
.tox
.coverage
*.egg-info
*.xml
Added: ZConfig/trunk/MANIFEST.in
===================================================================
--- ZConfig/trunk/MANIFEST.in (rev 0)
+++ ZConfig/trunk/MANIFEST.in 2013-02-12 21:55:42 UTC (rev 129322)
@@ -0,0 +1,10 @@
+include *.rst
+include *.txt
+include tox.ini
+include bootstrap.py
+include buildout.cfg
+
+recursive-include ZConfig *
+recursive-include doc *
+
+global-exclude *.pyc
Modified: ZConfig/trunk/NEWS.txt
===================================================================
--- ZConfig/trunk/NEWS.txt 2013-02-12 17:37:48 UTC (rev 129321)
+++ ZConfig/trunk/NEWS.txt 2013-02-12 21:55:42 UTC (rev 129322)
@@ -2,13 +2,21 @@
Change History for ZConfig
==========================
+ZConfig 3.0.0b1 (unreleased)
+----------------------------
+- Add Python 3.3 support.
+
+- Drop Python 2.4, 2.5 and 2.6 support.
+
+
ZConfig 2.9.3 (2012-06-25)
--------------------------
- Fixed: port values of 0 weren't allowed. Port 0 is used to request
an ephemeral port.
+
ZConfig 2.9.2 (2012-02-11)
--------------------------
Modified: ZConfig/trunk/ZConfig/__init__.py
===================================================================
--- ZConfig/trunk/ZConfig/__init__.py 2013-02-12 17:37:48 UTC (rev 129321)
+++ ZConfig/trunk/ZConfig/__init__.py 2013-02-12 21:55:42 UTC (rev 129322)
@@ -35,16 +35,22 @@
"""
__docformat__ = "reStructuredText"
-version_info = (2, 3)
+version_info = (3, 0)
__version__ = ".".join([str(n) for n in version_info])
from ZConfig.loader import loadConfig, loadConfigFile
from ZConfig.loader import loadSchema, loadSchemaFile
+try:
+ import cStringIO as StringIO
+except ImportError:
+ # Python 3 support.
+ import io as StringIO
+
class ConfigurationError(Exception):
"""Base class for ZConfig exceptions."""
-
+
# The 'message' attribute was deprecated for BaseException with
# Python 2.6; here we create descriptor properties to continue using it
def __set_message(self, v):
@@ -158,12 +164,11 @@
self.source = source
self.name = name
ConfigurationSyntaxError.__init__(
- self, "no replacement for " + `name`, url, lineno)
+ self, "no replacement for " + repr(name), url, lineno)
def configureLoggers(text):
"""Configure one or more loggers from configuration text."""
- import StringIO
schema = loadSchemaFile(StringIO.StringIO("""
<schema>
<import package='ZConfig.components.logger'/>
Modified: ZConfig/trunk/ZConfig/cfgparser.py
===================================================================
--- ZConfig/trunk/ZConfig/cfgparser.py 2013-02-12 17:37:48 UTC (rev 129321)
+++ ZConfig/trunk/ZConfig/cfgparser.py 2013-02-12 21:55:42 UTC (rev 129322)
@@ -88,8 +88,8 @@
name = self._normalize_case(name)
try:
newsect = self.context.startSection(section, type, name)
- except ZConfig.ConfigurationError, e:
- self.error(e[0])
+ except ZConfig.ConfigurationError as e:
+ self.error(e.message)
if isempty:
self.context.endSection(section, type, name, newsect)
@@ -108,12 +108,15 @@
try:
self.context.endSection(
prevsection, type, name, section)
- except ZConfig.ConfigurationError, e:
- self.error(e[0])
+ except ZConfig.ConfigurationError as e:
+ self.error(e.args[0])
return prevsection
def handle_key_value(self, section, rest):
- m = _keyvalue_rx.match(rest)
+ try:
+ m = _keyvalue_rx.match(rest)
+ except:
+ import pdb; pdb.set_trace()
if not m:
self.error("malformed configuration data")
key, value = m.group('key', 'value')
@@ -123,8 +126,8 @@
value = self.replace(value)
try:
section.addValue(key, value, (self.lineno, None, self.url))
- except ZConfig.ConfigurationError, e:
- self.error(e[0])
+ except ZConfig.ConfigurationError as e:
+ self.error(e.args[0])
def handle_directive(self, section, rest):
m = _keyvalue_rx.match(rest)
@@ -132,7 +135,7 @@
self.error("missing or unrecognized directive")
name, arg = m.group('key', 'value')
if name not in ("define", "import", "include"):
- self.error("unknown directive: " + `name`)
+ self.error("unknown directive: " + repr(name))
if not arg:
self.error("missing argument to %%%s directive" % name)
if name == "include":
@@ -142,7 +145,7 @@
elif name == "import":
self.handle_import(section, arg)
else:
- assert 0, "unexpected directive for " + `"%" + rest`
+ assert 0, "unexpected directive for " + repr("%" + rest)
def handle_import(self, section, rest):
pkgname = self.replace(rest.strip())
@@ -159,17 +162,17 @@
defvalue = ''
if len(parts) == 2:
defvalue = parts[1]
- if self.defines.has_key(defname):
+ if defname in self.defines:
if self.defines[defname] != defvalue:
- self.error("cannot redefine " + `defname`)
+ self.error("cannot redefine " + repr(defname))
if not isname(defname):
- self.error("not a substitution legal name: " + `defname`)
+ self.error("not a substitution legal name: " + repr(defname))
self.defines[defname] = self.replace(defvalue)
def replace(self, text):
try:
return substitute(text, self.defines)
- except ZConfig.SubstitutionReplacementError, e:
+ except ZConfig.SubstitutionReplacementError as e:
e.lineno = self.lineno
e.url = self.url
raise
Modified: ZConfig/trunk/ZConfig/cmdline.py
===================================================================
--- ZConfig/trunk/ZConfig/cmdline.py 2013-02-12 17:37:48 UTC (rev 129321)
+++ ZConfig/trunk/ZConfig/cmdline.py 2013-02-12 21:55:42 UTC (rev 129322)
@@ -89,15 +89,15 @@
"could not convert basic-key value", *pos)
def add_value(self, name, val, pos):
- if self.keypairs.has_key(name):
+ if name in self.keypairs:
L = self.keypairs[name]
else:
L = []
self.keypairs[name] = L
L.append((val, pos))
- def has_key(self, name):
- return self.keypairs.has_key(name)
+ def __contains__(self, name):
+ return name in self.keypairs
def get_key(self, name):
"""Return a list of (value, pos) items for the key 'name'.
@@ -149,9 +149,9 @@
def addValue(self, key, value, position):
try:
realkey = self.type.keytype(key)
- except ValueError, e:
+ except ValueError as e:
raise ZConfig.DataConversionError(e, key, position)
- if self.optionbag.has_key(realkey):
+ if realkey in self.optionbag:
return
ZConfig.matcher.BaseMatcher.addValue(self, key, value, position)
@@ -165,7 +165,7 @@
return sm
def finish_optionbag(self):
- for key in self.optionbag.keys():
+ for key in list(self.optionbag.keys()):
for val, pos in self.optionbag.get_key(key):
ZConfig.matcher.BaseMatcher.addValue(self, key, val, pos)
self.optionbag.finish()
Modified: ZConfig/trunk/ZConfig/components/basic/tests/test_mapping.py
===================================================================
--- ZConfig/trunk/ZConfig/components/basic/tests/test_mapping.py 2013-02-12 17:37:48 UTC (rev 129321)
+++ ZConfig/trunk/ZConfig/components/basic/tests/test_mapping.py 2013-02-12 21:55:42 UTC (rev 129322)
@@ -68,8 +68,7 @@
key-two value-two
</dict>
""")
- L = conf.simple_dict.items()
- L.sort()
+ L = sorted(conf.simple_dict.items())
self.assertEqual(L, [("key-one", "value-one"),
("key-two", "value-two")])
@@ -81,8 +80,7 @@
42 question?
</intkeys>
""")
- L = conf.int_dict.items()
- L.sort()
+ L = sorted(conf.int_dict.items())
self.assertEqual(L, [(1, "foo"), (2, "bar"), (42, "question?")])
Modified: ZConfig/trunk/ZConfig/components/logger/datatypes.py
===================================================================
--- ZConfig/trunk/ZConfig/components/logger/datatypes.py 2013-02-12 17:37:48 UTC (rev 129321)
+++ ZConfig/trunk/ZConfig/components/logger/datatypes.py 2013-02-12 21:55:42 UTC (rev 129322)
@@ -30,10 +30,10 @@
def logging_level(value):
s = str(value).lower()
- if _logging_levels.has_key(s):
+ if s in _logging_levels:
return _logging_levels[s]
else:
v = int(s)
if v < 0 or v > 50:
- raise ValueError("log level not in range: " + `v`)
+ raise ValueError("log level not in range: " + repr(v))
return v
Modified: ZConfig/trunk/ZConfig/components/logger/handlers.py
===================================================================
--- ZConfig/trunk/ZConfig/components/logger/handlers.py 2013-02-12 17:37:48 UTC (rev 129321)
+++ ZConfig/trunk/ZConfig/components/logger/handlers.py 2013-02-12 21:55:42 UTC (rev 129322)
@@ -17,6 +17,11 @@
from ZConfig.components.logger.factory import Factory
+try:
+ import urlparse
+except ImportError:
+ # Python 3 support.
+ import urllib.parse as urlparse
_log_format_variables = {
'name': '',
@@ -153,9 +158,8 @@
def syslog_facility(value):
value = value.lower()
- if not _syslog_facilities.has_key(value):
- L = _syslog_facilities.keys()
- L.sort()
+ if value not in _syslog_facilities:
+ L = sorted(_syslog_facilities.keys())
raise ValueError("Syslog facility must be one of " + ", ".join(L))
return value
@@ -171,7 +175,6 @@
return loghandler.Win32EventLogHandler(self.section.appname)
def http_handler_url(value):
- import urlparse
scheme, netloc, path, param, query, fragment = urlparse.urlparse(value)
if scheme != 'http':
raise ValueError('url must be an http url')
Modified: ZConfig/trunk/ZConfig/components/logger/tests/test_logger.py
===================================================================
--- ZConfig/trunk/ZConfig/components/logger/tests/test_logger.py 2013-02-12 17:37:48 UTC (rev 129321)
+++ ZConfig/trunk/ZConfig/components/logger/tests/test_logger.py 2013-02-12 21:55:42 UTC (rev 129322)
@@ -14,7 +14,6 @@
"""Tests for logging configuration via ZConfig."""
-import cStringIO as StringIO
import doctest
import logging
import os
@@ -28,6 +27,11 @@
from ZConfig.components.logger import handlers
from ZConfig.components.logger import loghandler
+try:
+ import cStringIO as StringIO
+except ImportError:
+ # Python 3 support.
+ import io as StringIO
class CustomFormatter(logging.Formatter):
def formatException(self, ei):
@@ -122,6 +126,8 @@
"critical"]:
self.assertEqual(convert(name), convert(name.upper()))
self.assertRaises(ValueError, convert, "hopefully-not-a-valid-value")
+ self.assertEqual(convert('10'), 10)
+ self.assertRaises(ValueError, convert, '100')
def test_http_method(self):
convert = handlers.get_or_post
Modified: ZConfig/trunk/ZConfig/datatypes.py
===================================================================
--- ZConfig/trunk/ZConfig/datatypes.py 2013-02-12 17:37:48 UTC (rev 129321)
+++ ZConfig/trunk/ZConfig/datatypes.py 2013-02-12 21:55:42 UTC (rev 129322)
@@ -54,10 +54,10 @@
v = self._conversion(value)
if self._min is not None and v < self._min:
raise ValueError("%s is below lower bound (%s)"
- % (`v`, `self._min`))
+ % (repr(v), repr(self._min)))
if self._max is not None and v > self._max:
raise ValueError("%s is above upper bound (%s)"
- % (`v`, `self._max`))
+ % (repr(v), repr(self._max)))
return v
@@ -136,12 +136,7 @@
def integer(value):
- try:
- return int(value)
- except ValueError:
- return long(value)
- except OverflowError:
- return long(value)
+ return int(value)
def null_conversion(value):
@@ -245,9 +240,14 @@
def float_conversion(v):
- if isinstance(v, basestring):
+ try:
+ is_str = isinstance(v, basestring)
+ except NameError:
+ # Python 3 support.
+ is_str = isinstance(v, str)
+ if is_str:
if v.lower() in ["inf", "-inf", "nan"]:
- raise ValueError(`v` + " is not a portable float representation")
+ raise ValueError(repr(v) + " is not a portable float representation")
return float(v)
class IpaddrOrHostname(RegularExpressionConversion):
@@ -394,7 +394,7 @@
"existing-dirpath": existing_dirpath,
"byte-size": SuffixMultiplier({'kb': 1024,
'mb': 1024*1024,
- 'gb': 1024*1024*1024L,
+ 'gb': 1024*1024*1024,
}),
"time-interval": SuffixMultiplier({'s': 1,
'm': 60,
@@ -430,16 +430,16 @@
return t
def register(self, name, conversion):
- if self._stock.has_key(name):
+ if name in self._stock:
raise ValueError("datatype name conflicts with built-in type: "
- + `name`)
- if self._other.has_key(name):
- raise ValueError("datatype name already registered: " + `name`)
+ + repr(name))
+ if name in self._other:
+ raise ValueError("datatype name already registered: " + repr(name))
self._other[name] = conversion
def search(self, name):
if not "." in name:
- raise ValueError("unloadable datatype name: " + `name`)
+ raise ValueError("unloadable datatype name: " + repr(name))
components = name.split('.')
start = components[0]
g = {}
Modified: ZConfig/trunk/ZConfig/info.py
===================================================================
--- ZConfig/trunk/ZConfig/info.py 2013-02-12 17:37:48 UTC (rev 129321)
+++ ZConfig/trunk/ZConfig/info.py 2013-02-12 21:55:42 UTC (rev 129322)
@@ -14,7 +14,6 @@
"""Objects that can describe a ZConfig schema."""
import copy
-
import ZConfig
@@ -58,7 +57,7 @@
def convert(self, datatype):
try:
return datatype(self.value)
- except ValueError, e:
+ except ValueError as e:
raise ZConfig.DataConversionError(e, self.value, self.position)
@@ -87,7 +86,7 @@
def __repr__(self):
clsname = self.__class__.__name__
- return "<%s for %s>" % (clsname, `self.name`)
+ return "<%s for %s>" % (clsname, repr(self.name))
def isabstract(self):
return False
@@ -161,11 +160,11 @@
def add_valueinfo(self, vi, key):
if self.name == "+":
- if self._default.has_key(key):
+ if key in self._default:
# not ideal: we're presenting the unconverted
# version of the key
raise ZConfig.SchemaError(
- "duplicate default value for key %s" % `key`)
+ "duplicate default value for key %s" % repr(key))
self._default[key] = vi
elif self._default is not None:
raise ZConfig.SchemaError(
@@ -175,7 +174,7 @@
def computedefault(self, keytype):
self.prepare_raw_defaults()
- for k, vi in self._rawdefaults.iteritems():
+ for k, vi in self._rawdefaults.items():
key = ValueInfo(k, vi.position).convert(keytype)
self.add_valueinfo(vi, key)
@@ -209,7 +208,7 @@
def computedefault(self, keytype):
self.prepare_raw_defaults()
- for k, vlist in self._rawdefaults.iteritems():
+ for k, vlist in self._rawdefaults.items():
key = ValueInfo(k, vlist[0].position).convert(keytype)
for vi in vlist:
self.add_valueinfo(vi, key)
@@ -249,7 +248,7 @@
def __repr__(self):
clsname = self.__class__.__name__
return "<%s for %s (%s)>" % (
- clsname, self.sectiontype.name, `self.name`)
+ clsname, self.sectiontype.name, repr(self.name))
def issection(self):
return True
@@ -292,7 +291,7 @@
return self._subtypes[name]
except KeyError:
raise ZConfig.SchemaError("no sectiontype %s in abstracttype %s"
- % (`name`, `self.name`))
+ % (repr(name), repr(self.name)))
def hassubtype(self, name):
"""Return true iff this type has 'name' as a concrete manifestation."""
@@ -300,9 +299,7 @@
def getsubtypenames(self):
"""Return the names of all concrete types as a sorted list."""
- L = self._subtypes.keys()
- L.sort()
- return L
+ return sorted(self._subtypes.keys())
def isabstract(self):
return True
@@ -331,10 +328,10 @@
try:
return self._types[n]
except KeyError:
- raise ZConfig.SchemaError("unknown type name: " + `name`)
+ raise ZConfig.SchemaError("unknown type name: " + repr(name))
def gettypenames(self):
- return self._types.keys()
+ return list(self._types.keys())
def __len__(self):
return len(self._children)
@@ -345,10 +342,10 @@
def _add_child(self, key, info):
# check naming constraints
assert key or info.attribute
- if key and self._keymap.has_key(key):
+ if key and key in self._keymap:
raise ZConfig.SchemaError(
"child name %s already used" % key)
- if info.attribute and self._attrmap.has_key(info.attribute):
+ if info.attribute and info.attribute in self._attrmap:
raise ZConfig.SchemaError(
"child attribute name %s already used" % info.attribute)
# a-ok, add the item to the appropriate maps
@@ -372,7 +369,7 @@
try:
return self._keymap[key]
except KeyError:
- raise ZConfig.ConfigurationError("no key matching " + `key`)
+ raise ZConfig.ConfigurationError("no key matching " + repr(key))
def getrequiredtypes(self):
d = {}
@@ -384,10 +381,10 @@
for key, ci in info._children:
if ci.issection():
t = ci.sectiontype
- if not d.has_key(t.name):
+ if t.name not in d:
d[t.name] = 1
stack.append(t)
- return d.keys()
+ return list(d.keys())
def getsectioninfo(self, type, name):
for key, info in self._children:
@@ -403,17 +400,17 @@
except ZConfig.ConfigurationError:
raise ZConfig.ConfigurationError(
"section type %s not allowed for name %s"
- % (`type`, `key`))
+ % (repr(type), repr(key)))
if not st.name == type:
raise ZConfig.ConfigurationError(
"name %s must be used for a %s section"
- % (`name`, `st.name`))
+ % (repr(name), repr(st.name)))
return info
# else must be a sectiontype or an abstracttype:
elif info.sectiontype.name == type:
if not (name or info.allowUnnamed()):
raise ZConfig.ConfigurationError(
- `type` + " sections must be named")
+ repr(type) + " sections must be named")
return info
elif info.sectiontype.isabstract():
st = info.sectiontype
@@ -446,9 +443,9 @@
def addtype(self, typeinfo):
n = typeinfo.name
- if self._types.has_key(n):
+ if n in self._types:
raise ZConfig.SchemaError("type name cannot be redefined: "
- + `typeinfo.name`)
+ + repr(typeinfo.name))
self._types[n] = typeinfo
def allowUnnamed(self):
@@ -494,12 +491,12 @@
return t
def addComponent(self, name):
- if self._components.has_key(name):
+ if name in self._components:
raise ZConfig.SchemaError("already have component %s" % name)
self._components[name] = name
def hasComponent(self, name):
- return self._components.has_key(name)
+ return name in self._components
def createDerivedSchema(base):
Modified: ZConfig/trunk/ZConfig/loader.py
===================================================================
--- ZConfig/trunk/ZConfig/loader.py 2013-02-12 17:37:48 UTC (rev 129321)
+++ ZConfig/trunk/ZConfig/loader.py 2013-02-12 21:55:42 UTC (rev 129322)
@@ -13,12 +13,10 @@
##############################################################################
"""Schema loader utility."""
-import cStringIO
import os.path
import re
import sys
import urllib
-import urllib2
import ZConfig
import ZConfig.cfgparser
@@ -28,7 +26,25 @@
import ZConfig.schema
import ZConfig.url
+try:
+ import cStringIO as StringIO
+except ImportError:
+ # Python 3 support.
+ import io as StringIO
+try:
+ import urllib2
+except ImportError:
+ # Python 3 support
+ import urllib.request as urllib2
+
+try:
+ from urllib import pathname2url
+except ImportError:
+ # Python 3 support
+ from urllib.request import pathname2url
+
+
def loadSchema(url):
return SchemaLoader().loadURL(url)
@@ -98,20 +114,23 @@
else:
try:
file = urllib2.urlopen(url)
- except urllib2.URLError, e:
+ except urllib2.URLError as e:
# urllib2.URLError has a particularly hostile str(), so we
# generally don't want to pass it along to the user.
self._raise_open_error(url, e.reason)
- except (IOError, OSError), e:
+ except (IOError, OSError) as e:
# Python 2.1 raises a different error from Python 2.2+,
# so we catch both to make sure we detect the situation.
self._raise_open_error(url, str(e))
+ # Python 3 support: file.read() returns bytes, so we convert it to an
+ # StringIO.
+ file = StringIO.StringIO(file.read().decode())
return self.createResource(file, url)
def _raise_open_error(self, url, message):
if url[:7].lower() == "file://":
what = "file"
- ident = urllib.url2pathname(url[7:])
+ ident = urllib2.url2pathname(url[7:])
else:
what = "URL"
ident = url
@@ -121,7 +140,7 @@
def normalizeURL(self, url):
if self.isPath(url):
- url = "file://" + urllib.pathname2url(os.path.abspath(url))
+ url = "file://" + pathname2url(os.path.abspath(url))
newurl, fragment = ZConfig.url.urldefrag(url)
if fragment:
raise ZConfig.ConfigurationError(
@@ -164,18 +183,27 @@
filename=path,
package=package,
path=pkg.__path__)
- url = "file:" + urllib.pathname2url(filename)
+ url = "file:" + pathname2url(filename)
url = ZConfig.url.urlnormalize(url)
return urllib2.urlopen(url)
else:
- loadpath = os.path.join(os.path.dirname(pkg.__file__), path)
- return cStringIO.StringIO(loader.get_data(loadpath))
+ for dir in pkg.__path__:
+ loadpath = os.path.join(dir, path)
+ try:
+ return StringIO.StringIO(
+ loader.get_data(loadpath).decode('utf-8'))
+ except Exception:
+ pass
+ raise ZConfig.SchemaResourceError("schema component not found",
+ filename=path,
+ package=package,
+ path=pkg.__path__)
def _url_from_file(file):
name = getattr(file, "name", None)
if name and name[0] != "<" and name[-1] != ">":
- return "file://" + urllib.pathname2url(os.path.abspath(name))
+ return "file://" + pathname2url(os.path.abspath(name))
else:
return None
@@ -189,7 +217,7 @@
self._cache = {}
def loadResource(self, resource):
- if resource.url and self._cache.has_key(resource.url):
+ if resource.url and resource.url in self._cache:
schema = self._cache[resource.url]
else:
schema = ZConfig.schema.parseResource(resource, self)
@@ -202,15 +230,15 @@
parts = package.split(".")
if not parts:
raise ZConfig.SchemaError(
- "illegal schema component name: " + `package`)
+ "illegal schema component name: " + repr(package))
if "" in parts:
# '' somewhere in the package spec; still illegal
raise ZConfig.SchemaError(
- "illegal schema component name: " + `package`)
+ "illegal schema component name: " + repr(package))
file = file or "component.xml"
try:
__import__(package)
- except ImportError, e:
+ except ImportError as e:
raise ZConfig.SchemaResourceError(
"could not load package %s: %s" % (package, str(e)),
filename=file,
@@ -248,7 +276,7 @@
if t.isabstract():
raise ZConfig.ConfigurationError(
"concrete sections cannot match abstract section types;"
- " found abstract type " + `type`)
+ " found abstract type " + repr(type))
return parent.createChildMatcher(t, name)
def endSection(self, parent, type, name, matcher):
@@ -298,14 +326,14 @@
d = {}
for name, callback in handlermap.items():
n = self._convert(name)
- if d.has_key(n):
+ if n in d:
raise ZConfig.ConfigurationError(
"handler name not unique when converted to a basic-key: "
- + `name`)
+ + repr(name))
d[n] = callback
L = []
for handler, value in self._handlers:
- if not d.has_key(handler):
+ if handler not in d:
L.append(handler)
if L:
raise ZConfig.ConfigurationError(
Modified: ZConfig/trunk/ZConfig/matcher.py
===================================================================
--- ZConfig/trunk/ZConfig/matcher.py 2013-02-12 17:37:48 UTC (rev 129321)
+++ ZConfig/trunk/ZConfig/matcher.py 2013-02-12 21:55:42 UTC (rev 129322)
@@ -39,15 +39,15 @@
def __repr__(self):
clsname = self.__class__.__name__
- extra = "type " + `self.type.name`
+ extra = "type " + repr(self.type.name)
return "<%s for %s>" % (clsname, extra)
def addSection(self, type, name, sectvalue):
if name:
- if self._sectionnames.has_key(name):
+ if name in self._sectionnames:
raise ZConfig.ConfigurationError(
"section names must not be re-used within the"
- " same container:" + `name`)
+ " same container:" + repr(name))
self._sectionnames[name] = name
ci = self.type.getsectioninfo(type, name)
attr = ci.attribute
@@ -58,12 +58,12 @@
self._values[attr] = sectvalue
else:
raise ZConfig.ConfigurationError(
- "too many instances of %s section" % `ci.sectiontype.name`)
+ "too many instances of %s section" % repr(ci.sectiontype.name))
def addValue(self, key, value, position):
try:
realkey = self.type.keytype(key)
- except ValueError, e:
+ except ValueError as e:
raise ZConfig.DataConversionError(e, key, position)
arbkey_info = None
for i in range(len(self.type)):
@@ -75,15 +75,15 @@
else:
if arbkey_info is None:
raise ZConfig.ConfigurationError(
- `key` + " is not a known key name")
+ repr(key) + " is not a known key name")
k, ci = arbkey_info
if ci.issection():
if ci.name:
- extra = " in %s sections" % `self.type.name`
+ extra = " in %s sections" % repr(self.type.name)
else:
extra = ""
raise ZConfig.ConfigurationError(
- "%s is not a valid key name%s" % (`key`, extra))
+ "%s is not a valid key name%s" % (repr(key), extra))
ismulti = ci.ismulti()
attr = ci.attribute
@@ -98,22 +98,22 @@
elif not ismulti:
if k != '+':
raise ZConfig.ConfigurationError(
- `key` + " does not support multiple values")
+ repr(key) + " does not support multiple values")
elif len(v) == ci.maxOccurs:
raise ZConfig.ConfigurationError(
- "too many values for " + `name`)
+ "too many values for " + repr(name))
value = ValueInfo(value, position)
if k == '+':
if ismulti:
- if v.has_key(realkey):
+ if realkey in v:
v[realkey].append(value)
else:
v[realkey] = [value]
else:
- if v.has_key(realkey):
+ if realkey in v:
raise ZConfig.ConfigurationError(
- "too many values for " + `key`)
+ "too many values for " + repr(key))
v[realkey] = value
elif ismulti:
v.append(value)
@@ -126,7 +126,7 @@
if not ci.isAllowedName(name):
raise ZConfig.ConfigurationError(
"%s is not an allowed name for %s sections"
- % (`name`, `ci.sectiontype.name`))
+ % (repr(name), repr(ci.sectiontype.name)))
return SectionMatcher(ci, type, name, self.handlers)
def finish(self):
@@ -137,7 +137,7 @@
if key:
key = repr(key)
else:
- key = "section type " + `ci.sectiontype.name`
+ key = "section type " + repr(ci.sectiontype.name)
assert ci.attribute is not None
attr = ci.attribute
v = values[attr]
@@ -186,7 +186,7 @@
st = s.getSectionDefinition()
try:
s = st.datatype(s)
- except ValueError, e:
+ except ValueError as e:
raise ZConfig.DataConversionError(
e, s, (-1, -1, None))
v.append(s)
@@ -201,7 +201,7 @@
st = values[attr].getSectionDefinition()
try:
v = st.datatype(values[attr])
- except ValueError, e:
+ except ValueError as e:
raise ZConfig.DataConversionError(
e, values[attr], (-1, -1, None))
else:
@@ -233,7 +233,7 @@
self.name = name
else:
raise ZConfig.ConfigurationError(
- `type.name` + " sections may not be unnamed")
+ repr(type.name) + " sections may not be unnamed")
BaseMatcher.__init__(self, info, type, handlers)
def createValue(self):
@@ -270,7 +270,7 @@
def __repr__(self):
if self._name:
# probably unique for a given config file; more readable than id()
- name = `self._name`
+ name = repr(self._name)
else:
# identify uniquely
name = "at %#x" % id(self)
@@ -279,8 +279,7 @@
def __str__(self):
l = []
- attrnames = [s for s in self.__dict__.keys() if s[0] != "_"]
- attrnames.sort()
+ attrnames = sorted([s for s in self.__dict__.keys() if s[0] != "_"])
for k in attrnames:
v = getattr(self, k)
l.append('%-40s: %s' % (k, v))
Modified: ZConfig/trunk/ZConfig/schema.py
===================================================================
--- ZConfig/trunk/ZConfig/schema.py 2013-02-12 17:37:48 UTC (rev 129321)
+++ ZConfig/trunk/ZConfig/schema.py 2013-02-12 21:55:42 UTC (rev 129322)
@@ -36,9 +36,9 @@
def _srepr(ob):
if isinstance(ob, type(u'')):
# drop the leading "u" from a unicode repr
- return `ob`[1:]
+ return repr(ob)[1:]
else:
- return `ob`
+ return repr(ob)
class BaseParser(xml.sax.ContentHandler):
@@ -85,7 +85,7 @@
attrs = dict(attrs)
if self._elem_stack:
parent = self._elem_stack[-1]
- if not self._allowed_parents.has_key(name):
+ if name not in self._allowed_parents:
self.error("Unknown tag " + name)
if parent not in self._allowed_parents[name]:
self.error("%s elements may not be nested in %s elements"
@@ -117,7 +117,7 @@
self._cdata.append(data)
elif data.strip():
self.error("unexpected non-blank character data: "
- + `data.strip()`)
+ + repr(data.strip()))
def endElement(self, name):
del self._elem_stack[-1]
@@ -158,7 +158,7 @@
convert = self._registry.get("dotted-name")
try:
name = convert(name)
- except ValueError, err:
+ except ValueError as err:
self.error("not a valid prefix: %s (%s)"
% (_srepr(name), str(err)))
if name[0] == ".":
@@ -182,7 +182,7 @@
return name
def get_datatype(self, attrs, attrkey, default, base=None):
- if attrs.has_key(attrkey):
+ if attrkey in attrs:
dtname = self.get_classname(attrs[attrkey])
else:
convert = getattr(base, attrkey, None)
@@ -192,8 +192,8 @@
try:
return self._registry.get(dtname)
- except ValueError, e:
- self.error(e[0])
+ except ValueError as e:
+ self.error(e.args[0])
def get_sect_typeinfo(self, attrs, base=None):
keytype = self.get_datatype(attrs, "keytype", "basic-key", base)
@@ -202,7 +202,7 @@
return keytype, valuetype, datatype
def get_required(self, attrs):
- if attrs.has_key("required"):
+ if "required" in attrs:
v = attrs["required"]
if v == "yes":
return True
@@ -255,7 +255,7 @@
# run the keytype converter to make sure this is a valid key
try:
name = self._stack[-1].keytype(name)
- except ValueError, e:
+ except ValueError as e:
self.error("could not convert key name to keytype: " + str(e))
if not aname:
aname = self.basic_key(name)
@@ -325,7 +325,7 @@
self.error("sectiontype name must not be omitted or empty")
name = self.basic_key(name)
self.push_prefix(attrs)
- if attrs.has_key("extends"):
+ if "extends" in attrs:
basename = self.basic_key(attrs["extends"])
base = self._schema.gettype(basename)
if base.isabstract():
@@ -337,7 +337,7 @@
keytype, valuetype, datatype = self.get_sect_typeinfo(attrs)
sectinfo = self._schema.createSectionType(
name, keytype, valuetype, datatype)
- if attrs.has_key("implements"):
+ if "implements" in attrs:
ifname = self.basic_key(attrs["implements"])
interface = self._schema.gettype(ifname)
if not interface.isabstract():
@@ -397,7 +397,7 @@
name, datatype, handler, attribute = self.get_key_info(attrs, "key")
min = self.get_required(attrs) and 1 or 0
key = info.KeyInfo(name, datatype, min, handler, attribute)
- if attrs.has_key("default"):
+ if "default" in attrs:
if min:
self.error("required key cannot have a default value")
key.adddefault(str(attrs["default"]).strip(),
@@ -414,7 +414,7 @@
key.finish()
def start_multikey(self, attrs):
- if attrs.has_key("default"):
+ if "default" in attrs:
self.error("default values for multikey must be given using"
" 'default' elements")
name, datatype, handler, attribute = self.get_key_info(attrs,
@@ -435,13 +435,13 @@
def basic_key(self, s):
try:
return self._basic_key(s)
- except ValueError, e:
+ except ValueError as e:
self.error(e[0])
def identifier(self, s):
try:
return self._identifier(s)
- except ValueError, e:
+ except ValueError as e:
self.error(e[0])
# exception setup helpers
@@ -485,7 +485,7 @@
self._stack = [self._schema]
- if attrs.has_key("extends"):
+ if "extends" in attrs:
sources = attrs["extends"].split()
sources.reverse()
@@ -498,7 +498,7 @@
self.extendSchema(src)
# Inherit keytype from bases, if unspecified and not conflicting
- if self._base_keytypes and not attrs.has_key("keytype"):
+ if self._base_keytypes and "keytype" not in attrs:
keytype = self._base_keytypes[0]
for kt in self._base_keytypes[1:]:
if kt is not keytype:
@@ -507,7 +507,7 @@
" extending schema")
# Inherit datatype from bases, if unspecified and not conflicting
- if self._base_datatypes and not attrs.has_key("datatype"):
+ if self._base_datatypes and "datatype" not in attrs:
datatype = self._base_datatypes[0]
for dt in self._base_datatypes[1:]:
if dt is not datatype:
Modified: ZConfig/trunk/ZConfig/schemaless.py
===================================================================
--- ZConfig/trunk/ZConfig/schemaless.py 2013-02-12 17:37:48 UTC (rev 129321)
+++ ZConfig/trunk/ZConfig/schemaless.py 2013-02-12 21:55:42 UTC (rev 129322)
@@ -65,8 +65,7 @@
result.append(start)
pre += ' '
- lst = list(self.items())
- lst.sort()
+ lst = sorted(self.items())
for name, values in lst:
for value in values:
result.append('%s%s %s' % (pre, name, value))
Modified: ZConfig/trunk/ZConfig/schemaless.txt
===================================================================
--- ZConfig/trunk/ZConfig/schemaless.txt 2013-02-12 17:37:48 UTC (rev 129321)
+++ ZConfig/trunk/ZConfig/schemaless.txt 2013-02-12 21:55:42 UTC (rev 129322)
@@ -46,7 +46,10 @@
...
... '''
- >>> import StringIO
+ >>> try:
+ ... import StringIO
+ ... except ImportError:
+ ... import io as StringIO
>>> config = schemaless.loadConfigFile(StringIO.StringIO(config_text))
@@ -104,7 +107,7 @@
>>> section.type
'section'
- >>> print section.name
+ >>> print(section.name)
None
Let's look at the named section from our example, so we can see the
@@ -130,7 +133,7 @@
The configuration can be re-serialized using ``str()``::
- >>> print str(config)
+ >>> print(str(config))
another-key whee!
new-key new-value-1
new-key new-value-2
@@ -199,7 +202,7 @@
>>> config = schemaless.loadConfigFile(StringIO.StringIO(config_text))
- >>> print config
+ >>> print(config)
%import some.package
%import another.package
<BLANKLINE>
@@ -230,7 +233,7 @@
>>> config = schemaless.loadConfigFile(StringIO.StringIO(config_text))
- >>> print config
+ >>> print(config)
%import some.package
%import another.package
<BLANKLINE>
Modified: ZConfig/trunk/ZConfig/tests/support.py
===================================================================
--- ZConfig/trunk/ZConfig/tests/support.py 2013-02-12 17:37:48 UTC (rev 129321)
+++ ZConfig/trunk/ZConfig/tests/support.py 2013-02-12 21:55:42 UTC (rev 129322)
@@ -15,23 +15,32 @@
"""Support code shared among the tests."""
import os
-import StringIO
-import urllib
import ZConfig
from ZConfig.loader import ConfigLoader
from ZConfig.url import urljoin
+try:
+ import StringIO
+except ImportError:
+ # Python 3 support.
+ import io as StringIO
try:
+ from urllib import pathname2url
+except ImportError:
+ # Python 3 support.
+ from urllib.request import pathname2url
+
+try:
__file__
except NameError:
import sys
__file__ = sys.argv[0]
d = os.path.abspath(os.path.join(os.path.dirname(__file__), "input"))
-CONFIG_BASE = "file://%s/" % urllib.pathname2url(d)
+CONFIG_BASE = "file://%s/" % pathname2url(d)
class TestHelper:
Modified: ZConfig/trunk/ZConfig/tests/test_cfgimports.py
===================================================================
--- ZConfig/trunk/ZConfig/tests/test_cfgimports.py 2013-02-12 17:37:48 UTC (rev 129321)
+++ ZConfig/trunk/ZConfig/tests/test_cfgimports.py 2013-02-12 21:55:42 UTC (rev 129322)
@@ -12,18 +12,19 @@
#
##############################################################################
"""Tests of the %import mechanism.
-
-$Id: test_cfgimports.py,v 1.1 2003/10/03 20:01:57 fdrake Exp $
"""
-
import unittest
-from StringIO import StringIO
-
import ZConfig
import ZConfig.tests.support
+try:
+ from StringIO import StringIO
+except ImportError:
+ # Python 3 support.
+ from io import StringIO
+
class TestImportFromConfiguration(
ZConfig.tests.support.TestHelper, unittest.TestCase):
Modified: ZConfig/trunk/ZConfig/tests/test_cmdline.py
===================================================================
--- ZConfig/trunk/ZConfig/tests/test_cmdline.py 2013-02-12 17:37:48 UTC (rev 129321)
+++ ZConfig/trunk/ZConfig/tests/test_cmdline.py 2013-02-12 21:55:42 UTC (rev 129322)
@@ -44,8 +44,8 @@
("section/innerkey=spoogey", None)]
bag = self.create_config_loader(schema).cook()
# Test a variety of queries on the OptionBag:
- self.assert_(bag.has_key("mykey"))
- self.assert_(not bag.has_key("another"))
+ self.assert_("mykey" in bag)
+ self.assert_("another" not in bag)
self.assertEqual(bag.get_section_info("st", None), None)
self.assertEqual(bag.get_section_info("st", "missing-sect"), None)
# Consume everything in the OptionBag:
@@ -54,8 +54,8 @@
self.assertEqual(len(L), 1)
self.assertEqual(s, "splat!")
bag2 = bag.get_section_info("st", "section")
- self.assert_(bag2.has_key("innerkey"))
- self.assert_(not bag2.has_key("another"))
+ self.assert_("innerkey" in bag2)
+ self.assert_("another" not in bag2)
L = bag2.get_key("innerkey")
s, pos = L[0]
self.assertEqual(len(L), 1)
Modified: ZConfig/trunk/ZConfig/tests/test_config.py
===================================================================
--- ZConfig/trunk/ZConfig/tests/test_config.py 2013-02-12 17:37:48 UTC (rev 129321)
+++ ZConfig/trunk/ZConfig/tests/test_config.py 2013-02-12 21:55:42 UTC (rev 129322)
@@ -12,9 +12,7 @@
#
##############################################################################
"""Tests of the configuration data structures and loader."""
-
import os
-import StringIO
import tempfile
import unittest
@@ -22,6 +20,11 @@
from ZConfig.tests.support import CONFIG_BASE
+try:
+ import cStringIO as StringIO
+except ImportError:
+ # Python 3 support.
+ import io as StringIO
class ConfigurationTestCase(unittest.TestCase):
Modified: ZConfig/trunk/ZConfig/tests/test_datatypes.py
===================================================================
--- ZConfig/trunk/ZConfig/tests/test_datatypes.py 2013-02-12 17:37:48 UTC (rev 129321)
+++ ZConfig/trunk/ZConfig/tests/test_datatypes.py 2013-02-12 21:55:42 UTC (rev 129322)
@@ -225,11 +225,6 @@
eq(convert('65535'), 65535)
eq(convert('65536'), 65536)
- big = sys.maxint + 1L # Python 2.1 needs the L suffix here
- s = str(big) # s won't have the suffix
- eq(convert(s), big)
- eq(convert("-" + s), -big)
-
raises(ValueError, convert, 'abc')
raises(ValueError, convert, '-0xabc')
raises(ValueError, convert, '')
@@ -349,12 +344,12 @@
eq(convert('128'), 128)
eq(convert('128KB'), 128*1024)
eq(convert('128MB'), 128*1024*1024)
- eq(convert('128GB'), 128*1024*1024*1024L)
+ eq(convert('128GB'), 128*1024*1024*1024)
raises(ValueError, convert, '128TB')
eq(convert('128'), 128)
eq(convert('128kb'), 128*1024)
eq(convert('128mb'), 128*1024*1024)
- eq(convert('128gb'), 128*1024*1024*1024L)
+ eq(convert('128gb'), 128*1024*1024*1024)
raises(ValueError, convert, '128tb')
def test_time_interval(self):
Modified: ZConfig/trunk/ZConfig/tests/test_loader.py
===================================================================
--- ZConfig/trunk/ZConfig/tests/test_loader.py 2013-02-12 17:37:48 UTC (rev 129321)
+++ ZConfig/trunk/ZConfig/tests/test_loader.py 2013-02-12 21:55:42 UTC (rev 129322)
@@ -17,18 +17,27 @@
import sys
import tempfile
import unittest
-import urllib2
-from StringIO import StringIO
-
import ZConfig
import ZConfig.loader
import ZConfig.url
from ZConfig.tests.support import CONFIG_BASE, TestHelper
+try:
+ import urllib2
+except ImportError:
+ # Python 3 support.
+ import urllib.request as urllib2
try:
+ from StringIO import StringIO
+except ImportError:
+ # Python 3 support.
+ from io import StringIO
+
+
+try:
myfile = __file__
except NameError:
myfile = sys.argv[0]
@@ -86,7 +95,7 @@
"</schema>")
try:
ZConfig.loadSchemaFile(sio)
- except ZConfig.SchemaResourceError, e:
+ except ZConfig.SchemaResourceError as e:
self.assertEqual(e.filename, "component.xml")
self.assertEqual(e.package, "ZConfig.tests.test_loader")
self.assert_(e.path is None)
@@ -129,7 +138,7 @@
"</schema>")
try:
loader.loadFile(sio)
- except ZConfig.SchemaResourceError, e:
+ except ZConfig.SchemaResourceError as e:
self.assertEqual(e.filename, "notthere.xml")
self.assertEqual(e.package, "ZConfig.tests.library.widget")
self.assert_(e.path)
@@ -301,7 +310,7 @@
sys.path[:] = self.old_path
def test_zip_import_component_from_schema(self):
- sio = StringIO('''
+ sio = StringIO(u'''
<schema>
<abstracttype name="something"/>
<import package="foo.sample"/>
Modified: ZConfig/trunk/ZConfig/tests/test_schema.py
===================================================================
--- ZConfig/trunk/ZConfig/tests/test_schema.py 2013-02-12 17:37:48 UTC (rev 129321)
+++ ZConfig/trunk/ZConfig/tests/test_schema.py 2013-02-12 21:55:42 UTC (rev 129322)
@@ -36,8 +36,7 @@
def get_section_attributes(section):
L = list(section.getSectionAttributes())
- L.sort()
- return L
+ return sorted(L)
class SchemaTestCase(TestHelper, unittest.TestCase):
@@ -568,14 +567,12 @@
<section type='used' name='a'/>
</schema>
""")
- L = schema.getrequiredtypes()
- L.sort()
+ L = sorted(schema.getrequiredtypes())
self.assertEqual(L, ["used"])
def test_getunusedtypes(self):
schema = self.load_schema("library.xml")
- L = schema.getunusedtypes()
- L.sort()
+ L = sorted(schema.getunusedtypes())
self.assertEqual(L, ["type-a", "type-b"])
schema = self.load_schema_text("""\
@@ -735,7 +732,7 @@
def get_data_conversion_error(self, schema, src, url):
try:
self.load_config_text(schema, src, url=url)
- except ZConfig.DataConversionError, e:
+ except ZConfig.DataConversionError as e:
return e
else:
self.fail("expected ZConfig.DataConversionError")
@@ -844,11 +841,9 @@
EXAMPLE.COM foo
</derived>
""")
- L = conf.base.map.items()
- L.sort()
+ L = sorted(conf.base.map.items())
self.assertEqual(L, [("Ident2", "bar"), ("ident1", "foo")])
- L = conf.derived.map.items()
- L.sort()
+ L = sorted(conf.derived.map.items())
self.assertEqual(L, [("example.com", "foo")])
self.assertEqual(get_section_attributes(conf), ["base", "derived"])
@@ -865,8 +860,7 @@
</schema>
""")
conf = self.load_config_text(schema, "<sect/>")
- items = conf.sect.mapping.items()
- items.sort()
+ items = sorted(conf.sect.mapping.items())
self.assertEqual(items, [("bar", "24"), ("foo", "42")])
def test_duplicate_default_key_checked_in_schema(self):
@@ -928,11 +922,9 @@
<base/>
<sect/>
""")
- base = conf.base.mapping.items()
- base.sort()
+ base = sorted(conf.base.mapping.items())
self.assertEqual(base, [("Foo", ["42"]), ("foo", ["42"])])
- sect = conf.sect.mapping.items()
- sect.sort()
+ sect = sorted(conf.sect.mapping.items())
self.assertEqual(sect, [("foo", ["42", "42"])])
def test_sectiontype_inherited_datatype(self):
@@ -963,8 +955,7 @@
"www.example.org 127.0.0.2\n")
table = conf.table
self.assertEqual(len(table), 2)
- L = table.items()
- L.sort()
+ L = sorted(table.items())
self.assertEqual(L, [("host.example.com", "127.0.0.1"),
("www.example.org", "127.0.0.2")])
Modified: ZConfig/trunk/ZConfig/url.py
===================================================================
--- ZConfig/trunk/ZConfig/url.py 2013-02-12 17:37:48 UTC (rev 129321)
+++ ZConfig/trunk/ZConfig/url.py 2013-02-12 21:55:42 UTC (rev 129322)
@@ -17,25 +17,13 @@
hostpart seperator; the functions here enforce this constraint.
"""
-import urlparse as _urlparse
-
try:
- from urlparse import urlsplit
+ import urlparse as _urlparse
except ImportError:
- def urlsplit(url):
- # Check for the fragment here, since Python 2.1.3 didn't get
- # it right for things like "http://www.python.org#frag".
- if '#' in url:
- url, fragment = url.split('#', 1)
- else:
- fragment = ''
- parts = list(_urlparse.urlparse(url))
- parts[-1] = fragment
- param = parts.pop(3)
- if param:
- parts[2] += ";" + param
- return tuple(parts)
+ # Python 3 support
+ import urllib.parse as _urlparse
+urlsplit = _urlparse.urlsplit
def urlnormalize(url):
lc = url.lower()
Modified: ZConfig/trunk/bootstrap.py
===================================================================
--- ZConfig/trunk/bootstrap.py 2013-02-12 17:37:48 UTC (rev 129321)
+++ ZConfig/trunk/bootstrap.py 2013-02-12 21:55:42 UTC (rev 129322)
@@ -18,75 +18,11 @@
use the -c option to specify an alternate configuration file.
"""
-import os, shutil, sys, tempfile, textwrap, urllib, urllib2, subprocess
+import os, shutil, sys, tempfile
from optparse import OptionParser
-if sys.platform == 'win32':
- def quote(c):
- if ' ' in c:
- return '"%s"' % c # work around spawn lamosity on windows
- else:
- return c
-else:
- quote = str
+tmpeggs = tempfile.mkdtemp()
-# See zc.buildout.easy_install._has_broken_dash_S for motivation and comments.
-stdout, stderr = subprocess.Popen(
- [sys.executable, '-Sc',
- 'try:\n'
- ' import ConfigParser\n'
- 'except ImportError:\n'
- ' print 1\n'
- 'else:\n'
- ' print 0\n'],
- stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
-has_broken_dash_S = bool(int(stdout.strip()))
-
-# In order to be more robust in the face of system Pythons, we want to
-# run without site-packages loaded. This is somewhat tricky, in
-# particular because Python 2.6's distutils imports site, so starting
-# with the -S flag is not sufficient. However, we'll start with that:
-if not has_broken_dash_S and 'site' in sys.modules:
- # We will restart with python -S.
- args = sys.argv[:]
- args[0:0] = [sys.executable, '-S']
- args = map(quote, args)
- os.execv(sys.executable, args)
-# Now we are running with -S. We'll get the clean sys.path, import site
-# because distutils will do it later, and then reset the path and clean
-# out any namespace packages from site-packages that might have been
-# loaded by .pth files.
-clean_path = sys.path[:]
-import site
-sys.path[:] = clean_path
-for k, v in sys.modules.items():
- if k in ('setuptools', 'pkg_resources') or (
- hasattr(v, '__path__') and
- len(v.__path__)==1 and
- not os.path.exists(os.path.join(v.__path__[0],'__init__.py'))):
- # This is a namespace package. Remove it.
- sys.modules.pop(k)
-
-is_jython = sys.platform.startswith('java')
-
-setuptools_source = 'http://peak.telecommunity.com/dist/ez_setup.py'
-distribute_source = 'http://python-distribute.org/distribute_setup.py'
-
-# parsing arguments
-def normalize_to_url(option, opt_str, value, parser):
- if value:
- if '://' not in value: # It doesn't smell like a URL.
- value = 'file://%s' % (
- urllib.pathname2url(
- os.path.abspath(os.path.expanduser(value))),)
- if opt_str == '--download-base' and not value.endswith('/'):
- # Download base needs a trailing slash to make the world happy.
- value += '/'
- else:
- value = None
- name = opt_str[2:].replace('-', '_')
- setattr(parser.values, name, value)
-
usage = '''\
[DESIRED PYTHON FOR BUILDOUT] bootstrap.py [options]
@@ -100,26 +36,8 @@
'''
parser = OptionParser(usage=usage)
-parser.add_option("-v", "--version", dest="version",
- help="use a specific zc.buildout version")
-parser.add_option("-d", "--distribute",
- action="store_true", dest="use_distribute", default=False,
- help="Use Distribute rather than Setuptools.")
-parser.add_option("--setup-source", action="callback", dest="setup_source",
- callback=normalize_to_url, nargs=1, type="string",
- help=("Specify a URL or file location for the setup file. "
- "If you use Setuptools, this will default to " +
- setuptools_source + "; if you use Distribute, this "
- "will default to " + distribute_source +"."))
-parser.add_option("--download-base", action="callback", dest="download_base",
- callback=normalize_to_url, nargs=1, type="string",
- help=("Specify a URL or directory for downloading "
- "zc.buildout and either Setuptools or Distribute. "
- "Defaults to PyPI."))
-parser.add_option("--eggs",
- help=("Specify a directory for storing eggs. Defaults to "
- "a temporary directory that is deleted when the "
- "bootstrap script completes."))
+parser.add_option("-v", "--version", help="use a specific zc.buildout version")
+
parser.add_option("-t", "--accept-buildout-test-releases",
dest='accept_buildout_test_releases',
action="store_true", default=False,
@@ -129,49 +47,38 @@
"extensions for you. If you use this flag, "
"bootstrap and buildout will get the newest releases "
"even if they are alphas or betas."))
-parser.add_option("-c", None, action="store", dest="config_file",
+parser.add_option("-c", "--config-file",
help=("Specify the path to the buildout configuration "
"file to be used."))
+parser.add_option("-f", "--find-links",
+ help=("Specify a URL to search for buildout releases"))
+
options, args = parser.parse_args()
-# if -c was provided, we push it back into args for buildout's main function
-if options.config_file is not None:
- args += ['-c', options.config_file]
+######################################################################
+# load/install distribute
-if options.eggs:
- eggs_dir = os.path.abspath(os.path.expanduser(options.eggs))
-else:
- eggs_dir = tempfile.mkdtemp()
-
-if options.setup_source is None:
- if options.use_distribute:
- options.setup_source = distribute_source
- else:
- options.setup_source = setuptools_source
-
-if options.accept_buildout_test_releases:
- args.append('buildout:accept-buildout-test-releases=true')
-args.append('bootstrap')
-
+to_reload = False
try:
- import pkg_resources
- import setuptools # A flag. Sometimes pkg_resources is installed alone.
+ import pkg_resources, setuptools
if not hasattr(pkg_resources, '_distribute'):
+ to_reload = True
raise ImportError
except ImportError:
- ez_code = urllib2.urlopen(
- options.setup_source).read().replace('\r\n', '\n')
ez = {}
- exec ez_code in ez
- setup_args = dict(to_dir=eggs_dir, download_delay=0)
- if options.download_base:
- setup_args['download_base'] = options.download_base
- if options.use_distribute:
- setup_args['no_fake'] = True
+
+ try:
+ from urllib.request import urlopen
+ except ImportError:
+ from urllib2 import urlopen
+
+ exec(urlopen('http://python-distribute.org/distribute_setup.py').read(), ez)
+ setup_args = dict(to_dir=tmpeggs, download_delay=0, no_fake=True)
ez['use_setuptools'](**setup_args)
- if 'pkg_resources' in sys.modules:
- reload(sys.modules['pkg_resources'])
+
+ if to_reload:
+ reload(pkg_resources)
import pkg_resources
# This does not (always?) update the default working set. We will
# do it.
@@ -179,31 +86,26 @@
if path not in pkg_resources.working_set.entries:
pkg_resources.working_set.add_entry(path)
-cmd = [quote(sys.executable),
- '-c',
- quote('from setuptools.command.easy_install import main; main()'),
- '-mqNxd',
- quote(eggs_dir)]
+######################################################################
+# Install buildout
-if not has_broken_dash_S:
- cmd.insert(1, '-S')
+ws = pkg_resources.working_set
-find_links = options.download_base
-if not find_links:
- find_links = os.environ.get('bootstrap-testing-find-links')
+cmd = [sys.executable, '-c',
+ 'from setuptools.command.easy_install import main; main()',
+ '-mZqNxd', tmpeggs]
+
+find_links = os.environ.get(
+ 'bootstrap-testing-find-links',
+ options.find_links or
+ ('http://downloads.buildout.org/'
+ if options.accept_buildout_test_releases else None)
+ )
if find_links:
- cmd.extend(['-f', quote(find_links)])
+ cmd.extend(['-f', find_links])
-if options.use_distribute:
- setup_requirement = 'distribute'
-else:
- setup_requirement = 'setuptools'
-ws = pkg_resources.working_set
-setup_requirement_path = ws.find(
- pkg_resources.Requirement.parse(setup_requirement)).location
-env = dict(
- os.environ,
- PYTHONPATH=setup_requirement_path)
+distribute_path = ws.find(
+ pkg_resources.Requirement.parse('distribute')).location
requirement = 'zc.buildout'
version = options.version
@@ -217,7 +119,7 @@
return False
return True
index = setuptools.package_index.PackageIndex(
- search_path=[setup_requirement_path])
+ search_path=[distribute_path])
if find_links:
index.add_find_links((find_links,))
req = pkg_resources.Requirement.parse(requirement)
@@ -239,22 +141,25 @@
requirement = '=='.join((requirement, version))
cmd.append(requirement)
-if is_jython:
- import subprocess
- exitcode = subprocess.Popen(cmd, env=env).wait()
-else: # Windows prefers this, apparently; otherwise we would prefer subprocess
- exitcode = os.spawnle(*([os.P_WAIT, sys.executable] + cmd + [env]))
-if exitcode != 0:
- sys.stdout.flush()
- sys.stderr.flush()
- print ("An error occurred when trying to install zc.buildout. "
- "Look above this message for any errors that "
- "were output by easy_install.")
- sys.exit(exitcode)
+import subprocess
+if subprocess.call(cmd, env=dict(os.environ, PYTHONPATH=distribute_path)) != 0:
+ raise Exception(
+ "Failed to execute command:\n%s",
+ repr(cmd)[1:-1])
-ws.add_entry(eggs_dir)
+######################################################################
+# Import and run buildout
+
+ws.add_entry(tmpeggs)
ws.require(requirement)
import zc.buildout.buildout
+
+if not [a for a in args if '=' not in a]:
+ args.append('bootstrap')
+
+# if -c was provided, we push it back into args for buildout' main function
+if options.config_file is not None:
+ args[0:0] = ['-c', options.config_file]
+
zc.buildout.buildout.main(args)
-if not options.eggs: # clean up temporary egg directory
- shutil.rmtree(eggs_dir)
+shutil.rmtree(tmpeggs)
Modified: ZConfig/trunk/setup.py
===================================================================
--- ZConfig/trunk/setup.py 2013-02-12 17:37:48 UTC (rev 129321)
+++ ZConfig/trunk/setup.py 2013-02-12 21:55:42 UTC (rev 129322)
@@ -18,7 +18,7 @@
options = dict(
name="ZConfig",
- version="2.9.4dev",
+ version="3.0.0b1dev",
author="Fred L. Drake, Jr.",
author_email="fred at zope.com",
maintainer="Zope Foundation and Contributors",
@@ -43,15 +43,19 @@
include_package_data=True,
zip_safe=False,
classifiers=[
+ 'Development Status :: 5 - Production/Stable',
"Intended Audience :: Developers",
"Intended Audience :: System Administrators",
"License :: OSI Approved :: Zope Public License",
"Operating System :: OS Independent",
- "Programming Language :: Python",
- "Programming Language :: Python :: 2.4",
- "Programming Language :: Python :: 2.5",
- "Programming Language :: Python :: 2.6",
- "Programming Language :: Python :: 2.7",
+ 'Programming Language :: Python',
+ 'Programming Language :: Python :: 2',
+ 'Programming Language :: Python :: 2.7',
+ 'Programming Language :: Python :: 3',
+ 'Programming Language :: Python :: 3.3',
+ 'Programming Language :: Python :: Implementation :: CPython',
+ 'Operating System :: OS Independent',
+ 'Topic :: Software Development',
],
# Support for 'setup.py test' when setuptools is available:
test_suite="__main__.alltests",
Added: ZConfig/trunk/tox.ini
===================================================================
--- ZConfig/trunk/tox.ini (rev 0)
+++ ZConfig/trunk/tox.ini 2013-02-12 21:55:42 UTC (rev 129322)
@@ -0,0 +1,24 @@
+[tox]
+envlist = py27,py33
+
+[testenv]
+commands =
+ python setup.py test -q
+# without explicit deps, setup.py test will download a bunch of eggs into $PWD
+deps =
+ zope.testrunner
+
+[testenv:coverage]
+basepython =
+ python2.7
+commands =
+# The installed version messes up nose's test discovery / coverage reporting
+# So, we uninstall that from the environment, and then install the editable
+# version, before running nosetests.
+ pip uninstall -y ZConfig
+ pip install -e .
+ nosetests --with-xunit --with-xcoverage
+deps =
+ nose
+ coverage
+ nosexcover
More information about the checkins
mailing list