[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnue/gnue-common/gnue/common GConfig.py GDataSo...
From: |
Jason Cater |
Subject: |
gnue/gnue-common/gnue/common GConfig.py GDataSo... |
Date: |
Tue, 26 Jun 2001 20:20:35 -0700 |
CVSROOT: /home/cvs
Module name: gnue
Changes by: Jason Cater <address@hidden> 01/06/26 20:20:35
Modified files:
gnue-common/gnue/common: GConfig.py GDataSource.py GObjects.py
GParser.py
Log message:
Converted parser format from nested tuples to nested dictionaries so
that in future info can be added to parser definition without breaking other
code and vise versa; Added 'default' element to GConfig.get; added flag to
GContent.dumpXML to dump text as is (not escape it)
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/gnue/common/GConfig.py.diff?cvsroot=OldCVS&tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/gnue/common/GDataSource.py.diff?cvsroot=OldCVS&tr1=1.8&tr2=1.9&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/gnue/common/GObjects.py.diff?cvsroot=OldCVS&tr1=1.10&tr2=1.11&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/gnue/common/GParser.py.diff?cvsroot=OldCVS&tr1=1.15&tr2=1.16&r1=text&r2=text
Patches:
Index: gnue/gnue-common/gnue/common/GConfig.py
diff -u gnue/gnue-common/gnue/common/GConfig.py:1.3
gnue/gnue-common/gnue/common/GConfig.py:1.4
--- gnue/gnue-common/gnue/common/GConfig.py:1.3 Mon Jun 25 12:29:11 2001
+++ gnue/gnue-common/gnue/common/GConfig.py Tue Jun 26 20:20:35 2001
@@ -40,9 +40,15 @@
_OPTION = {}
-def get(varName):
+class _NOOPTION:
+ pass
+
+def get(varName, default=_NOOPTION):
global _OPTION
- return _OPTION[string.lower(varName)]
+ if hasattr(_OPTION, string.lower(varName)) or default == _NOOPTION:
+ return _OPTION[string.lower(varName)]
+ else:
+ return default
class InvalidFormatError (StandardError):
# Raised if the Connections Definition File is
Index: gnue/gnue-common/gnue/common/GDataSource.py
diff -u gnue/gnue-common/gnue/common/GDataSource.py:1.8
gnue/gnue-common/gnue/common/GDataSource.py:1.9
--- gnue/gnue-common/gnue/common/GDataSource.py:1.8 Tue Jun 5 21:21:57 2001
+++ gnue/gnue-common/gnue/common/GDataSource.py Tue Jun 26 20:20:35 2001
@@ -101,20 +101,35 @@
#
######
from GParser import char, bool
-tagAttributes = { 'name': (1, 1, char, None),
- 'type': (0, 0, char, "object"),
- 'database': (0, 0, char, None),
- 'table': (0, 0, char, None),
- 'cache': (0, 0, int, None),
- 'prequery': (0, 0, bool, 0),
- 'order_by': (0, 0, char, None),
- 'master': (0, 0, char, None),
- 'masterlink': (0, 0, char, None),
- 'detaillink': (0, 0, char, None) }
+tagAttributes = {
+ 'name': {
+ 'Required': 1,
+ 'Unique': 1,
+ 'Typecast': char },
+ 'type': {
+ 'Typecast': char,
+ 'Default': "object" },
+ 'database': {
+ 'Typecast': char },
+ 'table': {
+ 'Typecast': char },
+ 'cache': {
+ 'Typecast': int,
+ 'Default': None },
+ 'prequery': {
+ 'Typecast': bool,
+ 'Default': 0 },
+ 'order_by': {
+ 'Typecast': char },
+ 'master': {
+ 'Typecast': char },
+ 'masterlink': {
+ 'Typecast': char },
+ 'detaillink': {
+ 'Typecast': char } }
+
+
xmlElements = {}
-#xmlElements = {
-# 'sql': (GSql, { }, 1)
-# }.update(GConnections.xmlElements)
Index: gnue/gnue-common/gnue/common/GObjects.py
diff -u gnue/gnue-common/gnue/common/GObjects.py:1.10
gnue/gnue-common/gnue/common/GObjects.py:1.11
--- gnue/gnue-common/gnue/common/GObjects.py:1.10 Mon Jun 25 14:15:48 2001
+++ gnue/gnue-common/gnue/common/GObjects.py Tue Jun 26 20:20:35 2001
@@ -142,8 +142,10 @@
if attribute[0] == "_":
continue
val = self.__dict__[attribute]
- if lookupDict[xmlEntity][1].has_key(attribute):
- if ('%s'%lookupDict[xmlEntity][1][attribute][3]) != ('%s'%val):
+ if lookupDict[xmlEntity].has_key('Attributes') and \
+ lookupDict[xmlEntity]['Attributes'].has_key(attribute):
+ if lookupDict[xmlEntity]['Attributes'][attribute].has_key('Default')
and \
+ ('%s'%lookupDict[xmlEntity]['Attributes'][attribute]['Default']) !=
('%s'%val):
if lookupDict[xmlEntity][1][attribute][2] == bool \
and val == 1:
xmlString = xmlString + ' %s=""' % (attribute)
Index: gnue/gnue-common/gnue/common/GParser.py
diff -u gnue/gnue-common/gnue/common/GParser.py:1.15
gnue/gnue-common/gnue/common/GParser.py:1.16
--- gnue/gnue-common/gnue/common/GParser.py:1.15 Mon Jun 25 14:15:48 2001
+++ gnue/gnue-common/gnue/common/GParser.py Tue Jun 26 20:20:35 2001
@@ -151,7 +151,13 @@
return string.join( string.split(text), ' ')
+def default(attrs, key, default):
+ if attrs.has_key(key):
+ return attrs[key]
+ else:
+ return default
+
#######################################################
#
# xmlHandler
@@ -183,7 +189,7 @@
print 'Error processing <%s> tag [I do not know what a <%s> tag does]' %
(name, name)
sys.exit()
- baseAttrs = self.xmlElements[name][1]
+ baseAttrs = default(self.xmlElements[name],'Attributes',{})
attrs = {}
loadedxmlattrs = {}
@@ -196,15 +202,15 @@
# Typecasting, anyone? If attribute should be int, make it an int
try:
- attrs[attr] = baseAttrs[attr][2](saxattrs[attr])
+ attrs[attr] = default(baseAttrs[attr],'Typecast',char)(saxattrs[attr])
loadedxmlattrs[attr] = attrs[attr]
except:
print 'Error processing <%s> tag [invalid type for "%s" attribute;
value is "%s"]' % (name, attr, saxattrs[attr])
sys.exit()
# If this attribute must be unique, check for duplicates
- if baseAttrs[attr][1]:
- if self.uniqueIDs.has_key('%s::%s' % (name, saxattrs[attr])):
+ if default (baseAttrs[attr],'Unique',0):
+ if self.uniqueIDs.has_key('%s' % (saxattrs[attr])):
print 'Error processing <%s> tag ["%s" attribute should be unique;
duplicate value is "%s"]' % (name, attr, saxattrs[attr])
sys.exit()
@@ -212,20 +218,20 @@
if not attrs.has_key(attr):
# Pull default values for missing attributes
- if baseAttrs[attr][3] != None:
- attrs[attr] = baseAttrs[attr][2](baseAttrs[attr][3])
+ if baseAttrs[attr].has_key ('Default'):
+ attrs[attr] = default(baseAttrs[attr],'Typecast', char)
(baseAttrs[attr]['Default'])
# Check for missing required attributes
- elif baseAttrs[attr][0]:
+ elif default(baseAttrs[attr], 'Required', 0):
print 'Error processing <%s> tag [required attribute "%s" not
present]' % (name, attr)
sys.exit()
if self.bootstrapflag:
if self.xmlStack[0] != None:
- object = self.xmlElements[name][0](self.xmlStack[0])
+ object = self.xmlElements[name]['BaseClass'](self.xmlStack[0])
else:
- object = self.xmlElements[name][0]()
+ object = self.xmlElements[name]['BaseClass']()
self.root = object
self.bootstrapflag = 1
@@ -245,20 +251,22 @@
def characters(self, ch, start, length):
text = ch[start:start+length]
- #print "####" + text + "####"
+
if self.xmlStack[0] != None:
- # Should we normalize the text:
- if self.xmlElements[self.nameStack[0]][2]:
- #print "Normalizing..."
+
+ # Should we keep the text?
+ if default(self.xmlElements[self.nameStack[0]],'MixedContent',0):
+
+ if default(self.xmlElements[self.nameStack[0]],'KeepWhitespace',0):
+ GContent(self.xmlStack[0], text)
+ else:
+ # Normalize
if len(string.replace(string.replace(string.replace(text,'
',''),'\n',''),'\t','')):
text = normalise_whitespace (text)
else:
text = ""
if len(text):
GContent(self.xmlStack[0], text)
- else:
- GContent(self.xmlStack[0], text)
- #print ">>>%s" % text
def endElement(self, name):
@@ -291,8 +299,11 @@
def toXML(self):
return saxutils.escape(self._content)
- def dumpXML(self, lookupDict, treeDump=None, gap=None):
- return saxutils.escape(self._content)
+ def dumpXML(self, lookupDict, treeDump=None, gap=None, escape=1):
+ if escape:
+ return saxutils.escape(self._content)
+ else:
+ return self._content
def showTree(self, indent=0):
print ' '*indent + 'GContent ' + `self._content`
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- gnue/gnue-common/gnue/common GConfig.py GDataSo...,
Jason Cater <=