82 |
|
|
83 |
def read(self, file_or_filename): |
def read(self, file_or_filename): |
84 |
|
|
85 |
if hasattr(file_or_filename, "write"): |
if hasattr(file_or_filename, "read"): |
86 |
# it's a file object |
# it's a file object |
87 |
self.__directory = "" |
self.__directory = "" |
88 |
self.__file = file_or_filename |
self.__file = file_or_filename |
133 |
|
|
134 |
|
|
135 |
def AddDispatchers(self, dict): |
def AddDispatchers(self, dict): |
136 |
self.__dispatchers.update(dict) |
"""Add the function names that should be used to process XML tags. |
137 |
|
|
138 |
|
dict -- a dictionary whose keys are XML tag strings and whose values |
139 |
|
are pairs of strings such that the first string is |
140 |
|
the name of the function that should be called when the |
141 |
|
XML tag opens and the second string is the name of the |
142 |
|
function that should be called when the XML tag closes. |
143 |
|
If a pair element is None, no function is called. |
144 |
|
""" |
145 |
|
|
146 |
#for key, (start, end) in dict.iteritems(): |
self.__dispatchers.update(dict) |
|
#if start is not None: self.start_dispatcher[key] = start |
|
|
#if end is not None: self.end_dispatcher[key] = end |
|
147 |
|
|
148 |
def startElementNS(self, name, qname, attrs): |
def startElementNS(self, name, qname, attrs): |
149 |
"""Call the method given for name in self.start_dispatcher |
"""Call the method given for name in self.start_dispatcher |
150 |
""" |
""" |
151 |
if name[0] is None: |
if name[0] is None: |
152 |
method_name = self.__dispatchers.get(name[1]) |
method_name = self.__dispatchers.get(name[1]) |
|
#method_name = self.start_dispatcher.get(name[1]) |
|
153 |
else: |
else: |
154 |
# Dispatch with namespace |
# Dispatch with namespace |
155 |
method_name = self.__dispatchers.get(name) |
method_name = self.__dispatchers.get(name) |
156 |
if method_name is not None \ |
if method_name is not None and method_name[0] is not None: |
|
and method_name[0] is not None: |
|
157 |
getattr(self, method_name[0])(name, qname, attrs) |
getattr(self, method_name[0])(name, qname, attrs) |
158 |
|
|
159 |
def endElementNS(self, name, qname): |
def endElementNS(self, name, qname): |
161 |
""" |
""" |
162 |
if name[0] is None: |
if name[0] is None: |
163 |
method_name = self.__dispatchers.get(name[1]) |
method_name = self.__dispatchers.get(name[1]) |
|
#method_name = self.end_dispatcher.get(name[1]) |
|
164 |
else: |
else: |
165 |
# Dispatch with namespace |
# Dispatch with namespace |
166 |
method_name = self.__dispatchers.get(name) |
method_name = self.__dispatchers.get(name) |
167 |
if method_name is not None \ |
if method_name is not None and method_name[1] is not None: |
|
and method_name[1] is not None: |
|
168 |
getattr(self, method_name[1])(name, qname) |
getattr(self, method_name[1])(name, qname) |
169 |
|
|
170 |
class SessionLoader(XMLReader): |
class SessionLoader(XMLReader): |