[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r8107 - trunk/gnue-common/src/definitions
From: |
johannes |
Subject: |
[gnue] r8107 - trunk/gnue-common/src/definitions |
Date: |
Thu, 24 Nov 2005 08:06:30 -0600 (CST) |
Author: johannes
Date: 2005-11-24 08:06:30 -0600 (Thu, 24 Nov 2005)
New Revision: 8107
Modified:
trunk/gnue-common/src/definitions/GParser.py
Log:
Fixed name of arguments in startElementNS (), endElementNS () and characters
(). Fixed some docstrings.
Modified: trunk/gnue-common/src/definitions/GParser.py
===================================================================
--- trunk/gnue-common/src/definitions/GParser.py 2005-11-24 13:49:48 UTC
(rev 8106)
+++ trunk/gnue-common/src/definitions/GParser.py 2005-11-24 14:06:30 UTC
(rev 8107)
@@ -267,9 +267,9 @@
def initValidation (self):
"""
Update some statistics about the elements in use. All 'required' elements
- will be added to the sequence L{_requiredTags} and all elements having
+ will be added to the sequence _requiredTags and all elements having
a True value set for 'SingleInstance' will be added to the sequence
- L{_singleInstanceTags}. Additionally the tag-counter dictionary will
+ _singleInstanceTags. Additionally the tag-counter dictionary will
be reset.
"""
@@ -317,14 +317,21 @@
# Start of a XML element
# ---------------------------------------------------------------------------
- def startElementNS (self, qtag, qname, saxattrs):
+ def startElementNS (self, name, qname, attrs):
"""
- Called by the internal SAX parser whenever a starting XML tag is
- encountered.
+ Signals the start of an element in namespace mode.
+
+ The name parameter contains the name of the element type as a (uri,
+ localname) tuple, the qname parameter the raw XML 1.0 name used in the
+ source document, and the attrs parameter holds an instance of the
+ Attributes class containing the attributes of the element.
+
+ The uri part of the name tuple is None for elements which have no
+ namespace.
"""
- ns, name = qtag
- attrs = {}
+ ns, tname = name
+ lattrs = {}
loadedxmlattrs = {}
baseAttrs = {}
@@ -347,20 +354,20 @@
#
# No namespace qualifier
#
- assert gDebug (7, "<%s>" % name)
+ assert gDebug (7, "<%s>" % tname)
try:
- baseAttrs = self.xmlElements [name].get ('Attributes', {})
+ baseAttrs = self.xmlElements [tname].get ('Attributes', {})
except KeyError:
raise MarkupError, \
(u_("Error processing <%(tagname)s> tag [I do not know what a "
- "<%(tagname)s> tag does]") % {'tagname': name}, self.url,
+ "<%(tagname)s> tag does]") % {'tagname': tname}, self.url,
self.parser.getLineNumber ())
xmlns = {}
- for qattr in saxattrs.keys ():
+ for qattr in attrs.keys ():
attrns, attr = qattr
if attrns:
@@ -368,80 +375,80 @@
tmsg = _("Unexpected namespace on attribute")
raise MarkupError, (tmsg, self.url, self.parser.getLineNumber ())
prefix = attrns.split (':') [-1]
- attrs [prefix + '__' + attr] = saxattrs [qattr]
+ lattrs [prefix + '__' + attr] = attrs [qattr]
xmlns [prefix] = attrns
- loadedxmlattrs [attr] = saxattrs [qattr]
+ loadedxmlattrs [attr] = attrs [qattr]
else:
# Typecasting, anyone? If attribute should be int, make it an int
try:
- typecast = baseAttrs [attr].get ('Typecast', GTypecast.text)
- attrs [attr] = typecast (saxattrs [qattr])
- loadedxmlattrs [attr] = attrs [attr]
+ typecast = baseAttrs [attr].get ('Typecast', GTypecast.text)
+ lattrs [attr] = typecast (attrs [qattr])
+ loadedxmlattrs [attr] = lattrs [attr]
except KeyError:
raise MarkupError, \
(u_('Error processing <%(tagname)s> tag [I do not '
'recognize the "%(attribute)s" attribute]') \
- % {'tagname': name, 'attribute': attr},
+ % {'tagname': tname, 'attribute': attr},
self.url, self.parser.getLineNumber ())
# If this attribute must be unique, check for duplicates
if baseAttrs [attr].get ('Unique', False):
- if self.uniqueIDs.has_key ('%s' % (saxattrs [qattr])):
+ if self.uniqueIDs.has_key ('%s' % (attrs [qattr])):
tmsg = u_('Error processing <%(tag)s> tag ["%(attribute)s" '
'attribute should be unique; duplicate value is '
'"%(duplicate)s"]') \
- % {'tag' : name,
+ % {'tag' : tname,
'attribute': attr,
- 'duplicate': saxattrs [qattr]}
+ 'duplicate': attrs [qattr]}
raise MarkupError, (tmsg, self.url, self.parser.getLineNumber ())
# If we would really want to ensure uniqueness, we'd like to
# uncomment the following lines. But as this seems to break forms
# keep it (for now)
- # self.uniqueIDs ["%s" % saxattrs [qattr]] = True
+ # self.uniqueIDs ["%s" % attrs [qattr]] = True
for attr in baseAttrs:
try:
- if not attr in attrs:
+ if not attr in lattrs:
# Pull default values for missing attributes
if 'Default' in baseAttrs [attr]:
- typecast = baseAttrs [attr].get ('Typecast', GTypecast.text)
- attrs [attr] = typecast (baseAttrs [attr]['Default'])
+ typecast = baseAttrs [attr].get ('Typecast', GTypecast.text)
+ lattrs [attr] = typecast (baseAttrs [attr]['Default'])
# Check for missing required attributes
elif baseAttrs [attr].get ('Required', False):
tm = u_('Error processing <%(tagname)s> tag [required attribute '
'"%(attribute)s" not present]') \
- % {'tagname': name, 'attribute': attr}
+ % {'tagname': tname, 'attribute': attr}
raise MarkupError, (tm, self.url, self.parser.getLineNumber ())
except (AttributeError, KeyError), msg:
raise errors.SystemError, \
u_("Error in GParser xmlElement definition for %(tag)s/%(attr)s"
"\n%(message)s") \
- % {'tag': name, 'attr': attr, 'message': msg}
+ % {'tag': tname, 'attr': attr, 'message': msg}
- attrs ['_xmlnamespaces'] = xmlns
+ lattrs ['_xmlnamespaces'] = xmlns
if self.bootstrapflag:
if self.xmlStack [0] is not None:
- object = self.xmlElements [name]['BaseClass'] (self.xmlStack [0])
+ object = self.xmlElements [tname]['BaseClass'] (self.xmlStack [0])
else:
- object = self.xmlElements [name]['BaseClass'] ()
+ object = self.xmlElements [tname]['BaseClass'] ()
self.root = object
self.bootstrapflag = 1
try:
- self._tagCounts [name] += 1
+ self._tagCounts [tname] += 1
except KeyError:
pass
- object._xmltag = name
+ object._xmltag = tname
object._xmlnamespace = ns
object._listedAttributes = loadedxmlattrs.keys ()
@@ -449,12 +456,12 @@
#
# namespace qualifier and we are masquerading
#
- assert gDebug (7, "<%s:%s>" % (ns,name))
+ assert gDebug (7, "<%s:%s>" % (ns, tname))
- for qattr in saxattrs.keys():
- attrns, attr = qattr
- attrs [attr] = saxattrs [qattr]
- loadedxmlattrs [attr] = saxattrs [qattr]
+ for qattr in attrs.keys ():
+ attrns, attr = qattr
+ lattrs [attr] = attrs [qattr]
+ loadedxmlattrs [attr] = attrs [qattr]
try:
object = self.xmlMasqueradeNamespaceElements (self.xmlStack [0])
@@ -463,10 +470,10 @@
tmsg = u_("Error processing <%(namespace)s:%(name)s> tag: root "
"element needs to be in default namespace") \
% {'namespace': ns,
- 'name' : name}
+ 'name' : tname}
raise MarkupError, (tmsg, self.url, self.parser.getLineNumber ())
- object._xmltag = name
+ object._xmltag = tname
object._xmlnamespace = ns
object._listedAttributes = loadedxmlattrs.keys ()
@@ -494,19 +501,19 @@
object._url = self.url
# Set the attributes
- object.__dict__.update (attrs)
+ object.__dict__.update (lattrs)
self.xmlStack.insert (0, object)
- self.nameStack.insert (0, name)
+ self.nameStack.insert (0, tname)
# processing trigger/procedure code from external files
- for qattr in saxattrs.keys ():
+ for qattr in attrs.keys ():
attrns, attr = qattr
if baseAttrs.has_key ('file') and attr == 'file':
# FIXME: find a better way to handle encoding of external resources
textEncoding = gConfig('textEncoding')
- handle = openResource (attrs [attr])
+ handle = openResource (lattrs [attr])
text = handle.read ().decode (textEncoding)
handle.close ()
@@ -520,7 +527,7 @@
# Process text which is not part of a tag (=contents)
# ---------------------------------------------------------------------------
- def characters (self, text):
+ def characters (self, content):
"""
Called by the internal SAX parser whenever text (not part of a tag) is
encountered.
@@ -534,29 +541,29 @@
# Should we keep the text?
if xmlns or self.xmlElements [self.nameStack [0]].get('MixedContent', 0):
if xmlns or
self.xmlElements[self.nameStack[0]].get('KeepWhitespace',0):
- GContent (self.xmlStack [0], text)
+ GContent (self.xmlStack [0], content)
else:
# Normalize
- if len (text.strip ()):
- text = normalise_whitespace (text)
+ if len (content.strip ()):
+ content = normalise_whitespace (content)
else:
- text = ""
+ content = ""
- if len (text):
- GContent (self.xmlStack [0], text)
+ if len (content):
+ GContent (self.xmlStack [0], content)
# ---------------------------------------------------------------------------
# End of a XML tag encountered
# ---------------------------------------------------------------------------
- def endElementNS (self, qtag, qname):
+ def endElementNS (self, name, qname):
"""
Called by the internal SAX parser whenever an ending XML tag/element is
encountered.
"""
- ns, name = qtag
+ ns, tname = name
self.nameStack.pop (0)
child = self.xmlStack.pop (0)
@@ -566,7 +573,7 @@
inits = child._buildObject ()
self._phaseInitCount = (inits != None and inits > self._phaseInitCount \
and inits or self._phaseInitCount)
- assert gDebug (7, "</%s>" % name)
+ assert gDebug (7, "</%s>" % tname)
# ---------------------------------------------------------------------------
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r8107 - trunk/gnue-common/src/definitions,
johannes <=