pyxb-users Mailing List for PyXB: Python XML Schema Bindings (Page 6)
Brought to you by:
pabigot
You can subscribe to this list here.
2009 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(4) |
Sep
(3) |
Oct
|
Nov
(11) |
Dec
(17) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2010 |
Jan
(17) |
Feb
(3) |
Mar
|
Apr
|
May
(7) |
Jun
(1) |
Jul
(7) |
Aug
(3) |
Sep
|
Oct
(7) |
Nov
(4) |
Dec
(2) |
2011 |
Jan
(3) |
Feb
(4) |
Mar
|
Apr
(4) |
May
|
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
(14) |
Nov
|
Dec
|
2012 |
Jan
(8) |
Feb
(7) |
Mar
(5) |
Apr
(5) |
May
(16) |
Jun
(5) |
Jul
(3) |
Aug
(2) |
Sep
|
Oct
|
Nov
(3) |
Dec
(1) |
2013 |
Jan
(4) |
Feb
(9) |
Mar
(8) |
Apr
(5) |
May
|
Jun
|
Jul
(2) |
Aug
|
Sep
(5) |
Oct
(9) |
Nov
(2) |
Dec
|
2014 |
Jan
|
Feb
(19) |
Mar
(4) |
Apr
(3) |
May
(3) |
Jun
(1) |
Jul
|
Aug
(3) |
Sep
|
Oct
(3) |
Nov
|
Dec
(3) |
2015 |
Jan
|
Feb
(3) |
Mar
(1) |
Apr
(10) |
May
(3) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(4) |
Nov
|
Dec
(1) |
2016 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(3) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
2017 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2018 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Peter B. <bi...@ac...> - 2012-05-16 14:55:28
|
On Tue, May 15, 2012 at 9:25 PM, Nathan Robertson <na...@na...> wrote: > Hi Peter, > > On 15 May 2012 22:10, Peter Bigot <bi...@ac...> wrote: >> Thanks for the detailed investigation. Before getting into the >> contextualized responses below, did you use PyXB 1.1.3 for that, or >> were you using the current development version (the next branch from >> git)? I'm seeing some differences in behavior locally, and don't know >> whether it's because of the large number of changes to PyXB's >> date/time classes since the last release, or environment differences. > > I was using PyXB 1.1.3. I repeated the tests against the git-next > branch this morning using Python 2.7.3 (compiled from source) on SuSE > Linux Enterprise 11 SP2 x64. Here's what I get (first block is > 1.1.4-DEV; second block is 1.1.3): > > (pyenv-pyxb-next)nathanr@gionta:~/work/junkcode/pyxb-datetime-test> > python test2.py > datetime.datetime.now() prints 2012-05-16 09:38:58.946262 > Using PyXB 1.1.4-DEV, Python 2.7.3 (default, Apr 30 2012, 14:51:37) > [GCC 4.3.4 [gcc-4_3-branch revision 152973]] > <?xml version="1.0" ?><ns1:timestamp > xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157+10:00</ns1:timestamp> > --> 2012-05-14 06:36:02.157000+00:00 --> <?xml version="1.0" > ?><ns1:timestamp > xmlns:ns1="http://test.com/test">2012-05-14T06:36:02.157Z</ns1:timestamp> > <?xml version="1.0" ?><ns1:timestamp > xmlns:ns1="http://test.com/test">2012-05-14T06:36:02.157Z</ns1:timestamp> > --> 2012-05-14 06:36:02.157000+00:00 --> <?xml version="1.0" > ?><ns1:timestamp > xmlns:ns1="http://test.com/test">2012-05-14T06:36:02.157Z</ns1:timestamp> > <?xml version="1.0" ?><ns1:timestamp > xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157</ns1:timestamp> > --> 2012-05-14 16:36:02.157000 --> <?xml version="1.0" > ?><ns1:timestamp > xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157</ns1:timestamp> > (pyenv-pyxb-next)nathanr@gionta:~/work/junkcode/pyxb-datetime-test> > > > (pyenv-zktraining)nathanr@gionta:~/work/junkcode/pyxb-datetime-test> > python test2.py > datetime.datetime.now() prints 2012-05-16 09:45:35.325685 > Using PyXB 1.1.3, Python 2.7.3 (default, Apr 30 2012, 14:51:37) > [GCC 4.3.4 [gcc-4_3-branch revision 152973]] > <?xml version="1.0" ?><ns1:timestamp > xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157+10:00</ns1:timestamp> > --> 2012-05-14 06:36:02.157000 --> <?xml version="1.0" > ?><ns1:timestamp > xmlns:ns1="http://test.com/test">2012-05-14T06:36:02.157Z</ns1:timestamp> > <?xml version="1.0" ?><ns1:timestamp > xmlns:ns1="http://test.com/test">2012-05-14T06:36:02.157Z</ns1:timestamp> > --> 2012-05-14 06:36:02.157000 --> <?xml version="1.0" > ?><ns1:timestamp > xmlns:ns1="http://test.com/test">2012-05-14T06:36:02.157Z</ns1:timestamp> > <?xml version="1.0" ?><ns1:timestamp > xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157</ns1:timestamp> > --> 2012-05-14 16:36:02.157000 --> <?xml version="1.0" > ?><ns1:timestamp > xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157</ns1:timestamp> > (pyenv-zktraining)nathanr@gionta:~/work/junkcode/pyxb-datetime-test> > > > The only difference between the behaviour in 1.1.3 and 1.1.4-DEV is > that "+00:00" is printed, and confirms that it is printing GMT for > some reason. Yes. The error in 1.1.3 was that the tzinfo field was not being set to preserve the fact that the time had been converted to UTC. Python will print the tzinfo field if it is non-None. > Is this environmental or something to do with my > configuration? The Java version of these tests picks up I'm +10:00, > and I also re-ran the tests on 1.1.4-DEV with both the SuSE provided > Python 2.6.0 and on Ubuntu 11.10 with their packaged version of Python > 2.7.2 and the output is still the same (+00:00). What do you get in > your environment? As best I can tell with gmail's wrapping (which is a hassle for me too), I get the same thing as you do. >[...] >> PyXB should always use the canonical representation when converting a >> value to text in a context where it will be used in XML, i.e. via >> v.xsdLiteral(). It will defer to the underlying Python implementation >> when converting a value to text by implicit or explicit use of str(). > > Section 3.2.7.3 (http://www.w3.org/TR/xmlschema-2/#dateTime) suggests > that canonical and non-canonical formats equivalent and > interchangeable. It would be a feature to be able to configure which > of the formats XML generated by PyXB will produce. It needn't be the > same time zone as the input - it makes sense to me to output > non-canonical times with respect to the local time zone, not the > inputted time zone (if any). The question here is expectation. Personally, I would expect UTC or the original timezone. >>> 2. Python printing out pyxb.binding.datatypes.dateTime's as GMT when >>> it prints out datetime.datetime's as local time is inconsistent. It >>> should represent itself to code (and print out its value) as local >>> time, not GMT. It should be compatible with datetime.datetime, which >>> it extends, and hence can be (and does get) used in place of in client >>> code. For mine, this is a PyXB bug, and is causing us problems in our >>> code at the moment. >> >> I believe this is fixed. > > Perhaps the issue I'm seeing is environmental. As I noted above, could > you re-run the test I'm running (I'll include the code at the bottom > of this post) and confirm whether you're seeing the same behaviour as > me? > > >> If you use my test program and add: >> >> showdt(xsd.dateTime.today().aslocal()) >> >> you can see behavior more like what you may want: >> >> class <type 'datetime.datetime'> >> timezone <pyxb.utils.utility.LocalTimeZone object at 0x260db50> >> str 2012-05-15 02:02:27.455888-05:00 >> >> Note that you have to use today() because now() produces a >> non-timezoned time, and the addition of the timezone screws things up. >> I'm not sure why I made PyXB's today() overload explicitly include a >> timezone. At the moment, that seems like a mistake, and I should have >> used a different name for that, since the documentation for >> datetime.today() explicitly says the tzinfo in the result is None. >> http://docs.python.org/library/datetime.html#datetime-objects > > Now that explains a lot, actually. When I add aslocal() in, I get: > > <?xml version="1.0" ?><ns1:timestamp > xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157+10:00</ns1:timestamp> > --> 2012-05-14 06:36:02.157000+00:00 2012-05-14 16:36:02.157000+10:00 > --> <?xml version="1.0" ?><ns1:timestamp > xmlns:ns1="http://test.com/test">2012-05-14T06:36:02.157Z</ns1:timestamp> > > Which would work, except aslocal() doesn't exist in the base datetime type: > >>>> print datetime.datetime.now() > 2012-05-16 10:35:10.274615 >>>> print datetime.datetime.now().aslocal() > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > AttributeError: 'datetime.datetime' object has no attribute 'aslocal' >>>> Yes, aslocal() was a mistake, added in part to help me understand the same sort of issues you're seeing. (E.g., when you see an absolute time as HH:MM:SS + TZ, does the TZ indicate that the offset has already been applied, or needs to be applied, in order to present the time as UTC? Huge difference, and at the moment misuse of aslocal() can easily get it wrong.) > This morning we decided to make a change to our Java code to always > output dates with no timezone information, and PyXB puts out > datetime.datetime objects without tzinfo set as without timezone > information as well. So totally turning off time zones information in > both directions is a workaround that we can work with in our > particular situation. Not knowing your situation, it's good you have a workaround. Personally, my gut clenches at the thought of eliminating timezones from the data. It really complicates correlation between events unless you're entirely within a single timezone that does not observe daylight savings time. Please review the enhancement I've made, and see if you can change your mind. >> One possibility I would entertain is an option to prevent PyXB from >> performing the normalize-to-UTC step when processing timezoned times. >> In that case, the tzinfo information would be present and not have a >> zero offset, and the underlying Python's datetime class should provide >> the preserved timezone when being converted via str(). >> >> I'm not absolutely convinced that this is a great idea, though, since >> it's so incredibly easy to screw things up when dealing with >> timezones. > > I would have thought this would have been the right way. If I'm > understanding you correctly, this should make pyxb's dateTime object > symmetrical and interchangable with the base datetime object, which > should be a design goal. Consistency with similar Python data types is a secondary goal. The primary goal is conformance to XML. This is why xsd:date is now based on datetime.datetime instead of datetime.date: XML supports the concept of a timezoned date, and Python's date type doesn't allow that. I don't think I've explained this well: XML times do not have a time zone as part of the value space. All values are converted to UTC as soon as they're translated into Python. This is why PyXB can't reconstruct your +10:00 offset: it's not there anymore. The tzinfo attribute is used solely to prove that the value is in fact in UTC, and is not a non-timezoned time (what Python calls a "naive time") for which zone information is not available. A non-timezoned time could technically be anywhere within a 28 [sic] hour period, given XML's constraint that timezones have a magnitude of no more than 14 hours. To make this more clear and because the feature makes sense, I've gone ahead and created a ticket for and implemented the customization point I proposed. Using pyxb.PreserveInputTimeZone(True) will inhibit the automatic canonicalization, keeping the original tzinfo in the value space. There is a cost of potential interoperability issues with other XML processors, and code errors if whatever uses the value doesn't do timezone-aware manipulations. Use "git pull" to update your 1.1.4-DEV workspace. The result is different from your proposal earlier that PyXB convert times to the non-canonical form representing the local timezone for output. I'd be somewhat more reluctant to do that, as it would involve actively manipulating the data in a manner not supported by the specification. If you want that, please add a ticket, but I'd probably implement it by adding a hook mechanism to allow a developer to override how PyXB creates the xsdLiteral form. Expected results from a modified version of your test program are: datetime.datetime.now() prints 2012-05-16 09:51:04.584878 Using PyXB 1.1.4-DEV, Python 2.7.3 (default, Apr 13 2012, 20:16:59) [GCC 4.6.3 20120306 (Red Hat 4.6.3-2)] <?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157+10:00</ns1:timestamp> --> 2012-05-14 06:36:02.157000+00:00 --> <?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T06:36:02.157Z</ns1:timestamp> <?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T06:36:02.157Z</ns1:timestamp> --> 2012-05-14 06:36:02.157000+00:00 --> <?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T06:36:02.157Z</ns1:timestamp> <?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157</ns1:timestamp> --> 2012-05-14 16:36:02.157000 --> <?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157</ns1:timestamp> Preserving input time zone: <?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157+10:00</ns1:timestamp> --> 2012-05-14 16:36:02.157000+10:00 --> <?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157+10:00</ns1:timestamp> <?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T06:36:02.157Z</ns1:timestamp> --> 2012-05-14 06:36:02.157000+00:00 --> <?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T06:36:02.157Z</ns1:timestamp> <?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157</ns1:timestamp> --> 2012-05-14 16:36:02.157000 --> <?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157</ns1:timestamp> The program itself is below. import sys import types import datetime import pyxb.binding.generate import os.path xsd='''<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://test.com/test" xmlns:zenkai="http://test.com/test"> <xsd:element name="timestamp" type="xsd:dateTime"/> </xsd:schema>''' #file('schema.xsd', 'w').write(xsd) code = pyxb.binding.generate.GeneratePython(schema_text=xsd) #file('code.py', 'w').write(code) rv = compile(code, 'test', 'exec') eval(rv) xml_list = ('<?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157+10:00</ns1:timestamp>', '<?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T06:36:02.157Z</ns1:timestamp>', '<?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157</ns1:timestamp>',) print "datetime.datetime.now() prints {0}".format(datetime.datetime.now()) print "Using PyXB {0}, Python {1}".format(pyxb.__version__, sys.version) for xml in xml_list: obj = CreateFromDocument(xml) print "{0} --> {1} --> {2}".format(xml, obj, obj.toxml()) print 'Preserving input time zone:' pyxb.PreserveInputTimeZone(True) for xml in xml_list: obj = CreateFromDocument(xml) print "{0} --> {1} --> {2}".format(xml, obj, obj.toxml()) |
From: Nathan R. <na...@na...> - 2012-05-16 02:25:52
|
Hi Peter, On 15 May 2012 22:10, Peter Bigot <bi...@ac...> wrote: > Thanks for the detailed investigation. Before getting into the > contextualized responses below, did you use PyXB 1.1.3 for that, or > were you using the current development version (the next branch from > git)? I'm seeing some differences in behavior locally, and don't know > whether it's because of the large number of changes to PyXB's > date/time classes since the last release, or environment differences. I was using PyXB 1.1.3. I repeated the tests against the git-next branch this morning using Python 2.7.3 (compiled from source) on SuSE Linux Enterprise 11 SP2 x64. Here's what I get (first block is 1.1.4-DEV; second block is 1.1.3): (pyenv-pyxb-next)nathanr@gionta:~/work/junkcode/pyxb-datetime-test> python test2.py datetime.datetime.now() prints 2012-05-16 09:38:58.946262 Using PyXB 1.1.4-DEV, Python 2.7.3 (default, Apr 30 2012, 14:51:37) [GCC 4.3.4 [gcc-4_3-branch revision 152973]] <?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157+10:00</ns1:timestamp> --> 2012-05-14 06:36:02.157000+00:00 --> <?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T06:36:02.157Z</ns1:timestamp> <?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T06:36:02.157Z</ns1:timestamp> --> 2012-05-14 06:36:02.157000+00:00 --> <?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T06:36:02.157Z</ns1:timestamp> <?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157</ns1:timestamp> --> 2012-05-14 16:36:02.157000 --> <?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157</ns1:timestamp> (pyenv-pyxb-next)nathanr@gionta:~/work/junkcode/pyxb-datetime-test> (pyenv-zktraining)nathanr@gionta:~/work/junkcode/pyxb-datetime-test> python test2.py datetime.datetime.now() prints 2012-05-16 09:45:35.325685 Using PyXB 1.1.3, Python 2.7.3 (default, Apr 30 2012, 14:51:37) [GCC 4.3.4 [gcc-4_3-branch revision 152973]] <?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157+10:00</ns1:timestamp> --> 2012-05-14 06:36:02.157000 --> <?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T06:36:02.157Z</ns1:timestamp> <?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T06:36:02.157Z</ns1:timestamp> --> 2012-05-14 06:36:02.157000 --> <?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T06:36:02.157Z</ns1:timestamp> <?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157</ns1:timestamp> --> 2012-05-14 16:36:02.157000 --> <?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157</ns1:timestamp> (pyenv-zktraining)nathanr@gionta:~/work/junkcode/pyxb-datetime-test> The only difference between the behaviour in 1.1.3 and 1.1.4-DEV is that "+00:00" is printed, and confirms that it is printing GMT for some reason. Is this environmental or something to do with my configuration? The Java version of these tests picks up I'm +10:00, and I also re-ran the tests on 1.1.4-DEV with both the SuSE provided Python 2.6.0 and on Ubuntu 11.10 with their packaged version of Python 2.7.2 and the output is still the same (+00:00). What do you get in your environment? > In particular, it appears to me that datetime.datetime.now() and > xsd.dateTime.now() are essentially the same: > > llc[21]$ cat /tmp/p1.py > import datetime > import pyxb.binding.datatypes as xsd > > def showdt (dt): > print 'class %s\n\ttimezone %s\n\tstr %s' % (type(dt), dt.tzinfo, str(dt)) > > showdt(datetime.datetime.now()) > showdt(xsd.dateTime.now()) > llc[22]$ python /tmp/p1.py > class <type 'datetime.datetime'> > timezone None > str 2012-05-15 06:30:12.653698 > class <class 'pyxb.binding.datatypes.dateTime'> > timezone None > str 2012-05-15 06:30:12.653771 > llc[23]$ Yeah, that test passes ok. I get the same result. > PyXB should always use the canonical representation when converting a > value to text in a context where it will be used in XML, i.e. via > v.xsdLiteral(). It will defer to the underlying Python implementation > when converting a value to text by implicit or explicit use of str(). Section 3.2.7.3 (http://www.w3.org/TR/xmlschema-2/#dateTime) suggests that canonical and non-canonical formats equivalent and interchangeable. It would be a feature to be able to configure which of the formats XML generated by PyXB will produce. It needn't be the same time zone as the input - it makes sense to me to output non-canonical times with respect to the local time zone, not the inputted time zone (if any). >> 2. Python printing out pyxb.binding.datatypes.dateTime's as GMT when >> it prints out datetime.datetime's as local time is inconsistent. It >> should represent itself to code (and print out its value) as local >> time, not GMT. It should be compatible with datetime.datetime, which >> it extends, and hence can be (and does get) used in place of in client >> code. For mine, this is a PyXB bug, and is causing us problems in our >> code at the moment. > > I believe this is fixed. Perhaps the issue I'm seeing is environmental. As I noted above, could you re-run the test I'm running (I'll include the code at the bottom of this post) and confirm whether you're seeing the same behaviour as me? > If you use my test program and add: > > showdt(xsd.dateTime.today().aslocal()) > > you can see behavior more like what you may want: > > class <type 'datetime.datetime'> > timezone <pyxb.utils.utility.LocalTimeZone object at 0x260db50> > str 2012-05-15 02:02:27.455888-05:00 > > Note that you have to use today() because now() produces a > non-timezoned time, and the addition of the timezone screws things up. > I'm not sure why I made PyXB's today() overload explicitly include a > timezone. At the moment, that seems like a mistake, and I should have > used a different name for that, since the documentation for > datetime.today() explicitly says the tzinfo in the result is None. > http://docs.python.org/library/datetime.html#datetime-objects Now that explains a lot, actually. When I add aslocal() in, I get: <?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157+10:00</ns1:timestamp> --> 2012-05-14 06:36:02.157000+00:00 2012-05-14 16:36:02.157000+10:00 --> <?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T06:36:02.157Z</ns1:timestamp> Which would work, except aslocal() doesn't exist in the base datetime type: >>> print datetime.datetime.now() 2012-05-16 10:35:10.274615 >>> print datetime.datetime.now().aslocal() Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'datetime.datetime' object has no attribute 'aslocal' >>> This morning we decided to make a change to our Java code to always output dates with no timezone information, and PyXB puts out datetime.datetime objects without tzinfo set as without timezone information as well. So totally turning off time zones information in both directions is a workaround that we can work with in our particular situation. > One possibility I would entertain is an option to prevent PyXB from > performing the normalize-to-UTC step when processing timezoned times. > In that case, the tzinfo information would be present and not have a > zero offset, and the underlying Python's datetime class should provide > the preserved timezone when being converted via str(). > > I'm not absolutely convinced that this is a great idea, though, since > it's so incredibly easy to screw things up when dealing with > timezones. I would have thought this would have been the right way. If I'm understanding you correctly, this should make pyxb's dateTime object symmetrical and interchangable with the base datetime object, which should be a design goal. Regards, Nathan. Python test code (appologies for GMail's text wrapping of lines below - I don't think it can be turned off): import datetime import pyxb import pyxb_generated import sys """ $ pyxbgen --schema-root=. -u schema.xsd -m pyxb_generated <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://test.com/test" xmlns:zenkai="http://test.com/test"> <xsd:element name="timestamp" type="xsd:dateTime"/> </xsd:schema> """ xml_list = ('<?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157+10:00</ns1:timestamp>', '<?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T06:36:02.157Z</ns1:timestamp>', '<?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157</ns1:timestamp>',) print "datetime.datetime.now() prints {0}".format(datetime.datetime.now()) print "Using PyXB {0}, Python {1}".format(pyxb.__version__, sys.version) for xml in xml_list: obj = pyxb_generated.CreateFromDocument(xml) print "{0} --> {1} --> {2}".format(xml, obj, obj.toxml()) |
From: Peter B. <bi...@ac...> - 2012-05-15 12:10:20
|
Thanks for the detailed investigation. Before getting into the contextualized responses below, did you use PyXB 1.1.3 for that, or were you using the current development version (the next branch from git)? I'm seeing some differences in behavior locally, and don't know whether it's because of the large number of changes to PyXB's date/time classes since the last release, or environment differences. In particular, it appears to me that datetime.datetime.now() and xsd.dateTime.now() are essentially the same: llc[21]$ cat /tmp/p1.py import datetime import pyxb.binding.datatypes as xsd def showdt (dt): print 'class %s\n\ttimezone %s\n\tstr %s' % (type(dt), dt.tzinfo, str(dt)) showdt(datetime.datetime.now()) showdt(xsd.dateTime.now()) llc[22]$ python /tmp/p1.py class <type 'datetime.datetime'> timezone None str 2012-05-15 06:30:12.653698 class <class 'pyxb.binding.datatypes.dateTime'> timezone None str 2012-05-15 06:30:12.653771 llc[23]$ On Tue, May 15, 2012 at 1:14 AM, Nathan Robertson <na...@na...> wrote: > Hi Peter, > > On 14 May 2012 20:49, Peter Bigot <bi...@ac...> wrote: >> I'm not sure. As you saw, http://www.w3.org/TR/xmlschema-2/#dateTime >> is pretty clear that anything that had a timezone is to be treated as >> UTC. If the original lexical space didn't have a timezone, I think I >> set it up to be given the local timezone; it might be argued that that >> is a mistake, but it might also have been necessary for consistency. >> >> If you would file this as a trac request I'll see what I can do. >> Please make it clear whether you just want xsd.dateTime.now() to be >> symmetrical or whether you need values that lack a timezone to do >> something other than what they do now. > > Ok, so I wrote a Java / JAXB version of my python test posted late > yesterday to the mailing list. I'm using Python 2.7.3, PyXB 1.1.3, > Java 7u4 (which includes JAXB 2.2.4). The code reads in an XML string, > prints out the value it got, then converts it back to XML and prints > out that string. Here's the result - first in Python/PyXB, then > Java/JAXB: > > (pyenv-zktraining)nathanr@gionta:~/work/junkcode/pyxb-datetime-test> > python test2.py > datetime.datetime.now() prints 2012-05-15 15:16:12.167164 > <?xml version="1.0" ?><ns1:timestamp > xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157+10:00</ns1:timestamp> > --> 2012-05-14 06:36:02.157000 --> <?xml version="1.0" > ?><ns1:timestamp > xmlns:ns1="http://test.com/test">2012-05-14T06:36:02.157Z</ns1:timestamp> > <?xml version="1.0" ?><ns1:timestamp > xmlns:ns1="http://test.com/test">2012-05-14T06:36:02.157Z</ns1:timestamp> > --> 2012-05-14 06:36:02.157000 --> <?xml version="1.0" > ?><ns1:timestamp > xmlns:ns1="http://test.com/test">2012-05-14T06:36:02.157Z</ns1:timestamp> > <?xml version="1.0" ?><ns1:timestamp > xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157</ns1:timestamp> > --> 2012-05-14 16:36:02.157000 --> <?xml version="1.0" > ?><ns1:timestamp > xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157</ns1:timestamp> > > (pyenv-zktraining)nathanr@gionta:~/work/junkcode/pyxb-datetime-test> java Test2 > Calendar.getInstance() prints: 2012-05-15 15:16:14.612 > <?xml version="1.0" ?><ns1:timestamp > xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157+10:00</ns1:timestamp> > --> 2012-05-14 16:36:02.157 --> <?xml version="1.0" encoding="UTF-8" > standalone="yes"?><timestamp > xmlns="http://test.com/test">2012-05-14T16:36:02.157+10:00</timestamp> > <?xml version="1.0" ?><ns1:timestamp > xmlns:ns1="http://test.com/test">2012-05-14T06:36:02.157Z</ns1:timestamp> > --> 2012-05-14 06:36:02.157 --> <?xml version="1.0" encoding="UTF-8" > standalone="yes"?><timestamp > xmlns="http://test.com/test">2012-05-14T06:36:02.157Z</timestamp> > <?xml version="1.0" ?><ns1:timestamp > xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157</ns1:timestamp> > --> 2012-05-14 16:36:02.157 --> <?xml version="1.0" encoding="UTF-8" > standalone="yes"?><timestamp > xmlns="http://test.com/test">2012-05-14T16:36:02.157+10:00</timestamp> > (pyenv-zktraining)nathanr@gionta:~/work/junkcode/pyxb-datetime-test> > > > So, for the purposes of below: > > - I will call yyyy-mm-ddThh:mm:ss.mmm+TZ:TZ "format 1" (timestamp with > +timezone on the end) This is a non-canonical representation in XML. > - I will call yyyy-mm-ddThh:mm:ss.mmmZ "format 2" (Z on the end, > signifying GMT time) This is the canonical representation for timezoned objects in XML. > - I will call yyyy-mm-ddThh:mm:ss.mmm "format 3" (no time zone) This is the canonical representation for non-timezoned objects. PyXB should always use the canonical representation when converting a value to text in a context where it will be used in XML, i.e. via v.xsdLiteral(). It will defer to the underlying Python implementation when converting a value to text by implicit or explicit use of str(). > > - Given an xsd:dateTime with format 1, PyXB will print the object out > in format 3, in GMT time, and marshal the date back out to XML in > format 2. > - Given an xsd:dateTime with format 1, JAXB will print the object out > in format 3, in local time, and marshal the date back out to XML in > format 1. > > - Given an xsd:dateTime with format 2, PyXB will print the object out > in format 3, in GMT time, and marshal the date back out to XML in > format 2. > - Given an xsd:dateTime with format 2, JAXB will print the object out > in format 3, in GMT time, and marshal the date back out to XML in > format 2. > > - Given an xsd:dateTime with format 3, PyXB will print the object out > in format 3, in local time, and marshal the date back out to XML in > format 3. > - Given an xsd:dateTime with format 3, JAXB will print the object out > in format 3, in local time, and marshal the date back out to XML in > format 1 (assuming local time by default) > > > Notes on the above: > > 1. JAXB handling of format 2 ("GMT time with trailing Z") appears > inconsistent. Why they would represent the object to client code in > GMT in that case, but as local time in the case of format 1 input, > I'll never know, and makes JAXB Calendar's inconsistent with the rest > of the Java platform when using format 2 input. I think this is > probably a JAXB bug. So, as a JAXB consumer, it is better to have > format 1 input, as JAXB Calendar's with format 1 input are symmetrical > and compatible with Calendar.getInstance() generated (standard > platform) calendars. > > 2. Python printing out pyxb.binding.datatypes.dateTime's as GMT when > it prints out datetime.datetime's as local time is inconsistent. It > should represent itself to code (and print out its value) as local > time, not GMT. It should be compatible with datetime.datetime, which > it extends, and hence can be (and does get) used in place of in client > code. For mine, this is a PyXB bug, and is causing us problems in our > code at the moment. I believe this is fixed. > 3. It's debatable what to do with format 3, but at least PyXB and JAXB > read it in the same. I think the current decision on handling format 3 > in PyXB is probably the right one. My personal opinion is that JAXB > printing out in format 1 and not format 3 in the case of format 3 > input is a mistake, but I can see arguments both ways. The argument > that "it's because JAXB always outputs format 1" is actually wrong, > because it doesn't do that for format 2 input. > > > So, there are two things I think need to be looked at for changing: > > 1. For interoperability, it would be nice if PyXB could print out in > format 1. Whether it be by default, or outputting in format 1 as a > configurable option. Those interoperating with JAXB code will want to > have PyXB output format 1, for sure. "Print out" in this case means what comes out of str(v) where v is an instance of the class? Because AFAICT that's just deferring to the underlying Python datetime.datetime.implementation which PyXB's dateTime class inherits. I can't really change that. The other issue is that http://www.w3.org/TR/xmlschema-2/#dateTime is extremely clear: All timezoned times are Coordinated Universal Time (UTC, sometimes called "Greenwich Mean Time"). Other timezones indicated in lexical representations are converted to UTC during conversion of literals to values. As such, there's nothing that will retain the +10:00 from the input once it's made into a value. PyXB retains fact-of timezone by having a non-None tzinfo attribute, but the fact that the offset is zero inhibits Python from printing it. If you use my test program and add: showdt(xsd.dateTime.today().aslocal()) you can see behavior more like what you may want: class <type 'datetime.datetime'> timezone <pyxb.utils.utility.LocalTimeZone object at 0x260db50> str 2012-05-15 02:02:27.455888-05:00 Note that you have to use today() because now() produces a non-timezoned time, and the addition of the timezone screws things up. I'm not sure why I made PyXB's today() overload explicitly include a timezone. At the moment, that seems like a mistake, and I should have used a different name for that, since the documentation for datetime.today() explicitly says the tzinfo in the result is None. http://docs.python.org/library/datetime.html#datetime-objects > 2. pyxb.binding.datatypes.dateTime should represent itself to client > code in a compatible way to datetime.datetime such that it can be a > drop in replacement (particularly given it subclasses it). That means > it should represent itself to client code as local time, not GMT. > What I tried up at the top suggests that PyXB does do this. It may be that some locale information in your environment is affecting the underlying Python behavior, though, causing PyXB's results to have a timezone attached. (I'm using Python 2.7.3 on Linux.) The other conflict is that I suspect Python is not displaying the effect of any timezone information, at least in str(), which is why things look like local time even when there is a timezone attached. > Peter - are you ok with me opening two Trac tickets for the above two > suggestions? Both are issues that will cause us problems for our July > production release I referenced in another email earlier today. >From my tests I believe PyXB's doing the overall right thing. If you still have problems when using the pre-release 1.1.4 material in git, let's keep discussing this. One possibility I would entertain is an option to prevent PyXB from performing the normalize-to-UTC step when processing timezoned times. In that case, the tzinfo information would be present and not have a zero offset, and the underlying Python's datetime class should provide the preserved timezone when being converted via str(). I'm not absolutely convinced that this is a great idea, though, since it's so incredibly easy to screw things up when dealing with timezones. > The Python code was in a previous posting - I'm providing the > Java/JAXB code below for completeness / mailing list archiving > purposes. > > Regards, > Nathan. > > -- > > import generated.*; > import javax.xml.*; > import javax.xml.bind.*; > import javax.xml.datatype.*; > import javax.xml.validation.*; > import java.io.*; > import java.net.*; > import java.util.*; > > /* > $ xjc -d . -p generated schema.xsd > $ javac Test2.java > $ java Test2 > > schema.xsd is: > <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" > targetNamespace="http://test.com/test" > xmlns:zenkai="http://test.com/test"> > <xsd:element name="timestamp" type="xsd:dateTime"/> > </xsd:schema> > */ > > public class Test2 { > private static final String[] XML_LIST = { > "<?xml version=\"1.0\" ?><ns1:timestamp > xmlns:ns1=\"http://test.com/test\">2012-05-14T16:36:02.157+10:00</ns1:timestamp>", > "<?xml version=\"1.0\" ?><ns1:timestamp > xmlns:ns1=\"http://test.com/test\">2012-05-14T06:36:02.157Z</ns1:timestamp>", > "<?xml version=\"1.0\" ?><ns1:timestamp > xmlns:ns1=\"http://test.com/test\">2012-05-14T16:36:02.157</ns1:timestamp>" > }; > > public static void main(String args[]) throws Exception { > Calendar c = Calendar.getInstance(); > System.out.format("Calendar.getInstance() prints: %1$tF > %1$tR:%1$tS.%1$tL", c); > System.out.println(""); > > ObjectFactory of = new ObjectFactory(); > JAXBContext jc = JAXBContext.newInstance("generated"); > Unmarshaller u = jc.createUnmarshaller(); > Marshaller m = jc.createMarshaller(); > m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.FALSE); > > URL url = new Test2().getClass().getClassLoader().getResource("schema.xsd"); > SchemaFactory sf = > SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); > Schema schema = sf.newSchema(url); > u.setSchema(schema); > > for (String xml: XML_LIST) { > System.out.print(xml); > > GregorianCalendar timestampIn = ((XMLGregorianCalendar) > ((JAXBElement<?>) u.unmarshal(new > ByteArrayInputStream(xml.getBytes()))).getValue()).toGregorianCalendar(); > System.out.format(" --> %1$tF %1$tR:%1$tS.%1$tL --> ", timestampIn); > > StringWriter sw = new StringWriter(); > m.marshal(of.createTimestamp(DatatypeFactory.newInstance().newXMLGregorianCalendar(timestampIn)), > sw); > System.out.println(sw.toString()); > } > } > } |
From: Nathan R. <na...@na...> - 2012-05-15 06:14:59
|
Hi Peter, On 14 May 2012 20:49, Peter Bigot <bi...@ac...> wrote: > I'm not sure. As you saw, http://www.w3.org/TR/xmlschema-2/#dateTime > is pretty clear that anything that had a timezone is to be treated as > UTC. If the original lexical space didn't have a timezone, I think I > set it up to be given the local timezone; it might be argued that that > is a mistake, but it might also have been necessary for consistency. > > If you would file this as a trac request I'll see what I can do. > Please make it clear whether you just want xsd.dateTime.now() to be > symmetrical or whether you need values that lack a timezone to do > something other than what they do now. Ok, so I wrote a Java / JAXB version of my python test posted late yesterday to the mailing list. I'm using Python 2.7.3, PyXB 1.1.3, Java 7u4 (which includes JAXB 2.2.4). The code reads in an XML string, prints out the value it got, then converts it back to XML and prints out that string. Here's the result - first in Python/PyXB, then Java/JAXB: (pyenv-zktraining)nathanr@gionta:~/work/junkcode/pyxb-datetime-test> python test2.py datetime.datetime.now() prints 2012-05-15 15:16:12.167164 <?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157+10:00</ns1:timestamp> --> 2012-05-14 06:36:02.157000 --> <?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T06:36:02.157Z</ns1:timestamp> <?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T06:36:02.157Z</ns1:timestamp> --> 2012-05-14 06:36:02.157000 --> <?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T06:36:02.157Z</ns1:timestamp> <?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157</ns1:timestamp> --> 2012-05-14 16:36:02.157000 --> <?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157</ns1:timestamp> (pyenv-zktraining)nathanr@gionta:~/work/junkcode/pyxb-datetime-test> java Test2 Calendar.getInstance() prints: 2012-05-15 15:16:14.612 <?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157+10:00</ns1:timestamp> --> 2012-05-14 16:36:02.157 --> <?xml version="1.0" encoding="UTF-8" standalone="yes"?><timestamp xmlns="http://test.com/test">2012-05-14T16:36:02.157+10:00</timestamp> <?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T06:36:02.157Z</ns1:timestamp> --> 2012-05-14 06:36:02.157 --> <?xml version="1.0" encoding="UTF-8" standalone="yes"?><timestamp xmlns="http://test.com/test">2012-05-14T06:36:02.157Z</timestamp> <?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157</ns1:timestamp> --> 2012-05-14 16:36:02.157 --> <?xml version="1.0" encoding="UTF-8" standalone="yes"?><timestamp xmlns="http://test.com/test">2012-05-14T16:36:02.157+10:00</timestamp> (pyenv-zktraining)nathanr@gionta:~/work/junkcode/pyxb-datetime-test> So, for the purposes of below: - I will call yyyy-mm-ddThh:mm:ss.mmm+TZ:TZ "format 1" (timestamp with +timezone on the end) - I will call yyyy-mm-ddThh:mm:ss.mmmZ "format 2" (Z on the end, signifying GMT time) - I will call yyyy-mm-ddThh:mm:ss.mmm "format 3" (no time zone) - Given an xsd:dateTime with format 1, PyXB will print the object out in format 3, in GMT time, and marshal the date back out to XML in format 2. - Given an xsd:dateTime with format 1, JAXB will print the object out in format 3, in local time, and marshal the date back out to XML in format 1. - Given an xsd:dateTime with format 2, PyXB will print the object out in format 3, in GMT time, and marshal the date back out to XML in format 2. - Given an xsd:dateTime with format 2, JAXB will print the object out in format 3, in GMT time, and marshal the date back out to XML in format 2. - Given an xsd:dateTime with format 3, PyXB will print the object out in format 3, in local time, and marshal the date back out to XML in format 3. - Given an xsd:dateTime with format 3, JAXB will print the object out in format 3, in local time, and marshal the date back out to XML in format 1 (assuming local time by default) Notes on the above: 1. JAXB handling of format 2 ("GMT time with trailing Z") appears inconsistent. Why they would represent the object to client code in GMT in that case, but as local time in the case of format 1 input, I'll never know, and makes JAXB Calendar's inconsistent with the rest of the Java platform when using format 2 input. I think this is probably a JAXB bug. So, as a JAXB consumer, it is better to have format 1 input, as JAXB Calendar's with format 1 input are symmetrical and compatible with Calendar.getInstance() generated (standard platform) calendars. 2. Python printing out pyxb.binding.datatypes.dateTime's as GMT when it prints out datetime.datetime's as local time is inconsistent. It should represent itself to code (and print out its value) as local time, not GMT. It should be compatible with datetime.datetime, which it extends, and hence can be (and does get) used in place of in client code. For mine, this is a PyXB bug, and is causing us problems in our code at the moment. 3. It's debatable what to do with format 3, but at least PyXB and JAXB read it in the same. I think the current decision on handling format 3 in PyXB is probably the right one. My personal opinion is that JAXB printing out in format 1 and not format 3 in the case of format 3 input is a mistake, but I can see arguments both ways. The argument that "it's because JAXB always outputs format 1" is actually wrong, because it doesn't do that for format 2 input. So, there are two things I think need to be looked at for changing: 1. For interoperability, it would be nice if PyXB could print out in format 1. Whether it be by default, or outputting in format 1 as a configurable option. Those interoperating with JAXB code will want to have PyXB output format 1, for sure. 2. pyxb.binding.datatypes.dateTime should represent itself to client code in a compatible way to datetime.datetime such that it can be a drop in replacement (particularly given it subclasses it). That means it should represent itself to client code as local time, not GMT. Peter - are you ok with me opening two Trac tickets for the above two suggestions? Both are issues that will cause us problems for our July production release I referenced in another email earlier today. The Python code was in a previous posting - I'm providing the Java/JAXB code below for completeness / mailing list archiving purposes. Regards, Nathan. -- import generated.*; import javax.xml.*; import javax.xml.bind.*; import javax.xml.datatype.*; import javax.xml.validation.*; import java.io.*; import java.net.*; import java.util.*; /* $ xjc -d . -p generated schema.xsd $ javac Test2.java $ java Test2 schema.xsd is: <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://test.com/test" xmlns:zenkai="http://test.com/test"> <xsd:element name="timestamp" type="xsd:dateTime"/> </xsd:schema> */ public class Test2 { private static final String[] XML_LIST = { "<?xml version=\"1.0\" ?><ns1:timestamp xmlns:ns1=\"http://test.com/test\">2012-05-14T16:36:02.157+10:00</ns1:timestamp>", "<?xml version=\"1.0\" ?><ns1:timestamp xmlns:ns1=\"http://test.com/test\">2012-05-14T06:36:02.157Z</ns1:timestamp>", "<?xml version=\"1.0\" ?><ns1:timestamp xmlns:ns1=\"http://test.com/test\">2012-05-14T16:36:02.157</ns1:timestamp>" }; public static void main(String args[]) throws Exception { Calendar c = Calendar.getInstance(); System.out.format("Calendar.getInstance() prints: %1$tF %1$tR:%1$tS.%1$tL", c); System.out.println(""); ObjectFactory of = new ObjectFactory(); JAXBContext jc = JAXBContext.newInstance("generated"); Unmarshaller u = jc.createUnmarshaller(); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.FALSE); URL url = new Test2().getClass().getClassLoader().getResource("schema.xsd"); SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = sf.newSchema(url); u.setSchema(schema); for (String xml: XML_LIST) { System.out.print(xml); GregorianCalendar timestampIn = ((XMLGregorianCalendar) ((JAXBElement<?>) u.unmarshal(new ByteArrayInputStream(xml.getBytes()))).getValue()).toGregorianCalendar(); System.out.format(" --> %1$tF %1$tR:%1$tS.%1$tL --> ", timestampIn); StringWriter sw = new StringWriter(); m.marshal(of.createTimestamp(DatatypeFactory.newInstance().newXMLGregorianCalendar(timestampIn)), sw); System.out.println(sw.toString()); } } } |
From: Nathan R. <na...@na...> - 2012-05-14 23:23:31
|
Hi Peter, On 14 May 2012 20:49, Peter Bigot <bi...@ac...> wrote: > I'm not sure. As you saw, http://www.w3.org/TR/xmlschema-2/#dateTime > is pretty clear that anything that had a timezone is to be treated as > UTC. If the original lexical space didn't have a timezone, I think I > set it up to be given the local timezone; it might be argued that that > is a mistake, but it might also have been necessary for consistency. > > If you would file this as a trac request I'll see what I can do. > Please make it clear whether you just want xsd.dateTime.now() to be > symmetrical or whether you need values that lack a timezone to do > something other than what they do now. I'll create some more test cases in both PyXB and JAXB and get back to you. I think the assumption that a dateTime without a timezone is in local time is a good one, and I believe it will break JAXB compatibility if that were changed (but I'll test this). The one that concerns me at the moment is when there *is* a timezone - if you print a pyxb.binding.datatypes.dateTime, or save one of them to a TIMESTAMP field in the database (which PostgreSQL silently defaults to "WITHOUT TIMEZONE"), you'll end up with timestamps being printed and stored to the database in GMT. But like I say, I need to do some more test cases to figure out what I think the right way to handle it is. Regards, Nathan. |
From: Peter B. <bi...@ac...> - 2012-05-14 10:52:58
|
On Mon, May 14, 2012 at 12:28 AM, Nathan Robertson <na...@na...> wrote: > Hi Peter, > > In Trac ticket #102 (http://sourceforge.net/apps/trac/pyxb/ticket/102) > you mentioned that the trunk now supports the optional timezone part > of an xsd:date field, and that we should ask for a new release if we > need it. We've hit another bug in our system where under certain > circumstances we're getting dates stored in the database that are off > by 10 hours (our GMT offset). > > Is there any chance you could do a 1.1.4 release so that we can have > the fix to ticket #102? There's always a chance.... I'd wanted to get the packaging issue #130 cleared up before the next release, but that might take a few days effort. Also I've got two contract jobs due in about a month, and I'm afraid income-producers have to take priority over PyXB. What time frame are you looking at for a release? (You can always just grab the next branch off git if you just want a functional system, and aren't depending on a specific version as the basis for whatever you're doing.) Peter > Regards, > Nathan. > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > pyxb-users mailing list > pyx...@li... > https://lists.sourceforge.net/lists/listinfo/pyxb-users |
From: Peter B. <bi...@ac...> - 2012-05-14 10:49:39
|
On Mon, May 14, 2012 at 2:30 AM, Nathan Robertson <na...@na...> wrote: > Hi, > > One of my developers tripped across another weirdness around timezones today: > > A test snippet looks like this: > > --- > import pyxb_generated > > """ > $ pyxbgen --schema-root=. -u schema.xsd -m pyxb_generated > > <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" > targetNamespace="http://test.com/test" > xmlns:zenkai="http://test.com/test"> > <xsd:element name="timestamp" type="xsd:dateTime"/> > </xsd:schema> > """ > > xml = '<?xml version="1.0" ?><ns1:timestamp > xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157+10:00</ns1:timestamp>' > obj = pyxb_generated.CreateFromDocument(xml) > print "{} --> {} --> {}".format(xml, obj, obj.toxml()) > --- > > (the original string in the variable "xml" was a timestamp generated > by JAXB, which we interface with PyXB in some of our apps) > > The output looks like: > (pyenv-zktraining)nathanr@gionta:~/work/junkcode/pyxb-datetime-test> > python test2.py > <?xml version="1.0" ?><ns1:timestamp > xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157+10:00</ns1:timestamp> > --> 2012-05-14 06:36:02.157000 --> <?xml version="1.0" > ?><ns1:timestamp > xmlns:ns1="http://test.com/test">2012-05-14T06:36:02.157Z</ns1:timestamp> > (pyenv-zktraining)nathanr@gionta:~/work/junkcode/pyxb-datetime-test> > > The two XML fragments printed out look fine - the XML spec says that > they're equivalent, and they are. However, printing out the python > object prints the UTC time, not the local time (which is what I would > have expected, given that is the behaviour of datetime.datetime.now() > and friends in the base library). Reading through the PyXB source code > (pyxb.binding.datatypes.dateTime.__new__()), it looks like it's > intentional, and not a bug. > > Now, of course this means that if we save a PyXB unmarshalled object > to a database table using an ORM layer it stores the time as 10 hours > off (PostgreSQL defaults the type TIMESTAMP to "TIMESTAMP WITHOUT > TIMEZONE", and we've got over 100 legacy tables with that datatype all > the way through them). Is there a way to make > pyxb.binding.datatypes.dateTime objects be symmetrical to > datetime.datetime.now() in terms of the way we deal with them? I'm not sure. As you saw, http://www.w3.org/TR/xmlschema-2/#dateTime is pretty clear that anything that had a timezone is to be treated as UTC. If the original lexical space didn't have a timezone, I think I set it up to be given the local timezone; it might be argued that that is a mistake, but it might also have been necessary for consistency. If you would file this as a trac request I'll see what I can do. Please make it clear whether you just want xsd.dateTime.now() to be symmetrical or whether you need values that lack a timezone to do something other than what they do now. Peter > > Regards, > Nathan. > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > pyxb-users mailing list > pyx...@li... > https://lists.sourceforge.net/lists/listinfo/pyxb-users |
From: Nathan R. <na...@na...> - 2012-05-14 07:30:23
|
Hi, One of my developers tripped across another weirdness around timezones today: A test snippet looks like this: --- import pyxb_generated """ $ pyxbgen --schema-root=. -u schema.xsd -m pyxb_generated <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://test.com/test" xmlns:zenkai="http://test.com/test"> <xsd:element name="timestamp" type="xsd:dateTime"/> </xsd:schema> """ xml = '<?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157+10:00</ns1:timestamp>' obj = pyxb_generated.CreateFromDocument(xml) print "{} --> {} --> {}".format(xml, obj, obj.toxml()) --- (the original string in the variable "xml" was a timestamp generated by JAXB, which we interface with PyXB in some of our apps) The output looks like: (pyenv-zktraining)nathanr@gionta:~/work/junkcode/pyxb-datetime-test> python test2.py <?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T16:36:02.157+10:00</ns1:timestamp> --> 2012-05-14 06:36:02.157000 --> <?xml version="1.0" ?><ns1:timestamp xmlns:ns1="http://test.com/test">2012-05-14T06:36:02.157Z</ns1:timestamp> (pyenv-zktraining)nathanr@gionta:~/work/junkcode/pyxb-datetime-test> The two XML fragments printed out look fine - the XML spec says that they're equivalent, and they are. However, printing out the python object prints the UTC time, not the local time (which is what I would have expected, given that is the behaviour of datetime.datetime.now() and friends in the base library). Reading through the PyXB source code (pyxb.binding.datatypes.dateTime.__new__()), it looks like it's intentional, and not a bug. Now, of course this means that if we save a PyXB unmarshalled object to a database table using an ORM layer it stores the time as 10 hours off (PostgreSQL defaults the type TIMESTAMP to "TIMESTAMP WITHOUT TIMEZONE", and we've got over 100 legacy tables with that datatype all the way through them). Is there a way to make pyxb.binding.datatypes.dateTime objects be symmetrical to datetime.datetime.now() in terms of the way we deal with them? Regards, Nathan. |
From: Nathan R. <na...@na...> - 2012-05-14 05:54:20
|
Hi Peter, In Trac ticket #102 (http://sourceforge.net/apps/trac/pyxb/ticket/102) you mentioned that the trunk now supports the optional timezone part of an xsd:date field, and that we should ask for a new release if we need it. We've hit another bug in our system where under certain circumstances we're getting dates stored in the database that are off by 10 hours (our GMT offset). Is there any chance you could do a 1.1.4 release so that we can have the fix to ticket #102? Regards, Nathan. |
From: Peter B. <bi...@ac...> - 2012-05-04 00:22:24
|
On Thu, May 3, 2012 at 6:10 PM, Karl Putland <ka...@si...> wrote: > > The problem is with MTOM is that the element has a placeholder that points to the mime attachment. So the element doesn't contain valid data when looking at is as just xml. Interesting. Based on a quick scan of http://www.w3.org/TR/soap12-mtom/ I would expect there's some way to do this, but I'd have to see some real examples to figure out how. There seem to be several ways the data can be encapsulated. Peter > > The web service that I have to use was built with jax-ws and I was trying to avoid the java brain damage. > > --Karl > > Karl Putland > Senior VoIP Engineer > > SimpleSignal > 3600 S Yosemite, Suite 150 > Denver, CO 80237 > One Number Rings All My Phones: 303-242-8608 > > SimpleSignal.com | Blog | Facebook | Twitter > > > > On Thu, May 3, 2012 at 3:14 PM, Peter Bigot <bi...@ac...> wrote: >> >> I've not had the opportunity to do anything with web services for >> about two years, so I'm pretty rusty on it. I also haven't heard of >> suds in this context, and google for "suds+soap" is remarkably >> unhelpful. >> >> I would expect that if a SOAP call or response has attachments, >> they're either in the XML document (which isn't really attachments) so >> PyXB would handle them, or they're MIME sections in the HTML body in >> which case you'd pull them out either from the URL interface or by >> processing the response document at the HTML level. I would think >> having to reprocess them into an element would be wrong. >> >> Peter >> >> On Thu, May 3, 2012 at 12:27 PM, Karl Putland <ka...@si...> wrote: >> > >> > >> > There's some information regarding using PyXB for communicating with web services. >> > I'd tried using suds, which works... with the exception of some calls which return SOAP with Attachments. >> > Can pyxb handle the soap with attachments or does it need to be reprocessed into then element before parsing? >> > >> > >> > >> > --Karl >> > >> > Karl Putland >> > Senior VoIP Engineer >> > >> > SimpleSignal >> > 3600 S Yosemite, Suite 150 >> > Denver, CO 80237 >> > One Number Rings All My Phones: 303-242-8608 >> > >> > SimpleSignal.com | Blog | Facebook | Twitter >> > >> > >> > ------------------------------------------------------------------------------ >> > Live Security Virtual Conference >> > Exclusive live event will cover all the ways today's security and >> > threat landscape has changed and how IT managers can respond. Discussions >> > will include endpoint security, mobile security and the latest in malware >> > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ >> > _______________________________________________ >> > pyxb-users mailing list >> > pyx...@li... >> > https://lists.sourceforge.net/lists/listinfo/pyxb-users >> > > > |
From: Karl P. <ka...@si...> - 2012-05-03 23:19:10
|
The problem is with MTOM is that the element has a placeholder that points to the mime attachment. So the element doesn't contain valid data when looking at is as just xml. The web service that I have to use was built with jax-ws and I was trying to avoid the java brain damage. --Karl Karl Putland Senior VoIP Engineer *SimpleSignal* 3600 S Yosemite, Suite 150 Denver, CO 80237 One Number Rings All My Phones: 303-242-8608 SimpleSignal.com <http://www.simplesignal.com/> | Blog<http://www.simplesignal.com/blog> | Facebook <http://www.facebook.com/SimpleSignal?ref=ts> | Twitter<http://twitter.com/simplesignal> On Thu, May 3, 2012 at 3:14 PM, Peter Bigot <bi...@ac...> wrote: > I've not had the opportunity to do anything with web services for > about two years, so I'm pretty rusty on it. I also haven't heard of > suds in this context, and google for "suds+soap" is remarkably > unhelpful. > > I would expect that if a SOAP call or response has attachments, > they're either in the XML document (which isn't really attachments) so > PyXB would handle them, or they're MIME sections in the HTML body in > which case you'd pull them out either from the URL interface or by > processing the response document at the HTML level. I would think > having to reprocess them into an element would be wrong. > > Peter > > On Thu, May 3, 2012 at 12:27 PM, Karl Putland <ka...@si...> > wrote: > > > > > > There's some information regarding using PyXB for communicating with web > services. > > I'd tried using suds, which works... with the exception of some calls > which return SOAP with Attachments. > > Can pyxb handle the soap with attachments or does it need to be > reprocessed into then element before parsing? > > > > > > > > --Karl > > > > Karl Putland > > Senior VoIP Engineer > > > > SimpleSignal > > 3600 S Yosemite, Suite 150 > > Denver, CO 80237 > > One Number Rings All My Phones: 303-242-8608 > > > > SimpleSignal.com | Blog | Facebook | Twitter > > > > > > > ------------------------------------------------------------------------------ > > Live Security Virtual Conference > > Exclusive live event will cover all the ways today's security and > > threat landscape has changed and how IT managers can respond. Discussions > > will include endpoint security, mobile security and the latest in malware > > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > > _______________________________________________ > > pyxb-users mailing list > > pyx...@li... > > https://lists.sourceforge.net/lists/listinfo/pyxb-users > > > |
From: Peter B. <bi...@ac...> - 2012-05-03 21:15:06
|
I've not had the opportunity to do anything with web services for about two years, so I'm pretty rusty on it. I also haven't heard of suds in this context, and google for "suds+soap" is remarkably unhelpful. I would expect that if a SOAP call or response has attachments, they're either in the XML document (which isn't really attachments) so PyXB would handle them, or they're MIME sections in the HTML body in which case you'd pull them out either from the URL interface or by processing the response document at the HTML level. I would think having to reprocess them into an element would be wrong. Peter On Thu, May 3, 2012 at 12:27 PM, Karl Putland <ka...@si...> wrote: > > > There's some information regarding using PyXB for communicating with web services. > I'd tried using suds, which works... with the exception of some calls which return SOAP with Attachments. > Can pyxb handle the soap with attachments or does it need to be reprocessed into then element before parsing? > > > > --Karl > > Karl Putland > Senior VoIP Engineer > > SimpleSignal > 3600 S Yosemite, Suite 150 > Denver, CO 80237 > One Number Rings All My Phones: 303-242-8608 > > SimpleSignal.com | Blog | Facebook | Twitter > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > pyxb-users mailing list > pyx...@li... > https://lists.sourceforge.net/lists/listinfo/pyxb-users > |
From: Karl P. <ka...@si...> - 2012-05-03 20:28:34
|
There's some information regarding using PyXB for communicating with web services. I'd tried using suds, which works... with the exception of some calls which return SOAP with Attachments. Can pyxb handle the soap with attachments or does it need to be reprocessed into then element before parsing? --Karl Karl Putland Senior VoIP Engineer *SimpleSignal* 3600 S Yosemite, Suite 150 Denver, CO 80237 One Number Rings All My Phones: 303-242-8608 SimpleSignal.com <http://www.simplesignal.com/> | Blog<http://www.simplesignal.com/blog> | Facebook <http://www.facebook.com/SimpleSignal?ref=ts> | Twitter<http://twitter.com/simplesignal> |
From: Peter B. <bi...@ac...> - 2012-05-01 12:40:04
|
Without inspecting in detail, this is probably: https://sourceforge.net/apps/trac/pyxb/ticket/112 At this time there is no fix. I may have an opportunity to dig into this in a month or so. You could assist by providing the modified files you mention, so when it does get worked I can verify this is the issue. Best approach would be to open a new ticket on the trac site and attach them to it. Thanks. Peter On Tue, May 1, 2012 at 7:36 AM, Bill Riegel <Wil...@ha...> wrote: > > > Poc.xsd is the modified xsd > > Poc.xml is the example xml file > > > > When I run pocsample.py > > > > I see: > > > > pydev debugger: starting > > Traceback (most recent call last): > > File > "C:\downloads\eclipse_indigo_3_7\eclipse\plugins\org.python.pydev.debug_2.4.0.2012020116\pysrc\pydevd.py", > line 1307, in <module> > > debugger.run(setup['file'], None, None) > > File > "C:\downloads\eclipse_indigo_3_7\eclipse\plugins\org.python.pydev.debug_2.4.0.2012020116\pysrc\pydevd.py", > line 1060, in run > > pydev_imports.execfile(file, globals, locals) #execute the script > > File "C:\Users\hbl4152\workspace\python1\src\pocSample.py", line 6, in > <module> > > pobObject = poc.CreateFromDocument(xml, location_base='poc.xml') > > File "C:\Users\hbl4152\workspace\python1\src\poc.py", line 32, in > CreateFromDocument > > saxer.parse(StringIO.StringIO(xml_text)) > > File "C:\Python27\lib\xml\sax\expatreader.py", line 107, in parse > > xmlreader.IncrementalParser.parse(self, source) > > File "C:\Python27\lib\xml\sax\xmlreader.py", line 123, in parse > > self.feed(buffer) > > File "C:\Python27\lib\xml\sax\expatreader.py", line 207, in feed > > self._parser.Parse(data, isFinal) > > File "C:\Python27\lib\xml\sax\expatreader.py", line 349, in end_element_ns > > self._cont_handler.endElementNS(pair, None) > > File "C:\Python27\lib\site-packages\pyxb\binding\saxer.py", line 374, in > endElementNS > > binding_object = this_state.endBindingElement() > > File "C:\Python27\lib\site-packages\pyxb\binding\saxer.py", line 232, in > endBindingElement > > self.__bindingInstance.validateBinding() > > File "C:\Python27\lib\site-packages\pyxb\binding\basis.py", line 422, in > validateBinding > > self._validateBinding_vx() > > File "C:\Python27\lib\site-packages\pyxb\binding\basis.py", line 1836, in > _validateBinding_vx > > raise pyxb.BindingValidationError('Error matching content to binding > model: %s' % (e,)) > > pyxb.exceptions_.BindingValidationError: Error matching content to binding > model: Ungenerated symbols: {<pyxb.binding.content.ElementUse object at > 0x02D54E10>: [u'Want this for the holidays!']} > > > > this is due ( In my opinion, to the choice entry for Items, it allows > USPrice or comment ) > > <xsd:choice> > <xsd:element name="USPrice" type="xsd:decimal" > minOccurs="0"/> > <xsd:element ref="po:comment" minOccurs="0"/> > </xsd:choice> > > > > My example poc.xml has a USPrice for one Item but comment for the other > Item. > > > > Assistance would be appreciated. > > > > Bill Riegel > > Landmark Graphics Corp. > > 713-839-3388 > > > > ________________________________ > This e-mail, including any attached files, may contain confidential and > privileged information for the sole use of the intended recipient. Any > review, use, distribution, or disclosure by others is strictly prohibited. > If you are not the intended recipient (or authorized to receive information > for the intended recipient), please contact the sender by reply e-mail and > delete all copies of this message. > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > pyxb-users mailing list > pyx...@li... > https://lists.sourceforge.net/lists/listinfo/pyxb-users > |
From: Bill R. <Wil...@ha...> - 2012-05-01 12:36:15
|
Poc.xsd is the modified xsd Poc.xml is the example xml file When I run pocsample.py I see: pydev debugger: starting Traceback (most recent call last): File "C:\downloads\eclipse_indigo_3_7\eclipse\plugins\org.python.pydev.debug_2.4.0.2012020116\pysrc\pydevd.py", line 1307, in <module> debugger.run(setup['file'], None, None) File "C:\downloads\eclipse_indigo_3_7\eclipse\plugins\org.python.pydev.debug_2.4.0.2012020116\pysrc\pydevd.py", line 1060, in run pydev_imports.execfile(file, globals, locals) #execute the script File "C:\Users\hbl4152\workspace\python1\src\pocSample.py", line 6, in <module> pobObject = poc.CreateFromDocument(xml, location_base='poc.xml') File "C:\Users\hbl4152\workspace\python1\src\poc.py", line 32, in CreateFromDocument saxer.parse(StringIO.StringIO(xml_text)) File "C:\Python27\lib\xml\sax\expatreader.py", line 107, in parse xmlreader.IncrementalParser.parse(self, source) File "C:\Python27\lib\xml\sax\xmlreader.py", line 123, in parse self.feed(buffer) File "C:\Python27\lib\xml\sax\expatreader.py", line 207, in feed self._parser.Parse(data, isFinal) File "C:\Python27\lib\xml\sax\expatreader.py", line 349, in end_element_ns self._cont_handler.endElementNS(pair, None) File "C:\Python27\lib\site-packages\pyxb\binding\saxer.py", line 374, in endElementNS binding_object = this_state.endBindingElement() File "C:\Python27\lib\site-packages\pyxb\binding\saxer.py", line 232, in endBindingElement self.__bindingInstance.validateBinding() File "C:\Python27\lib\site-packages\pyxb\binding\basis.py", line 422, in validateBinding self._validateBinding_vx() File "C:\Python27\lib\site-packages\pyxb\binding\basis.py", line 1836, in _validateBinding_vx raise pyxb.BindingValidationError('Error matching content to binding model: %s' % (e,)) pyxb.exceptions_.BindingValidationError: Error matching content to binding model: Ungenerated symbols: {<pyxb.binding.content.ElementUse object at 0x02D54E10>: [u'Want this for the holidays!']} this is due ( In my opinion, to the choice entry for Items, it allows USPrice or comment ) <xsd:choice> <xsd:element name="USPrice" type="xsd:decimal" minOccurs="0"/> <xsd:element ref="po:comment" minOccurs="0"/> </xsd:choice> My example poc.xml has a USPrice for one Item but comment for the other Item. Assistance would be appreciated. Bill Riegel Landmark Graphics Corp. 713-839-3388 ---------------------------------------------------------------------- This e-mail, including any attached files, may contain confidential and privileged information for the sole use of the intended recipient. Any review, use, distribution, or disclosure by others is strictly prohibited. If you are not the intended recipient (or authorized to receive information for the intended recipient), please contact the sender by reply e-mail and delete all copies of this message. |
From: N. M. P. <nma...@gm...> - 2012-04-08 16:59:21
|
Hi Peter, Once again, huge thanks for the response! Your comments made it "click" as to how the bindings work. As you guessed, I do (or should try at least) need to generate all bindings at once. All of the "other.xsd" files imports netconf plus one other xsd. I noticed the "_nf.py" module being created as I generated modules from the other tertiary sources so to speak. After working with the examples from the source, Python is starting to make more sense which in turn helps me understand PyXB the more I am using it. (Coming from Perl and PHP :) Python seems so literal and quite eloquent ... I'm really starting to like it. The PyXB module rocks!! Thanks again for the nudge in the right direction :) Max On Sat, Apr 7, 2012 at 7:01 AM, Peter Bigot <bi...@ac...> wrote: > On Fri, Apr 6, 2012 at 10:34 PM, N. Max Pierson <nma...@gm...> > wrote: > > Hi Peter, > > > > Thanks for the reply. > > > > First, I should say that I'm rather new to python and PyXB, so please be > > patient with my ignorance :) > > > > I was guessing that it wouldn't work because there's no element's > specified > > in that specific document?? > > No, that'd be ok. It defines attributes, so it's not useless. > > > I need to make use of the "xml:lang" attribute in a document that's > > surrounded in a netconf project that I am working on. The netconf.xsd > file I > > have imports the xml.xsd file. Then the other xsd files I have imports > the > > netconf.xsd file. I am not having any issues with the netconf.xsd (and a > few > > of the other xsd files I was supplied so far). > > OK. Yes, a binding for netconf.xsd can be created without doing > anything special. Although it imports the XML namespace, that gets > resolved into a reference to Python's built-in namespace for xml:lang. > See > http://pyxb.sourceforge.net/api/pyxb.namespace.builtin._XML-class.html > > > So I guess as far as validation is concerned, if the xml.xsd is imported > for > > use of the xml:lang attribute, it will still validate even though I do > not > > have a binding for it?? > > You should have a binding for it. If you look at the generated > binding for netconf, you'll see an anonymous complex type that > references the built-in definition of xml:lang. > > > I'm still reading up on the documentation for the PyXB module, so my > > understanding of still minimal of what all "bindings" are needed to > validate > > against the xsd files I have and how the bindings are used in building > the > > modules created by PxYB. > > PyXB should complain if it needs to get information from an imported > namespace and doesn't already have the necessary binding information > (which it can find from builtin namespaces, namespaces for which it > can locate a pre-generated archive, and namespaces for which it can > find schemas by retrieving a URI from a schemaLocation). Only then do > you need to manually generate bindings for those namespaces. See > http://pyxb.sourceforge.net/userref_pyxbgen.html#sharing-namespace-bindings > and other material in that area of the documentation. > > Depending on how the schema for the overall project are constructed, > you may want to do: > > pyxbgen -u netconf.xsd -m netconf --archive-to-file netconf.wxs > > then: > > pyxbgen -u other.xsd -m other --archive-path .:+ > > if the "other.xsd" schema references netconf. Do the same thing for > other namespaces that are imported into multiple schemas. The > alternative is to generate bindings for all the schemas at once, as > with > http://pyxb.sourceforge.net/userref_pyxbgen.html#generating-related-namespaces > . > > Peter > > > > > Regards, > > Max > > > > > > On Fri, Apr 6, 2012 at 5:43 PM, Peter Bigot <bi...@ac...> wrote: > >> > >> Sorry for the delay; somehow this got tagged as spam. > >> > >> http://www.w3.org/XML/1998/namespace is a built-in namespace, and > >> can't be generated from a schema. pyxb doesn't have a binding for it, > >> but does recognize and process elements/attributes in that namespace > >> in both schema and documents. > >> > >> Maybe I missed a use-case: what are you trying to do that you need a > >> binding for it? > >> > >> Peter > >> > >> On Wed, Apr 4, 2012 at 10:21 PM, N. Max Pierson <nma...@gm...> > >> wrote: > >> > Hi, > >> > > >> > I'm getting a warning from pyxbgen when trying to generate a module > for > >> > XML > >> > Namespace located here http://www.w3.org/XML/1998/namespace > >> > > >> > The source xsd can be found here http://www.pyxlmap.com/xml.xsd and > the > >> > warning messages are as follows ... > >> > > >> > **!!**!! Not destroying builtin > >> > {http://www.w3.org/XML/1998/namespace}lang: > >> > STD[<anonymous>:restriction of anySimpleType > >> > pattern="",enumeration=""] > >> > Replacing unresolved AD[{http://www.w3.org/XML/1998/namespace}lang:?] > >> > **!!**!! Not destroying builtin > >> > {http://www.w3.org/XML/1998/namespace}base: > >> > STD[anyURI:restriction of anySimpleType > >> > > >> > > >> > > pattern="",minLength="None",length="None",maxLength="None",whiteSpace="collapse",enumeration=""] > >> > Replacing unresolved AD[{http://www.w3.org/XML/1998/namespace}base:?] > >> > **!!**!! Not destroying builtin > >> > {http://www.w3.org/XML/1998/namespace}id: > >> > STD[ID:restriction of NCName] > >> > Replacing unresolved AD[{http://www.w3.org/XML/1998/namespace}id:?] > >> > Replacing unresolved > >> > AGD[{http://www.w3.org/XML/1998/namespace}specialAttrs] > >> > Python for xml=http://www.w3.org/XML/1998/namespace requires 1 > modules > >> > WARNING: No binding file for > >> > NM:xml=http://www.w3.org/XML/1998/namespace@base > >> > > >> > And the module does not get built. Any ideas? > >> > > >> > Regards, > >> > Max > >> > > >> > > >> > > ------------------------------------------------------------------------------ > >> > Better than sec? Nothing is better than sec when it comes to > >> > monitoring Big Data applications. Try Boundary one-second > >> > resolution app monitoring today. Free. > >> > http://p.sf.net/sfu/Boundary-dev2dev > >> > _______________________________________________ > >> > pyxb-users mailing list > >> > pyx...@li... > >> > https://lists.sourceforge.net/lists/listinfo/pyxb-users > >> > > > > > > |
From: Peter B. <bi...@ac...> - 2012-04-07 12:01:54
|
On Fri, Apr 6, 2012 at 10:34 PM, N. Max Pierson <nma...@gm...> wrote: > Hi Peter, > > Thanks for the reply. > > First, I should say that I'm rather new to python and PyXB, so please be > patient with my ignorance :) > > I was guessing that it wouldn't work because there's no element's specified > in that specific document?? No, that'd be ok. It defines attributes, so it's not useless. > I need to make use of the "xml:lang" attribute in a document that's > surrounded in a netconf project that I am working on. The netconf.xsd file I > have imports the xml.xsd file. Then the other xsd files I have imports the > netconf.xsd file. I am not having any issues with the netconf.xsd (and a few > of the other xsd files I was supplied so far). OK. Yes, a binding for netconf.xsd can be created without doing anything special. Although it imports the XML namespace, that gets resolved into a reference to Python's built-in namespace for xml:lang. See http://pyxb.sourceforge.net/api/pyxb.namespace.builtin._XML-class.html > So I guess as far as validation is concerned, if the xml.xsd is imported for > use of the xml:lang attribute, it will still validate even though I do not > have a binding for it?? You should have a binding for it. If you look at the generated binding for netconf, you'll see an anonymous complex type that references the built-in definition of xml:lang. > I'm still reading up on the documentation for the PyXB module, so my > understanding of still minimal of what all "bindings" are needed to validate > against the xsd files I have and how the bindings are used in building the > modules created by PxYB. PyXB should complain if it needs to get information from an imported namespace and doesn't already have the necessary binding information (which it can find from builtin namespaces, namespaces for which it can locate a pre-generated archive, and namespaces for which it can find schemas by retrieving a URI from a schemaLocation). Only then do you need to manually generate bindings for those namespaces. See http://pyxb.sourceforge.net/userref_pyxbgen.html#sharing-namespace-bindings and other material in that area of the documentation. Depending on how the schema for the overall project are constructed, you may want to do: pyxbgen -u netconf.xsd -m netconf --archive-to-file netconf.wxs then: pyxbgen -u other.xsd -m other --archive-path .:+ if the "other.xsd" schema references netconf. Do the same thing for other namespaces that are imported into multiple schemas. The alternative is to generate bindings for all the schemas at once, as with http://pyxb.sourceforge.net/userref_pyxbgen.html#generating-related-namespaces. Peter > > Regards, > Max > > > On Fri, Apr 6, 2012 at 5:43 PM, Peter Bigot <bi...@ac...> wrote: >> >> Sorry for the delay; somehow this got tagged as spam. >> >> http://www.w3.org/XML/1998/namespace is a built-in namespace, and >> can't be generated from a schema. pyxb doesn't have a binding for it, >> but does recognize and process elements/attributes in that namespace >> in both schema and documents. >> >> Maybe I missed a use-case: what are you trying to do that you need a >> binding for it? >> >> Peter >> >> On Wed, Apr 4, 2012 at 10:21 PM, N. Max Pierson <nma...@gm...> >> wrote: >> > Hi, >> > >> > I'm getting a warning from pyxbgen when trying to generate a module for >> > XML >> > Namespace located here http://www.w3.org/XML/1998/namespace >> > >> > The source xsd can be found here http://www.pyxlmap.com/xml.xsd and the >> > warning messages are as follows ... >> > >> > **!!**!! Not destroying builtin >> > {http://www.w3.org/XML/1998/namespace}lang: >> > STD[<anonymous>:restriction of anySimpleType >> > pattern="",enumeration=""] >> > Replacing unresolved AD[{http://www.w3.org/XML/1998/namespace}lang:?] >> > **!!**!! Not destroying builtin >> > {http://www.w3.org/XML/1998/namespace}base: >> > STD[anyURI:restriction of anySimpleType >> > >> > >> > pattern="",minLength="None",length="None",maxLength="None",whiteSpace="collapse",enumeration=""] >> > Replacing unresolved AD[{http://www.w3.org/XML/1998/namespace}base:?] >> > **!!**!! Not destroying builtin >> > {http://www.w3.org/XML/1998/namespace}id: >> > STD[ID:restriction of NCName] >> > Replacing unresolved AD[{http://www.w3.org/XML/1998/namespace}id:?] >> > Replacing unresolved >> > AGD[{http://www.w3.org/XML/1998/namespace}specialAttrs] >> > Python for xml=http://www.w3.org/XML/1998/namespace requires 1 modules >> > WARNING: No binding file for >> > NM:xml=http://www.w3.org/XML/1998/namespace@base >> > >> > And the module does not get built. Any ideas? >> > >> > Regards, >> > Max >> > >> > >> > ------------------------------------------------------------------------------ >> > Better than sec? Nothing is better than sec when it comes to >> > monitoring Big Data applications. Try Boundary one-second >> > resolution app monitoring today. Free. >> > http://p.sf.net/sfu/Boundary-dev2dev >> > _______________________________________________ >> > pyxb-users mailing list >> > pyx...@li... >> > https://lists.sourceforge.net/lists/listinfo/pyxb-users >> > > > |
From: N. M. P. <nma...@gm...> - 2012-04-07 03:34:46
|
Hi Peter, Thanks for the reply. First, I should say that I'm rather new to python and PyXB, so please be patient with my ignorance :) I was guessing that it wouldn't work because there's no element's specified in that specific document?? I need to make use of the "xml:lang" attribute in a document that's surrounded in a netconf project that I am working on. The netconf.xsd file I have imports the xml.xsd file. Then the other xsd files I have imports the netconf.xsd file. I am not having any issues with the netconf.xsd (and a few of the other xsd files I was supplied so far). So I guess as far as validation is concerned, if the xml.xsd is imported for use of the xml:lang attribute, it will still validate even though I do not have a binding for it?? I'm still reading up on the documentation for the PyXB module, so my understanding of still minimal of what all "bindings" are needed to validate against the xsd files I have and how the bindings are used in building the modules created by PxYB. Regards, Max On Fri, Apr 6, 2012 at 5:43 PM, Peter Bigot <bi...@ac...> wrote: > Sorry for the delay; somehow this got tagged as spam. > > http://www.w3.org/XML/1998/namespace is a built-in namespace, and > can't be generated from a schema. pyxb doesn't have a binding for it, > but does recognize and process elements/attributes in that namespace > in both schema and documents. > > Maybe I missed a use-case: what are you trying to do that you need a > binding for it? > > Peter > > On Wed, Apr 4, 2012 at 10:21 PM, N. Max Pierson <nma...@gm...> > wrote: > > Hi, > > > > I'm getting a warning from pyxbgen when trying to generate a module for > XML > > Namespace located here http://www.w3.org/XML/1998/namespace > > > > The source xsd can be found here http://www.pyxlmap.com/xml.xsd and the > > warning messages are as follows ... > > > > **!!**!! Not destroying builtin { > http://www.w3.org/XML/1998/namespace}lang: > > STD[<anonymous>:restriction of anySimpleType > > pattern="",enumeration=""] > > Replacing unresolved AD[{http://www.w3.org/XML/1998/namespace}lang:?] > > **!!**!! Not destroying builtin { > http://www.w3.org/XML/1998/namespace}base: > > STD[anyURI:restriction of anySimpleType > > > > > pattern="",minLength="None",length="None",maxLength="None",whiteSpace="collapse",enumeration=""] > > Replacing unresolved AD[{http://www.w3.org/XML/1998/namespace}base:?] > > **!!**!! Not destroying builtin {http://www.w3.org/XML/1998/namespace}id > : > > STD[ID:restriction of NCName] > > Replacing unresolved AD[{http://www.w3.org/XML/1998/namespace}id:?] > > Replacing unresolved AGD[{ > http://www.w3.org/XML/1998/namespace}specialAttrs] > > Python for xml=http://www.w3.org/XML/1998/namespace requires 1 modules > > WARNING: No binding file for > > NM:xml=http://www.w3.org/XML/1998/namespace@base > > > > And the module does not get built. Any ideas? > > > > Regards, > > Max > > > > > ------------------------------------------------------------------------------ > > Better than sec? Nothing is better than sec when it comes to > > monitoring Big Data applications. Try Boundary one-second > > resolution app monitoring today. Free. > > http://p.sf.net/sfu/Boundary-dev2dev > > _______________________________________________ > > pyxb-users mailing list > > pyx...@li... > > https://lists.sourceforge.net/lists/listinfo/pyxb-users > > > |
From: Peter B. <bi...@ac...> - 2012-04-06 22:43:49
|
Sorry for the delay; somehow this got tagged as spam. http://www.w3.org/XML/1998/namespace is a built-in namespace, and can't be generated from a schema. pyxb doesn't have a binding for it, but does recognize and process elements/attributes in that namespace in both schema and documents. Maybe I missed a use-case: what are you trying to do that you need a binding for it? Peter On Wed, Apr 4, 2012 at 10:21 PM, N. Max Pierson <nma...@gm...> wrote: > Hi, > > I'm getting a warning from pyxbgen when trying to generate a module for XML > Namespace located here http://www.w3.org/XML/1998/namespace > > The source xsd can be found here http://www.pyxlmap.com/xml.xsd and the > warning messages are as follows ... > > **!!**!! Not destroying builtin {http://www.w3.org/XML/1998/namespace}lang: > STD[<anonymous>:restriction of anySimpleType > pattern="",enumeration=""] > Replacing unresolved AD[{http://www.w3.org/XML/1998/namespace}lang:?] > **!!**!! Not destroying builtin {http://www.w3.org/XML/1998/namespace}base: > STD[anyURI:restriction of anySimpleType > > pattern="",minLength="None",length="None",maxLength="None",whiteSpace="collapse",enumeration=""] > Replacing unresolved AD[{http://www.w3.org/XML/1998/namespace}base:?] > **!!**!! Not destroying builtin {http://www.w3.org/XML/1998/namespace}id: > STD[ID:restriction of NCName] > Replacing unresolved AD[{http://www.w3.org/XML/1998/namespace}id:?] > Replacing unresolved AGD[{http://www.w3.org/XML/1998/namespace}specialAttrs] > Python for xml=http://www.w3.org/XML/1998/namespace requires 1 modules > WARNING: No binding file for > NM:xml=http://www.w3.org/XML/1998/namespace@base > > And the module does not get built. Any ideas? > > Regards, > Max > > ------------------------------------------------------------------------------ > Better than sec? Nothing is better than sec when it comes to > monitoring Big Data applications. Try Boundary one-second > resolution app monitoring today. Free. > http://p.sf.net/sfu/Boundary-dev2dev > _______________________________________________ > pyxb-users mailing list > pyx...@li... > https://lists.sourceforge.net/lists/listinfo/pyxb-users > |
From: N. M. P. <nma...@gm...> - 2012-04-05 03:21:44
|
Hi, I'm getting a warning from pyxbgen when trying to generate a module for XML Namespace located here http://www.w3.org/XML/1998/namespace The source xsd can be found here http://www.pyxlmap.com/xml.xsd and the warning messages are as follows ... **!!**!! Not destroying builtin {http://www.w3.org/XML/1998/namespace}lang: STD[<anonymous>:restriction of anySimpleType pattern="",enumeration=""] Replacing unresolved AD[{http://www.w3.org/XML/1998/namespace}lang:?] **!!**!! Not destroying builtin {http://www.w3.org/XML/1998/namespace}base: STD[anyURI:restriction of anySimpleType pattern="",minLength="None",length="None",maxLength="None",whiteSpace="collapse",enumeration=""] Replacing unresolved AD[{http://www.w3.org/XML/1998/namespace}base:?] **!!**!! Not destroying builtin {http://www.w3.org/XML/1998/namespace}id: STD[ID:restriction of NCName] Replacing unresolved AD[{http://www.w3.org/XML/1998/namespace}id:?] Replacing unresolved AGD[{http://www.w3.org/XML/1998/namespace}specialAttrs] Python for xml=http://www.w3.org/XML/1998/namespace requires 1 modules WARNING: No binding file for NM:xml= http://www.w3.org/XML/1998/namespace@base And the module does not get built. Any ideas? Regards, Max |
From: Dimster <dim...@ya...> - 2012-03-28 20:40:01
|
Thanks for the quick answer, I'll file a ticket later today. Best, Dim ________________________________ From: Peter Bigot <bi...@ac...> To: Dimster <dim...@ya...> Cc: "pyx...@li..." <pyx...@li...> Sent: Wednesday, 28 March 2012, 16:12 Subject: Re: [pyxb-users] Add text to mixed xml elements On Wed, Mar 28, 2012 at 1:51 PM, Dimster <dim...@ya...> wrote: > Hi, > > Is there a way to add text to an element of type MIXED? > > Consider: > > <xs:complexType name="IntervalValueType" mixed="true"> > <xs:sequence> > <xs:element name="MinValue" minOccurs="0" maxOccurs="1" > type="xs:string" /> > <xs:element name="MaxValue" minOccurs="0" maxOccurs="1" > type="xs:string" /> > </xs:sequence> > </xs:complexType> > > and the corresponding pyxb binding: > > # Complex type IntervalValueType with content type MIXED > class IntervalValueType (pyxb.binding.basis.complexTypeDefinition) > > Using the above class, how can I output > > <value>5</value>, where value is of IntervalValueType? > > I have tried all combinations of constructors and appends but I wasn't able > to achieve that - I always get > <value><MinValue>5</MinValue></value> PyXB's support for mixed content is pretty weak, mostly because there's no canonical representation (i.e., no way to reconstruct the proper order of elements and non-element content when converting back to XML in accordance with the content model). What's supposed to work is something like: x = ff.IntervalValue(MinValue="one") x.append("text", maybe_element=False) print x.content() print x.toxml() but although that puts "text" in as mixed content, it doesn't come out again. PyXB is supposed to spit out all the non-element content in a block after the element content, but in fact it doesn't (see pyxb.binding.basis.complexTypeDefinition._toDOM_csc where it walks over the mixed content doing nothing). Please file a ticket at https://sourceforge.net/apps/trac/pyxb/ and I'll look at this. Peter > Thanks, > Dim > > ------------------------------------------------------------------------------ > This SF email is sponsosred by: > Try Windows Azure free for 90 days Click Here > http://p.sf.net/sfu/sfd2d-msazure > _______________________________________________ > pyxb-users mailing list > pyx...@li... > https://lists.sourceforge.net/lists/listinfo/pyxb-users > |
From: Peter B. <bi...@ac...> - 2012-03-28 20:12:10
|
On Wed, Mar 28, 2012 at 1:51 PM, Dimster <dim...@ya...> wrote: > Hi, > > Is there a way to add text to an element of type MIXED? > > Consider: > > <xs:complexType name="IntervalValueType" mixed="true"> > <xs:sequence> > <xs:element name="MinValue" minOccurs="0" maxOccurs="1" > type="xs:string" /> > <xs:element name="MaxValue" minOccurs="0" maxOccurs="1" > type="xs:string" /> > </xs:sequence> > </xs:complexType> > > and the corresponding pyxb binding: > > # Complex type IntervalValueType with content type MIXED > class IntervalValueType (pyxb.binding.basis.complexTypeDefinition) > > Using the above class, how can I output > > <value>5</value>, where value is of IntervalValueType? > > I have tried all combinations of constructors and appends but I wasn't able > to achieve that - I always get > <value><MinValue>5</MinValue></value> PyXB's support for mixed content is pretty weak, mostly because there's no canonical representation (i.e., no way to reconstruct the proper order of elements and non-element content when converting back to XML in accordance with the content model). What's supposed to work is something like: x = ff.IntervalValue(MinValue="one") x.append("text", maybe_element=False) print x.content() print x.toxml() but although that puts "text" in as mixed content, it doesn't come out again. PyXB is supposed to spit out all the non-element content in a block after the element content, but in fact it doesn't (see pyxb.binding.basis.complexTypeDefinition._toDOM_csc where it walks over the mixed content doing nothing). Please file a ticket at https://sourceforge.net/apps/trac/pyxb/ and I'll look at this. Peter > Thanks, > Dim > > ------------------------------------------------------------------------------ > This SF email is sponsosred by: > Try Windows Azure free for 90 days Click Here > http://p.sf.net/sfu/sfd2d-msazure > _______________________________________________ > pyxb-users mailing list > pyx...@li... > https://lists.sourceforge.net/lists/listinfo/pyxb-users > |
From: Dimster <dim...@ya...> - 2012-03-28 18:51:19
|
Hi, Is there a way to add text to an element of type MIXED? Consider: <xs:complexType name="IntervalValueType" mixed="true"> <xs:sequence> <xs:element name="MinValue" minOccurs="0" maxOccurs="1" type="xs:string" /> <xs:element name="MaxValue" minOccurs="0" maxOccurs="1" type="xs:string" /> </xs:sequence> </xs:complexType> and the corresponding pyxb binding: # Complex type IntervalValueType with content type MIXED class IntervalValueType (pyxb.binding.basis.complexTypeDefinition) Using the above class, how can I output <value>5</value>, where value is of IntervalValueType? I have tried all combinations of constructors and appends but I wasn't able to achieve that - I always get <value><MinValue>5</MinValue></value> Thanks, Dim |
From: Peter B. <bi...@ac...> - 2012-03-17 21:14:41
|
On Sat, Mar 17, 2012 at 1:25 PM, Solbrig, Harold R. <Sol...@ma...> wrote: > Hello, > > Is this the correct forum to file bug reports? Questions and discussion are appropriate here, but if you have an actual bug or feature request, please enter a ticket at https://sourceforge.net/apps/trac/pyxb/ so it can be properly tracked. Peter > > Thanks! > > > ------------------------------------------------------------------------------ > This SF email is sponsosred by: > Try Windows Azure free for 90 days Click Here > http://p.sf.net/sfu/sfd2d-msazure > _______________________________________________ > pyxb-users mailing list > pyx...@li... > https://lists.sourceforge.net/lists/listinfo/pyxb-users > |
From: Solbrig, H. R. <Sol...@ma...> - 2012-03-17 18:59:41
|
Hello, Is this the correct forum to file bug reports? Thanks! |