1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 """Classes supporting U{XMLSchema Part 2: Datatypes<http://www.w3.org/TR/xmlschema-2/>}.
16
17 Each L{simple type definition<pyxb.xmlschema.structures.SimpleTypeDefinition>} component
18 instance is paired with at most one L{basis.simpleTypeDefinition}
19 class, which is a subclass of a Python type augmented with facets and
20 other constraining information. This file contains the definitions of
21 these types.
22
23 We want the simple datatypes to be efficient Python values, but to
24 also hold specific constraints that don't apply to the Python types.
25 To do this, we subclass each PST. Primitive PSTs inherit from the
26 Python type that represents them, and from a
27 pyxb.binding.basis.simpleTypeDefinition class which adds in the
28 constraint infrastructure. Derived PSTs inherit from the parent PST.
29
30 There is an exception to this when the Python type best suited for a
31 derived SimpleTypeDefinition differs from the type associated with its
32 parent STD: for example, L{xsd:integer<integer>} has a value range
33 that requires it be represented by a Python C{long}, but
34 L{xsd:int<int>} allows representation by a Python C{int}. In this
35 case, the derived PST class is structured like a primitive type, but
36 the PST associated with the STD superclass is recorded in a class
37 variable C{_XsdBaseType}.
38
39 Note the strict terminology: "datatype" refers to a class which is a
40 subclass of a Python type, while "type definition" refers to an
41 instance of either SimpleTypeDefinition or ComplexTypeDefinition.
42
43 """
44
45 from pyxb.exceptions_ import *
46 import types
47 import pyxb.namespace
48 import pyxb.utils.domutils as domutils
49 import pyxb.utils.utility as utility
50 import basis
51 import re
52 import binascii
53 import base64
54
55 _PrimitiveDatatypes = []
56 _DerivedDatatypes = []
57 _ListDatatypes = []
58
59
60
61
62 -class anySimpleType (basis.simpleTypeDefinition, unicode):
70
71
72
73 -class string (basis.simpleTypeDefinition, unicode):
86
87 _PrimitiveDatatypes.append(string)
88
89
90
91 -class boolean (basis.simpleTypeDefinition, types.IntType):
92 """XMLSchema datatype U{boolean<http://www.w3.org/TR/xmlschema-2/#boolean>}."""
93 _XsdBaseType = anySimpleType
94 _ExpandedName = pyxb.namespace.XMLSchema.createExpandedName('boolean')
95
96 @classmethod
98 if value:
99 return 'true'
100 return 'false'
101
103 if self:
104 return 'true'
105 return 'false'
106
108 args = cls._ConvertArguments(args, kw)
109 if 0 < len(args):
110 value = args[0]
111 args = args[1:]
112 if value in (1, 0, '1', '0', 'true', 'false'):
113 if value in (1, '1', 'true'):
114 iv = True
115 else:
116 iv = False
117 return super(boolean, cls).__new__(cls, iv, *args, **kw)
118 raise BadTypeValueError('[xsd:boolean] Initializer "%s" not valid for type' % (value,))
119 return super(boolean, cls).__new__(cls, *args, **kw)
120
121 _PrimitiveDatatypes.append(boolean)
122
123 -class decimal (basis.simpleTypeDefinition, types.FloatType):
136
137 _PrimitiveDatatypes.append(decimal)
138
139 -class float (basis.simpleTypeDefinition, types.FloatType):
147
148 _PrimitiveDatatypes.append(float)
149
150 -class double (basis.simpleTypeDefinition, types.FloatType):
158
159 _PrimitiveDatatypes.append(double)
160
161 import time as python_time
162 import datetime
163
164 -class duration (basis.simpleTypeDefinition, datetime.timedelta):
165 """XMLSchema datatype U{duration<http://www.w3.org/TR/xmlschema-2/#duration>}.
166
167 This class uses the Python C{datetime.timedelta} class as its
168 underlying representation. This works fine as long as no months
169 or years are involved, and no negative durations are involved.
170 Because the XML Schema value space is so much larger, it is kept
171 distinct from the Python value space, which reduces to integral
172 days, seconds, and microseconds.
173
174 In other words, the implementation of this type is a little
175 shakey.
176
177 """
178
179 _XsdBaseType = anySimpleType
180 _ExpandedName = pyxb.namespace.XMLSchema.createExpandedName('duration')
181
182 __Lexical_re = re.compile('^(?P<neg>-?)P((?P<years>\d+)Y)?((?P<months>\d+)M)?((?P<days>\d+)D)?(?P<Time>T((?P<hours>\d+)H)?((?P<minutes>\d+)M)?(((?P<seconds>\d+)(?P<fracsec>\.\d+)?)S)?)?$')
183
184
185 __XSDFields = ( 'years', 'months', 'days', 'hours', 'minutes', 'seconds' )
186 __PythonFields = ( 'days', 'seconds', 'microseconds', 'minutes', 'hours' )
187
190 __negativeDuration = None
191
194 __durationData = None
195
197 args = cls._ConvertArguments(args, kw)
198 text = args[0]
199 have_kw_update = False
200 if isinstance(text, (str, unicode)):
201 match = cls.__Lexical_re.match(text)
202 if match is None:
203 raise BadTypeValueError('Value "%s" not in %s lexical space' % (text, cls._ExpandedName))
204 match_map = match.groupdict()
205 if 'T' == match_map.get('Time', None):
206
207 raise BadTypeValueError('Value "%s" not in %s lexical space' % (text, cls._ExpandedName))
208
209 negative_duration = ('-' == match_map.get('neg', None))
210
211 fractional_seconds = 0.0
212 if match_map.get('fracsec', None) is not None:
213 fractional_seconds = types.FloatType('0%s' % (match_map['fracsec'],))
214 usec = types.IntType(1000000 * fractional_seconds)
215 if negative_duration:
216 kw['microseconds'] = - usec
217 else:
218 kw['microseconds'] = usec
219 else:
220
221 kw.pop('microsecond', None)
222
223 data = { }
224 for fn in cls.__XSDFields:
225 v = match_map.get(fn, 0)
226 if v is None:
227 v = 0
228 data[fn] = types.IntType(v)
229 if fn in cls.__PythonFields:
230 if negative_duration:
231 kw[fn] = - data[fn]
232 else:
233 kw[fn] = data[fn]
234 data['seconds'] += fractional_seconds
235 have_kw_update = True
236 elif isinstance(text, cls):
237 data = text.durationData()
238 negative_duration = text.negativeDuration()
239 elif isinstance(text, datetime.timedelta):
240 data = { 'days' : text.days,
241 'seconds' : text.seconds + (text.microseconds / 1000000.0) }
242 negative_duration = (0 > data['days'])
243 if negative_duration:
244 data['days'] = 1 - data['days']
245 data['seconds'] = 24 * 60 * 60.0 - data['seconds']
246 data['minutes'] = 0
247 data['hours'] = 0
248 if not have_kw_update:
249 rem_time = data['seconds']
250 use_seconds = rem_time
251 if (0 != (rem_time % 1)):
252 data['microseconds'] = types.IntType(1000000 * (rem_time % 1))
253 rem_time = rem_time // 1
254 if 60 <= rem_time:
255 data['seconds'] = rem_time % 60
256 rem_time = data['minutes'] + (rem_time // 60)
257 if 60 <= rem_time:
258 data['minutes'] = rem_time % 60
259 rem_time = data['hours'] + (rem_time // 60)
260 data['hours'] = rem_time % 24
261 data['days'] += (rem_time // 24)
262 for fn in cls.__PythonFields:
263 if fn in data:
264 if negative_duration:
265 kw[fn] = - data[fn]
266 else:
267 kw[fn] = data[fn]
268 else:
269 kw.pop(fn, None)
270 kw['microseconds'] = data.pop('microseconds', 0)
271 data['seconds'] += kw['microseconds'] / 1000000.0
272
273 rv = super(duration, cls).__new__(cls, **kw)
274 rv.__durationData = data
275 rv.__negativeDuration = negative_duration
276 return rv
277
278 @classmethod
300
301 _PrimitiveDatatypes.append(duration)
304
305 __PatternMap = { '%Y' : '(?P<negYear>-?)(?P<year>\d{4,})'
306 , '%m' : '(?P<month>\d{2})'
307 , '%d' : '(?P<day>\d{2})'
308 , '%H' : '(?P<hour>\d{2})'
309 , '%M' : '(?P<minute>\d{2})'
310 , '%S' : '(?P<second>\d{2})(?P<fracsec>\.\d+)?'
311 , '%Z' : '(?P<tzinfo>Z|[-+]\d\d:\d\d)' }
312 @classmethod
317
318 __Fields = ( 'year', 'month', 'day', 'hour', 'minute', 'second' )
319
320 _DefaultYear = 1983
321 _DefaultMonth = 6
322 _DefaultDay = 18
323
324 @classmethod
326 match = lexical_re.match(text)
327 if match is None:
328 raise BadTypeValueError('Value "%s" not in %s lexical space' % (text, cls._ExpandedName))
329 match_map = match.groupdict()
330 kw = { }
331 for (k, v) in match_map.iteritems():
332 if (k in cls.__Fields) and (v is not None):
333 kw[k] = types.IntType(v)
334 if '-' == match_map.get('negYear', None):
335 kw['year'] = - kw['year']
336 if match_map.get('fracsec', None) is not None:
337 kw['microsecond'] = types.IntType(1000000 * types.FloatType('0%s' % (match_map['fracsec'],)))
338 else:
339
340 kw.pop('microsecond', None)
341 if match_map.get('tzinfo', None) is not None:
342 kw['tzinfo'] = pyxb.utils.utility.UTCOffsetTimeZone(match_map['tzinfo'], flip=True)
343 else:
344 kw.pop('tzinfo', None)
345 return kw
346
347 @classmethod
349 for f in fields:
350 kw[f] = getattr(python_value, f)
351 return getattr(super(_PyXBDateTime_base, cls), '_SetKeysFromPython_csc', lambda *a,**kw: None)(python_value, kw, fields)
352
353 @classmethod
356
359 """True iff the time represented included time zone information.
360
361 Whether True or not, the moment denoted by an instance is
362 assumed to be in UTC. That state is expressed in the lexical
363 space iff hasTimeZone is True.
364 """
365 return self.__hasTimeZone
368 __hasTimeZone = False
369
370 @classmethod
372 tzoffs = kw.pop('tzinfo', None)
373 has_time_zone = kw.pop('_force_timezone', False)
374 if tzoffs is not None:
375 use_kw = kw.copy()
376 use_kw.setdefault('year', cls._DefaultYear)
377 use_kw.setdefault('month', cls._DefaultMonth)
378 use_kw.setdefault('day', cls._DefaultDay)
379 dt = datetime.datetime(tzinfo=tzoffs, **use_kw)
380 dt = tzoffs.fromutc(dt)
381 for k in kw.iterkeys():
382 kw[k] = getattr(dt, k)
383 has_time_zone = True
384 return has_time_zone
385
386 @classmethod
393
394 -class dateTime (_PyXBDateTimeZone_base, datetime.datetime):
395 """XMLSchema datatype U{dateTime<http://www.w3.org/TR/xmlschema-2/#dateTime>}.
396
397 This class uses the Python C{datetime.datetime} class as its
398 underlying representation. Note that per the XMLSchema spec, all
399 dateTime objects are in UTC, and that timezone information in the
400 string representation in XML is an indication of the local time
401 zone's offset from UTC. Presence of time zone information in the
402 lexical space is preserved through the value of the L{hasTimeZone()}
403 field.
404
405 @warning: The value space of Python's C{datetime.datetime} class
406 is more restricted than that of C{xs:datetime}. As a specific
407 example, Python does not support negative years or years with more
408 than four digits. For now, the convenience of having an object
409 that is compatible with Python is more important than supporting
410 the full value space. In the future, the choice may be left up to
411 the developer.
412 """
413
414 _XsdBaseType = anySimpleType
415 _ExpandedName = pyxb.namespace.XMLSchema.createExpandedName('dateTime')
416
417 __Lexical_re = re.compile(_PyXBDateTime_base._DateTimePattern('^%Y-%m-%dT%H:%M:%S%Z?$'))
418 __Fields = ( 'year', 'month', 'day', 'hour', 'minute', 'second', 'microsecond', 'tzinfo' )
419
421 args = cls._ConvertArguments(args, kw)
422 ctor_kw = { }
423 if 1 == len(args):
424 value = args[0]
425 if isinstance(value, types.StringTypes):
426 ctor_kw.update(cls._LexicalToKeywords(value, cls.__Lexical_re))
427 elif isinstance(value, (datetime.datetime, datetime.date, datetime.time)):
428 cls._SetKeysFromPython(value, ctor_kw, cls.__Fields)
429 if isinstance(value, _PyXBDateTimeZone_base):
430 ctor_kw['_force_timezone'] = True
431 elif isinstance(value, (types.IntType, types.LongType)):
432 raise TypeError('function takes at least 3 arguments (%d given)' % (len(args),))
433 else:
434 raise BadTypeValueError('Unexpected type %s in %s' % (type(value), cls._ExpandedName))
435 elif 3 <= len(args):
436 for fi in range(len(cls.__Fields)):
437 fn = cls.__Fields[fi]
438 if fi < len(args):
439 ctor_kw[fn] = args[fi]
440 elif fn in kw:
441 ctor_kw[fn] = kw[fn]
442 kw.pop(fn, None)
443 fi += 1
444 else:
445 raise TypeError('function takes at least 3 arguments (%d given)' % (len(args),))
446
447 has_time_zone = cls._AdjustForTimezone(ctor_kw)
448 kw.update(ctor_kw)
449 year = kw.pop('year')
450 month = kw.pop('month')
451 day = kw.pop('day')
452 rv = super(dateTime, cls).__new__(cls, year, month, day, **kw)
453 rv._setHasTimeZone(has_time_zone)
454 return rv
455
456 @classmethod
458 iso = value.isoformat()
459 if 0 <= iso.find('.'):
460 iso = iso.rstrip('0')
461 if value.hasTimeZone():
462 iso += 'Z'
463 return iso
464
465 __UTCZone = pyxb.utils.utility.UTCOffsetTimeZone(0)
466 __LocalZone = pyxb.utils.utility.LocalTimeZone()
467
468 @classmethod
470 """Return today.
471
472 Just like datetime.datetime.today(), except this one sets a
473 tzinfo field so it's clear the value is UTC."""
474 return cls(datetime.datetime.now(cls.__UTCZone))
475
477 """Returns a C{datetime.datetime} instance denoting the same
478 time as this instance but adjusted to be in the local time
479 zone.
480
481 @rtype: C{datetime.datetime} (B{NOT} C{xsd.dateTime})
482 """
483 return self.replace(tzinfo=self.__UTCZone).astimezone(self.__LocalZone)
484
485 _PrimitiveDatatypes.append(dateTime)
486
487 -class time (_PyXBDateTimeZone_base, datetime.time):
488 """XMLSchema datatype U{time<http://www.w3.org/TR/xmlschema-2/#time>}.
489
490 This class uses the Python C{datetime.time} class as its
491 underlying representation. Note that per the XMLSchema spec, all
492 dateTime objects are in UTC, and that timezone information in the
493 string representation in XML is an indication of the local time
494 zone's offset from UTC. Presence of time zone information in the
495 lexical space is preserved through the value of the
496 L{hasTimeZone()} field.
497 """
498
499 _XsdBaseType = anySimpleType
500 _ExpandedName = pyxb.namespace.XMLSchema.createExpandedName('time')
501
502 __Lexical_re = re.compile(_PyXBDateTime_base._DateTimePattern('^%H:%M:%S%Z?$'))
503 __Fields = ( 'hour', 'minute', 'second', 'microsecond' )
504
506 args = cls._ConvertArguments(args, kw)
507 ctor_kw = { }
508 if 1 <= len(args):
509 value = args[0]
510 if isinstance(value, types.StringTypes):
511 ctor_kw.update(cls._LexicalToKeywords(value, cls.__Lexical_re))
512 elif isinstance(value, datetime.time):
513 cls._SetKeysFromPython(value, ctor_kw, cls.__Fields)
514 elif isinstance(value, (types.IntType, types.LongType)):
515 for fn in range(min(len(args), len(cls.__Fields))):
516 ctor_kw[cls.__Fields[fn]] = args[fn]
517 else:
518 raise BadTypeValueError('Unexpected type %s' % (type(value),))
519
520 has_time_zone = cls._AdjustForTimezone(ctor_kw)
521 kw.update(ctor_kw)
522 rv = super(time, cls).__new__(cls, **kw)
523 rv._setHasTimeZone(has_time_zone)
524 return rv
525
526 @classmethod
528 iso = value.isoformat()
529 if 0 <= iso.find('.'):
530 iso = iso.rstrip('0')
531 if value.hasTimeZone():
532 iso += 'Z'
533 return iso
534
535 _PrimitiveDatatypes.append(time)
538 _XsdBaseType = anySimpleType
539
540 __DateFields = ( 'year', 'month', 'day' )
541 _ISO_beginYear = 0
542 _ISO_endYear = 4
543 _ISO_beginMonth = 5
544 _ISO_endMonth = 7
545 _ISO_beginDay = 8
546 _ISO_endDay = 10
547 _ISOBegin = _ISO_beginYear
548 _ISOEnd = _ISO_endDay
549
556
558 args = cls._ConvertArguments(args, kw)
559 ctor_kw = { }
560 ctor_kw['year'] = cls._DefaultYear
561 ctor_kw['month'] = cls._DefaultMonth
562 ctor_kw['day'] = cls._DefaultDay
563 if 1 == len(args):
564 value = args[0]
565 if isinstance(value, types.StringTypes):
566 ctor_kw.update(cls._LexicalToKeywords(value, cls._Lexical_re))
567 elif isinstance(value, datetime.date):
568 cls._SetKeysFromPython(value, ctor_kw, cls._Fields)
569 elif isinstance(value, (types.IntType, types.LongType)):
570 if (1 != len(cls._Fields)):
571 raise TypeError('function takes exactly %d arguments (%d given)' % (len(cls._Fields), len(args)))
572 ctor_kw[cls._Fields[0]] = value
573 else:
574 raise BadTypeValueError('Unexpected type %s' % (type(value),))
575 elif len(cls._Fields) == len(args):
576 for fi in range(len(cls._Fields)):
577 ctor_kw[cls._Fields[fi]] = args[fi]
578 else:
579 raise TypeError('function takes exactly %d arguments (%d given)' % (len(cls._Fields), len(args)))
580
581 kw.update(ctor_kw)
582 argv = []
583 for f in cls.__DateFields:
584 argv.append(kw.pop(f))
585 return super(_PyXBDateOnly_base, cls).__new__(cls, *argv, **kw)
586
587 @classmethod
590
591 -class date (_PyXBDateOnly_base):
601
602 _PrimitiveDatatypes.append(date)
614
615 _PrimitiveDatatypes.append(gYearMonth)
616
617 -class gYear (_PyXBDateOnly_base):
627 _PrimitiveDatatypes.append(gYear)
639 _PrimitiveDatatypes.append(gMonthDay)
640
641 -class gDay (_PyXBDateOnly_base):
651 _PrimitiveDatatypes.append(gDay)
652
653 -class gMonth (_PyXBDateOnly_base):
664 _PrimitiveDatatypes.append(gMonth)
665
666 -class hexBinary (basis.simpleTypeDefinition, types.StringType):
667 """XMLSchema datatype U{hexBinary<http://www.w3.org/TR/xmlschema-2/#hexBinary>}."""
668 _XsdBaseType = anySimpleType
669 _ExpandedName = pyxb.namespace.XMLSchema.createExpandedName('hexBinary')
670
671 @classmethod
673 if kw.get('_from_xml', False):
674 try:
675 args = (binascii.unhexlify(args[0]),) + args[1:]
676 except TypeError, e:
677 raise BadTypeValueError('%s is not a valid hexBinary string' % (cls.__class__.__name__,))
678 return args
679
680 @classmethod
682 return binascii.hexlify(value).upper()
683
684 @classmethod
687
688 _PrimitiveDatatypes.append(hexBinary)
689
690 -class base64Binary (basis.simpleTypeDefinition, types.StringType):
691 """XMLSchema datatype U{base64Binary<http://www.w3.org/TR/xmlschema-2/#base64Binary>}.
692
693 See also U{RFC2045<http://tools.ietf.org/html/rfc2045>} and U{RFC4648<http://tools.ietf.org/html/rfc4648>}.
694 """
695 _XsdBaseType = anySimpleType
696 _ExpandedName = pyxb.namespace.XMLSchema.createExpandedName('base64Binary')
697
698
699
700
701 _B04 = '[AQgw]'
702 _B04S = '(%s ?)' % (_B04,)
703 _B16 = '[AEIMQUYcgkosw048]'
704 _B16S = '(%s ?)' % (_B16,)
705 _B64 = '[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/]'
706 _B64S = '(%s ?)' % (_B64,)
707
708 __Pattern = '^((' + _B64S + '{4})*((' + _B64S + '{3}' + _B64 + ')|(' + _B64S + '{2}' + _B16S + '=)|(' + _B64S + _B04S + '= ?=)))?$'
709 __Lexical_re = re.compile(__Pattern)
710
711 @classmethod
713 if kw.get('_from_xml', False):
714 xmls = args[0]
715 try:
716 args = (base64.standard_b64decode(xmls),) + args[1:]
717 except TypeError, e:
718 raise BadTypeValueError('%s is not a valid base64Binary string: %s' % (cls.__class__.__name__, str(e)))
719
720 if cls.__Lexical_re.match(xmls) is None:
721 raise BadTypeValueError('%s is not a valid base64Binary string: XML strict failed' % (cls.__class__.__name__,))
722 return args
723
724 @classmethod
726 return base64.standard_b64encode(value)
727
728 @classmethod
731
732 _PrimitiveDatatypes.append(base64Binary)
733
734 -class anyURI (basis.simpleTypeDefinition, unicode):
746
747 _PrimitiveDatatypes.append(anyURI)
748
749 -class QName (basis.simpleTypeDefinition, unicode):
750 """XMLSchema datatype U{QName<http://www.w3.org/TR/xmlschema-2/#QName>}."""
751 _XsdBaseType = anySimpleType
752 _ExpandedName = pyxb.namespace.XMLSchema.createExpandedName('QName')
753
754 @classmethod
756 """Section 4.3.1.3: Legacy length return None to indicate no check"""
757 return None
758
759 __localName = None
760 __prefix = None
761
763 """Return the prefix portion of the QName, or None if the name is not qualified."""
764 if self.__localName is None:
765 self.__resolveLocals()
766 return self.__prefix
767
773
779
780 @classmethod
783
784 @classmethod
786 if not isinstance(value, types.StringTypes):
787 raise BadTypeValueError('%s value must be a string' % (cls.__name__,))
788 if 0 <= value.find(':'):
789 (prefix, local) = value.split(':', 1)
790 if (NCName._ValidRE.match(prefix) is None) or (NCName._ValidRE.match(local) is None):
791 raise BadTypeValueError('%s lexical/value space violation for "%s"' % (cls.__name__, value))
792 else:
793 if NCName._ValidRE.match(value) is None:
794 raise BadTypeValueError('%s lexical/value space violation for "%s"' % (cls.__name__, value))
795 super_fn = getattr(super(QName, cls), '_XsdConstraintsPreCheck_vb', lambda *a,**kw: True)
796 return super_fn(value)
797
798
799 _PrimitiveDatatypes.append(QName)
800
801 -class NOTATION (basis.simpleTypeDefinition):
810
811 _PrimitiveDatatypes.append(NOTATION)
814 """XMLSchema datatype U{normalizedString<http:///www.w3.org/TR/xmlschema-2/#normalizedString>}.
815
816 Normalized strings can't have carriage returns, linefeeds, or
817 tabs in them."""
818
819
820
821
822
823
824
825
826
827
828 _ExpandedName = pyxb.namespace.XMLSchema.createExpandedName('normalizedString')
829
830
831
832
833 __BadChars = re.compile("[\r\n\t]")
834
835 _ValidRE = None
836 _InvalidRE = None
837
838 @classmethod
854
855 @classmethod
857 """Post-extended method to validate that a string matches a given pattern.
858
859 If you can express the valid strings as a compiled regular
860 expression in the class variable _ValidRE, or the invalid
861 strings as a compiled regular expression in the class variable
862 _InvalidRE, you can just use those. If the acceptable matches
863 are any trickier, you should invoke the superclass
864 implementation, and if it returns True then perform additional
865 tests."""
866 super_fn = getattr(super(normalizedString, cls), '_ValidateString_va', lambda *a,**kw: True)
867 if not super_fn(value):
868 return False
869 return cls.__ValidateString(value)
870
871 @classmethod
879
880 _DerivedDatatypes.append(normalizedString)
881 assert normalizedString.XsdSuperType() == string
882
883 -class token (normalizedString):
884 """XMLSchema datatype U{token<http:///www.w3.org/TR/xmlschema-2/#token>}.
885
886 Tokens cannot leading or trailing space characters; any
887 carriage return, line feed, or tab characters; nor any occurrence
888 of two or more consecutive space characters."""
889
890 _ExpandedName = pyxb.namespace.XMLSchema.createExpandedName('token')
891
892 @classmethod
894 super_fn = getattr(super(token, cls), '_ValidateString_va', lambda *a,**kw: True)
895 if not super_fn(value):
896 return False
897 if value.startswith(" "):
898 raise BadTypeValueError('Leading spaces in token')
899 if value.endswith(" "):
900 raise BadTypeValueError('Trailing spaces in token')
901 if 0 <= value.find(' '):
902 raise BadTypeValueError('Multiple internal spaces in token')
903 return True
904 _DerivedDatatypes.append(token)
910 _DerivedDatatypes.append(language)
913 """XMLSchema datatype U{NMTOKEN<http:///www.w3.org/TR/xmlschema-2/#NMTOKEN>}.
914
915 See U{http://www.w3.org/TR/2000/WD-xml-2e-20000814.html#NT-Nmtoken}.
916
917 NMTOKEN is an identifier that can start with any character that is
918 legal in it."""
919 _ExpandedName = pyxb.namespace.XMLSchema.createExpandedName('NMTOKEN')
920 _ValidRE = re.compile('^[-_.:A-Za-z0-9]*$')
921 _DerivedDatatypes.append(NMTOKEN)
925 _ListDatatypes.append(NMTOKENS)
926
927 -class Name (token):
933 _DerivedDatatypes.append(Name)
941 _DerivedDatatypes.append(NCName)
942
943 -class ID (NCName):
948 _DerivedDatatypes.append(ID)
949
950 -class IDREF (NCName):
955 _DerivedDatatypes.append(IDREF)
956
957 -class IDREFS (basis.STD_list):
961 _ListDatatypes.append(IDREFS)
973 _DerivedDatatypes.append(ENTITY)
979 _ListDatatypes.append(ENTITIES)
980
981 -class integer (basis.simpleTypeDefinition, types.LongType):
989
990 _DerivedDatatypes.append(integer)
995 _DerivedDatatypes.append(nonPositiveInteger)
1000 _DerivedDatatypes.append(negativeInteger)
1001
1002 -class long (integer):
1005 _DerivedDatatypes.append(long)
1006
1007 -class int (basis.simpleTypeDefinition, types.IntType):
1017 _DerivedDatatypes.append(int)
1022 _DerivedDatatypes.append(short)
1023
1024 -class byte (short):
1027 _DerivedDatatypes.append(byte)
1032 _DerivedDatatypes.append(nonNegativeInteger)
1037 _DerivedDatatypes.append(unsignedLong)
1042 _DerivedDatatypes.append(unsignedInt)
1047 _DerivedDatatypes.append(unsignedShort)
1052 _DerivedDatatypes.append(unsignedByte)
1057 _DerivedDatatypes.append(positiveInteger)
1058
1059 import datatypes_facets
1060 import content
1061
1062 -class anyType (basis.complexTypeDefinition):
1074
1075
1076
1077 anyType._IsUrType = classmethod(lambda _c: _c == anyType)
1078