Closed tomschr closed 8 years ago
If something is not implemented, I would raise the NotImplementedError exception (see line 117)
According to the python documentation (https://docs.python.org/3/library/exceptions.html#concrete-exceptions), that's not now NotImplementedError should be used. As it's only a single occurence, I'll keep it as DBXIException for now.
Forgot to comment on that:
Collect all namespaces and save it, for example, in a separate file (for example, core.py). Avoids any nasty typos. ;) Include it where necessary.
The dependency hierarchy is dbxincluder.init > dbxincluder.docbook > dbxincluder.xinclude so this isn't needed IMO as every dependency (except utils) is only used once.
The dependency hierarchy ...
IMHO this hasn't anything to do with dependency hierarchy. :)
For example, in src/dbxincluder/xinclude.py
you have six occurances of http://www.w3.org/XML/1998/namespace
and two for http://www.w3.org/2001/XInclude/local-attributes
.
I think that code cries to refactor that part and use constants to collect all namespaces. If it is in a separate file or in the xinclude.py
itself is not really relevant for me. However, duplicate strings should be avoided. Good chances for typos! ;-)
For example, you could start with an NS
dict in xinclude.py
:
NS=dict(xml='http://www.w3.org/XML/1998/namespace',
local="http://www.w3.org/2001/XInclude/local-attributes",
xi="http://www.w3.org/2001/XInclude",
)
With the help of etree.QName
you can build your curly-braces-notation automatically:
# using the above dict:
xmlid = etree.QName(NS['xml'], 'id')
Here are some more usecases:
>>> xmlid = etree.QName(NS['xml'], 'id')
>>> xmlid.text
'{http://www.w3.org/XML/1998/namespace}id'
>>> xmlid.namespace
'http://www.w3.org/XML/1998/namespace'
>>> xmlid.localname
'id'
Oh, that's what you meant by namespaces... I thought about namespaces as python includes.
etree.QName looks definitely useful.
Oh, that's what you meant by namespaces... I thought about namespaces as python includes.
Oh, I'm sorry, I had better say XML namespaces. :grin:
Fixed!
core.py
). Avoids any nasty typos. ;) Include it where necessary.__init__.py
:NotImplementedError
exception (see line 117)xinclude.py
:DBXIException
exception class into a separate filecore.py
(in that example).Enough for today. ;-)