[Zodb-checkins] CVS: Packages/ZConfig - Exceptions.py:1.1 ApacheStyle.py:1.8 Config.py:1.14 Context.py:1.15 Substitution.py:1.13 __init__.py:1.3 Common.py:NONE
Fred L. Drake, Jr.
fred@zope.com
Thu, 5 Dec 2002 00:18:17 -0500
Update of /cvs-repository/Packages/ZConfig
In directory cvs.zope.org:/tmp/cvs-serv6613
Modified Files:
ApacheStyle.py Config.py Context.py Substitution.py
__init__.py
Added Files:
Exceptions.py
Removed Files:
Common.py
Log Message:
- Remove the poorly-named "Common" module.
- Define exceptions in the "Exceptions" module.
- Expose all the exceptions in the ZConfig package directly.
=== Added File Packages/ZConfig/Exceptions.py ===
"""Names used from all modules in the package.
Since some names are only defined if needed, this module should be
imported using the from-import-* syntax.
"""
class ConfigurationError(Exception):
def __init__(self, msg):
self.message = msg
Exception.__init__(self, msg)
def __str__(self):
return self.message
class ConfigurationMissingSectionError(ConfigurationError):
def __init__(self, type, name=None):
self.type = type
self.name = name
details = 'Missing section (type: %s' % type
if name is not None:
details += ', name: %s' % name
ConfigurationError.__init__(self, details + ')')
class ConfigurationConflictingSectionError(ConfigurationError):
def __init__(self, type, name=None):
self.type = type
self.name = name
details = 'Conflicting sections (type: %s' % type
if name is not None:
details += ', name: %s' % name
ConfigurationError.__init__(self, details + ')')
class ConfigurationSyntaxError(ConfigurationError):
def __init__(self, msg, url, lineno):
self.url = url
self.lineno = lineno
ConfigurationError.__init__(self, msg)
def __str__(self):
return "%s\n(line %s in %s)" % (self.message, self.lineno, self.url)
class ConfigurationTypeError(ConfigurationError):
def __init__(self, msg, found, expected):
self.found = found
self.expected = expected
ConfigurationError.__init__(self, msg)
class SubstitutionSyntaxError(ConfigurationError):
"""Raised when interpolation source text contains syntactical errors."""
class SubstitutionReplacementError(ConfigurationError, LookupError):
"""Raised when no replacement is available for a reference."""
def __init__(self, source, name):
self.source = source
self.name = name
ConfigurationError.__init__(self, "no replacement for " + `name`)
=== Packages/ZConfig/ApacheStyle.py 1.7 => 1.8 ===
--- Packages/ZConfig/ApacheStyle.py:1.7 Wed Dec 4 16:20:43 2002
+++ Packages/ZConfig/ApacheStyle.py Thu Dec 5 00:17:45 2002
@@ -2,7 +2,7 @@
import urlparse
-from Common import *
+from ZConfig import ConfigurationError, ConfigurationSyntaxError
def Parse(resource, context, section):
=== Packages/ZConfig/Config.py 1.13 => 1.14 ===
--- Packages/ZConfig/Config.py:1.13 Wed Dec 4 23:44:20 2002
+++ Packages/ZConfig/Config.py Thu Dec 5 00:17:45 2002
@@ -1,6 +1,12 @@
"""Configuration data structure."""
-from Common import *
+import ZConfig
+
+try:
+ True
+except NameError:
+ True = 1
+ False = 0
class Configuration:
def __init__(self, container, type, name, url):
@@ -31,7 +37,7 @@
def setDelegate(self, section):
if self.delegate is not None:
- raise ConfigurationError("cannot modify delegation")
+ raise ZConfig.ConfigurationError("cannot modify delegation")
self.delegate = section
def addChildSection(self, section):
@@ -53,7 +59,7 @@
if child is None or child.url != self.url:
self._sections_by_name[key] = section
else:
- raise ConfigurationError(
+ raise ZConfig.ConfigurationError(
"cannot replace existing named section")
def getSection(self, type, name=None):
@@ -64,14 +70,14 @@
try:
return self._sections_by_name[key]
except KeyError:
- raise ConfigurationMissingSectionError(type, name)
+ raise ZConfig.ConfigurationMissingSectionError(type, name)
else:
L = []
for sect in self._sections:
if sect.type == type:
L.append(sect)
if len(L) > 1:
- raise ConfigurationConflictingSectionError(type, name)
+ raise ZConfig.ConfigurationConflictingSectionError(type, name)
if L:
return L[0]
elif self.delegate:
@@ -93,7 +99,7 @@
except KeyError:
self._data[key] = value
else:
- raise ConfigurationError("cannot add existing key")
+ raise ZConfig.ConfigurationError("cannot add existing key")
def has_key(self, key):
key = key.lower()
=== Packages/ZConfig/Context.py 1.14 => 1.15 ===
--- Packages/ZConfig/Context.py:1.14 Wed Dec 4 16:20:43 2002
+++ Packages/ZConfig/Context.py Thu Dec 5 00:17:45 2002
@@ -5,7 +5,8 @@
import urllib2
import urlparse
-from Common import *
+import ZConfig
+
from Config import Configuration, ImportingConfiguration
from Substitution import isname, substitute
@@ -116,10 +117,10 @@
# another resource.
oldsect = self._named_sections[name]
if oldsect.url == section.url:
- raise ConfigurationError(
+ raise ZConfig.ConfigurationError(
"named section cannot be defined twice in same resource")
if oldsect.type != type:
- raise ConfigurationError(
+ raise ZConfig.ConfigurationError(
"named section cannot change type")
newsect = self.createNestedSection(section, type, name, delegatename)
self._all_sections.append(newsect)
@@ -148,7 +149,7 @@
def _parse_url(self, url, section):
url, fragment = urlparse.urldefrag(url)
if fragment:
- raise ConfigurationError(
+ raise ZConfig.ConfigurationError(
"fragment identifiers are not currently supported")
file = urllib2.urlopen(url)
self._current_imports.append(section)
@@ -166,14 +167,14 @@
for referrer in L:
type = self.getDelegateType(referrer.type)
if type is None:
- raise ConfigurationTypeError(
+ raise ZConfig.ConfigurationTypeError(
"%s sections are not allowed to specify delegation\n"
"(in %s)"
% (repr(referrer.type), referrer.url),
referrer.type, None)
type = type.lower()
if type != section.type:
- raise ConfigurationTypeError(
+ raise ZConfig.ConfigurationTypeError(
"%s sections can only inherit from %s sections\n"
"(in %s)"
% (repr(referrer.type), repr(type), referrer.url),
@@ -205,9 +206,9 @@
def define(self, name, value):
key = name.lower()
if self._definitions.has_key(key):
- raise ConfigurationError("cannot redefine " + `name`)
+ raise ZConfig.ConfigurationError("cannot redefine " + `name`)
if not isname(name):
- raise ConfigurationError(
+ raise ZConfig.ConfigurationError(
"not a substitution legal name: " + `name`)
self._definitions[key] = value
=== Packages/ZConfig/Substitution.py 1.12 => 1.13 ===
--- Packages/ZConfig/Substitution.py:1.12 Wed Dec 4 23:00:45 2002
+++ Packages/ZConfig/Substitution.py Thu Dec 5 00:17:45 2002
@@ -1,21 +1,12 @@
"""Substitution support for ZConfig values."""
-from Common import *
+import ZConfig
-class SubstitutionError(ConfigurationError):
- """Base class for exceptions raised by ZConfig.Substitution."""
-
-class SubstitutionSyntaxError(SubstitutionError):
- """Raised when interpolation source text contains syntactical errors."""
-
-class SubstitutionReplacementError(SubstitutionError, LookupError):
- """Raised when no replacement is available for a reference."""
-
- def __init__(self, source, name):
- self.source = source
- self.name = name
- SubstitutionError.__init__(
- self, "no replacement for " + `name`)
+try:
+ True
+except NameError:
+ True = 1
+ False = 0
def substitute(s, mapping):
@@ -29,7 +20,7 @@
if name:
v = mapping.get(name)
if v is None:
- raise SubstitutionReplacementError(s, name)
+ raise ZConfig.SubstitutionReplacementError(s, name)
result += v
return result
else:
@@ -55,7 +46,7 @@
i = s.find("$")
c = s[i+1:i+2]
if c == "":
- raise SubstitutionSyntaxError(
+ raise ZConfig.SubstitutionSyntaxError(
"illegal lone '$' at end of source")
if c == "$":
return s[:i+1], None, s[i+2:]
@@ -63,16 +54,17 @@
if c == "{":
m = _name_match(s, i + 2)
if not m:
- raise SubstitutionSyntaxError("'${' not followed by name")
+ raise ZConfig.SubstitutionSyntaxError(
+ "'${' not followed by name")
name = m.group(0)
i = m.end() + 1
if not s.startswith("}", i - 1):
- raise SubstitutionSyntaxError(
+ raise ZConfig.SubstitutionSyntaxError(
"'${%s' not followed by '}'" % name)
else:
m = _name_match(s, i+1)
if not m:
- raise SubstitutionSyntaxError(
+ raise ZConfig.SubstitutionSyntaxError(
"'$' not followed by '$' or name")
name = m.group(0)
i = m.end()
=== Packages/ZConfig/__init__.py 1.2 => 1.3 ===
--- Packages/ZConfig/__init__.py:1.2 Thu Nov 7 15:05:24 2002
+++ Packages/ZConfig/__init__.py Thu Dec 5 00:17:45 2002
@@ -16,6 +16,8 @@
$Id$
"""
+from ZConfig.Exceptions import *
+
def load(url):
import Context
return Context.Context().load(url)
=== Removed File Packages/ZConfig/Common.py ===