FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
plotdevice-libs/google/pygoogle/SOAP.py at master · plotdevice/plotdevice-libs · GitHub
plotdevice-libs/google/pygoogle/SOAP.py at master · plotdevice/plotdevice-libs · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
See all industries
View all solutions
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
plotdevice
plotdevice-libs
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
plotdevice-libs
/
google
/
pygoogle
/
SOAP.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
3957 lines (3073 loc) · 127 KB
Breadcrumbs
plotdevice-libs
/
google
/
pygoogle
/
SOAP.py
Copy path
File metadata and controls
executable file
·
3957 lines (3073 loc) · 127 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python
################################################################################
#
# SOAP.py 0.9.7 - Cayce Ullman (cayce@actzero.com)
# Brian Matthews (blm@actzero.com)
#
# INCLUDED:
# - General SOAP Parser based on sax.xml (requires Python 2.0)
# - General SOAP Builder
# - SOAP Proxy for RPC client code
# - SOAP Server framework for RPC server code
#
# FEATURES:
# - Handles all of the types in the BDG
# - Handles faults
# - Allows namespace specification
# - Allows SOAPAction specification
# - Homogeneous typed arrays
# - Supports multiple schemas
# - Header support (mustUnderstand and actor)
# - XML attribute support
# - Multi-referencing support (Parser/Builder)
# - Understands SOAP-ENC:root attribute
# - Good interop, passes all client tests for Frontier, SOAP::LITE, SOAPRMI
# - Encodings
# - SSL clients (with OpenSSL configured in to Python)
# - SSL servers (with OpenSSL configured in to Python and M2Crypto installed)
#
# TODO:
# - Timeout on method calls - MCU
# - Arrays (sparse, multidimensional and partial) - BLM
# - Clean up data types - BLM
# - Type coercion system (Builder) - MCU
# - Early WSDL Support - MCU
# - Attachments - BLM
# - setup.py - MCU
# - mod_python example - MCU
# - medusa example - MCU
# - Documentation - JAG
# - Look at performance
#
################################################################################
#
# Copyright (c) 2001, Cayce Ullman.
# Copyright (c) 2001, Brian Matthews.
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# Neither the name of actzero, inc. nor the names of its contributors may
# be used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
################################################################################
#
# Additional changes:
# 0.9.7.3 - 4/18/2002 - Mark Pilgrim (f8dy@diveintomark.org)
# added dump_dict as alias for dump_dictionary for Python 2.2 compatibility
# 0.9.7.2 - 4/12/2002 - Mark Pilgrim (f8dy@diveintomark.org)
# fixed logic to unmarshal the value of "null" attributes ("true" or "1"
# means true, others false)
# 0.9.7.1 - 4/11/2002 - Mark Pilgrim (f8dy@diveintomark.org)
# added "dump_str" as alias for "dump_string" for Python 2.2 compatibility
# Between 2.1 and 2.2, type("").__name__ changed from "string" to "str"
################################################################################
import
xml
.
sax
import
collections
import
base64
import
cgi
import
urllib
.
request
,
urllib
.
parse
,
urllib
.
error
import
exceptions
import
copy
import
re
import
socket
import
string
import
sys
import
time
import
socketserver
from
types
import
*
try
:
from
M2Crypto
import
SSL
except
:
pass
ident
=
'$Id: SOAP.py,v 1.1.1.1 2004/01/16 16:15:18 bluecoat93 Exp $'
__version__
=
"0.9.7.3"
# Platform hackery
# Check float support
try
:
float
(
"NaN"
)
float
(
"INF"
)
float
(
"-INF"
)
good_float
=
1
except
:
good_float
=
0
################################################################################
# Exceptions
################################################################################
class
Error
(
exceptions
.
Exception
):
def
__init__
(
self
,
msg
):
self
.
msg
=
msg
def
__str__
(
self
):
return
"<Error : %s>"
%
self
.
msg
__repr__
=
__str__
class
RecursionError
(
Error
):
pass
class
UnknownTypeError
(
Error
):
pass
class
HTTPError
(
Error
):
# indicates an HTTP protocol error
def
__init__
(
self
,
code
,
msg
):
self
.
code
=
code
self
.
msg
=
msg
def
__str__
(
self
):
return
"<HTTPError %s %s>"
%
(
self
.
code
,
self
.
msg
)
__repr__
=
__str__
##############################################################################
# Namespace Class
################################################################################
def
invertDict
(
dict
):
d
=
{}
for
k
,
v
in
list
(
dict
.
items
()):
d
[
v
]
=
k
return
d
class
NS
:
XML
=
"http://www.w3.org/XML/1998/namespace"
ENV
=
"http://schemas.xmlsoap.org/soap/envelope/"
ENC
=
"http://schemas.xmlsoap.org/soap/encoding/"
XSD
=
"http://www.w3.org/1999/XMLSchema"
XSD2
=
"http://www.w3.org/2000/10/XMLSchema"
XSD3
=
"http://www.w3.org/2001/XMLSchema"
XSD_L
=
[
XSD
,
XSD2
,
XSD3
]
EXSD_L
=
[
ENC
,
XSD
,
XSD2
,
XSD3
]
XSI
=
"http://www.w3.org/1999/XMLSchema-instance"
XSI2
=
"http://www.w3.org/2000/10/XMLSchema-instance"
XSI3
=
"http://www.w3.org/2001/XMLSchema-instance"
XSI_L
=
[
XSI
,
XSI2
,
XSI3
]
URN
=
"http://soapinterop.org/xsd"
# For generated messages
XML_T
=
"xml"
ENV_T
=
"SOAP-ENV"
ENC_T
=
"SOAP-ENC"
XSD_T
=
"xsd"
XSD2_T
=
"xsd2"
XSD3_T
=
"xsd3"
XSI_T
=
"xsi"
XSI2_T
=
"xsi2"
XSI3_T
=
"xsi3"
URN_T
=
"urn"
NSMAP
=
{
ENV_T
:
ENV
,
ENC_T
:
ENC
,
XSD_T
:
XSD
,
XSD2_T
:
XSD2
,
XSD3_T
:
XSD3
,
XSI_T
:
XSI
,
XSI2_T
:
XSI2
,
XSI3_T
:
XSI3
,
URN_T
:
URN
}
NSMAP_R
=
invertDict
(
NSMAP
)
STMAP
=
{
'1999'
: (
XSD_T
,
XSI_T
),
'2000'
: (
XSD2_T
,
XSI2_T
),
'2001'
: (
XSD3_T
,
XSI3_T
)}
STMAP_R
=
invertDict
(
STMAP
)
def
__init__
(
self
):
raise
Error
(
"Don't instantiate this"
)
################################################################################
# Configuration class
################################################################################
class
SOAPConfig
:
__readonly
=
(
'SSLserver'
,
'SSLclient'
)
def
__init__
(
self
,
config
=
None
,
**
kw
):
d
=
self
.
__dict__
if
config
:
if
not
isinstance
(
config
,
SOAPConfig
):
raise
AttributeError
(
"initializer must be SOAPConfig instance"
)
s
=
config
.
__dict__
for
k
,
v
in
list
(
s
.
items
()):
if
k
[
0
]
!=
'_'
:
d
[
k
]
=
v
else
:
# Setting debug also sets returnFaultInfo, dumpFaultInfo,
# dumpHeadersIn, dumpHeadersOut, dumpSOAPIn, and dumpSOAPOut
self
.
debug
=
0
# Setting namespaceStyle sets typesNamespace, typesNamespaceURI,
# schemaNamespace, and schemaNamespaceURI
self
.
namespaceStyle
=
'1999'
self
.
strictNamespaces
=
0
self
.
typed
=
1
self
.
buildWithNamespacePrefix
=
1
self
.
returnAllAttrs
=
0
try
:
SSL
;
d
[
'SSLserver'
]
=
1
except
:
d
[
'SSLserver'
]
=
0
try
:
socket
.
ssl
;
d
[
'SSLclient'
]
=
1
except
:
d
[
'SSLclient'
]
=
0
for
k
,
v
in
list
(
kw
.
items
()):
if
k
[
0
]
!=
'_'
:
setattr
(
self
,
k
,
v
)
def
__setattr__
(
self
,
name
,
value
):
if
name
in
self
.
__readonly
:
raise
AttributeError
(
"readonly configuration setting"
)
d
=
self
.
__dict__
if
name
in
(
'typesNamespace'
,
'typesNamespaceURI'
,
'schemaNamespace'
,
'schemaNamespaceURI'
):
if
name
[
-
3
:]
==
'URI'
:
base
,
uri
=
name
[:
-
3
],
1
else
:
base
,
uri
=
name
,
0
if
type
(
value
)
==
StringType
:
if
value
in
NS
.
NSMAP
:
n
=
(
value
,
NS
.
NSMAP
[
value
])
elif
value
in
NS
.
NSMAP_R
:
n
=
(
NS
.
NSMAP_R
[
value
],
value
)
else
:
raise
AttributeError
(
"unknown namespace"
)
elif
type
(
value
)
in
(
ListType
,
TupleType
):
if
uri
:
n
=
(
value
[
1
],
value
[
0
])
else
:
n
=
(
value
[
0
],
value
[
1
])
else
:
raise
AttributeError
(
"unknown namespace type"
)
d
[
base
],
d
[
base
+
'URI'
]
=
n
try
:
d
[
'namespaceStyle'
]
=
\
NS
.
STMAP_R
[(
d
[
'typesNamespace'
],
d
[
'schemaNamespace'
])]
except
:
d
[
'namespaceStyle'
]
=
''
elif
name
==
'namespaceStyle'
:
value
=
str
(
value
)
if
value
not
in
NS
.
STMAP
:
raise
AttributeError
(
"unknown namespace style"
)
d
[
name
]
=
value
n
=
d
[
'typesNamespace'
]
=
NS
.
STMAP
[
value
][
0
]
d
[
'typesNamespaceURI'
]
=
NS
.
NSMAP
[
n
]
n
=
d
[
'schemaNamespace'
]
=
NS
.
STMAP
[
value
][
1
]
d
[
'schemaNamespaceURI'
]
=
NS
.
NSMAP
[
n
]
elif
name
==
'debug'
:
d
[
name
]
=
\
d
[
'returnFaultInfo'
]
=
\
d
[
'dumpFaultInfo'
]
=
\
d
[
'dumpHeadersIn'
]
=
\
d
[
'dumpHeadersOut'
]
=
\
d
[
'dumpSOAPIn'
]
=
\
d
[
'dumpSOAPOut'
]
=
value
else
:
d
[
name
]
=
value
Config
=
SOAPConfig
()
################################################################################
# Types and Wrappers
################################################################################
class
anyType
:
_validURIs
=
(
NS
.
XSD
,
NS
.
XSD2
,
NS
.
XSD3
,
NS
.
ENC
)
def
__init__
(
self
,
data
=
None
,
name
=
None
,
typed
=
1
,
attrs
=
None
):
if
self
.
__class__
==
anyType
:
raise
Error
(
"anyType can't be instantiated directly"
)
if
type
(
name
)
in
(
ListType
,
TupleType
):
self
.
_ns
,
self
.
_name
=
name
else
:
self
.
_ns
,
self
.
_name
=
self
.
_validURIs
[
0
],
name
self
.
_typed
=
typed
self
.
_attrs
=
{}
self
.
_cache
=
None
self
.
_type
=
self
.
_typeName
()
self
.
_data
=
self
.
_checkValueSpace
(
data
)
if
attrs
!=
None
:
self
.
_setAttrs
(
attrs
)
def
__str__
(
self
):
if
self
.
_name
:
return
"<%s %s at %d>"
%
(
self
.
__class__
,
self
.
_name
,
id
(
self
))
return
"<%s at %d>"
%
(
self
.
__class__
,
id
(
self
))
__repr__
=
__str__
def
_checkValueSpace
(
self
,
data
):
return
data
def
_marshalData
(
self
):
return
str
(
self
.
_data
)
def
_marshalAttrs
(
self
,
ns_map
,
builder
):
a
=
''
for
attr
,
value
in
list
(
self
.
_attrs
.
items
()):
ns
,
n
=
builder
.
genns
(
ns_map
,
attr
[
0
])
a
+=
n
+
' %s%s="%s"'
%
\
(
ns
,
attr
[
1
],
cgi
.
escape
(
str
(
value
),
1
))
return
a
def
_fixAttr
(
self
,
attr
):
if
type
(
attr
)
in
(
StringType
,
UnicodeType
):
attr
=
(
None
,
attr
)
elif
type
(
attr
)
==
ListType
:
attr
=
tuple
(
attr
)
elif
type
(
attr
)
!=
TupleType
:
raise
AttributeError
(
"invalid attribute type"
)
if
len
(
attr
)
!=
2
:
raise
AttributeError
(
"invalid attribute length"
)
if
type
(
attr
[
0
])
not
in
(
NoneType
,
StringType
,
UnicodeType
):
raise
AttributeError
(
"invalid attribute namespace URI type"
)
return
attr
def
_getAttr
(
self
,
attr
):
attr
=
self
.
_fixAttr
(
attr
)
try
:
return
self
.
_attrs
[
attr
]
except
:
return
None
def
_setAttr
(
self
,
attr
,
value
):
attr
=
self
.
_fixAttr
(
attr
)
self
.
_attrs
[
attr
]
=
str
(
value
)
def
_setAttrs
(
self
,
attrs
):
if
type
(
attrs
)
in
(
ListType
,
TupleType
):
for
i
in
range
(
0
,
len
(
attrs
),
2
):
self
.
_setAttr
(
attrs
[
i
],
attrs
[
i
+
1
])
return
if
type
(
attrs
)
==
DictType
:
d
=
attrs
elif
isinstance
(
attrs
,
anyType
):
d
=
attrs
.
_attrs
else
:
raise
AttributeError
(
"invalid attribute type"
)
for
attr
,
value
in
list
(
d
.
items
()):
self
.
_setAttr
(
attr
,
value
)
def
_setMustUnderstand
(
self
,
val
):
self
.
_setAttr
((
NS
.
ENV
,
"mustUnderstand"
),
val
)
def
_getMustUnderstand
(
self
):
return
self
.
_getAttr
((
NS
.
ENV
,
"mustUnderstand"
))
def
_setActor
(
self
,
val
):
self
.
_setAttr
((
NS
.
ENV
,
"actor"
),
val
)
def
_getActor
(
self
):
return
self
.
_getAttr
((
NS
.
ENV
,
"actor"
))
def
_typeName
(
self
):
return
self
.
__class__
.
__name__
[:
-
4
]
def
_validNamespaceURI
(
self
,
URI
,
strict
):
if
not
self
.
_typed
:
return
None
if
URI
in
self
.
_validURIs
:
return
URI
if
not
strict
:
return
self
.
_ns
raise
AttributeError
(
"not a valid namespace for type %s"
%
self
.
_type
)
class
voidType
(
anyType
):
pass
class
stringType
(
anyType
):
def
_checkValueSpace
(
self
,
data
):
if
data
==
None
:
raise
ValueError
(
"must supply initial %s value"
%
self
.
_type
)
if
type
(
data
)
not
in
(
StringType
,
UnicodeType
):
raise
AttributeError
(
"invalid %s type"
%
self
.
_type
)
return
data
class
untypedType
(
stringType
):
def
__init__
(
self
,
data
=
None
,
name
=
None
,
attrs
=
None
):
stringType
.
__init__
(
self
,
data
,
name
,
0
,
attrs
)
class
IDType
(
stringType
):
pass
class
NCNameType
(
stringType
):
pass
class
NameType
(
stringType
):
pass
class
ENTITYType
(
stringType
):
pass
class
IDREFType
(
stringType
):
pass
class
languageType
(
stringType
):
pass
class
NMTOKENType
(
stringType
):
pass
class
QNameType
(
stringType
):
pass
class
tokenType
(
anyType
):
_validURIs
=
(
NS
.
XSD2
,
NS
.
XSD3
)
__invalidre
=
'[
\n
\t
]|^ | $| '
def
_checkValueSpace
(
self
,
data
):
if
data
==
None
:
raise
ValueError
(
"must supply initial %s value"
%
self
.
_type
)
if
type
(
data
)
not
in
(
StringType
,
UnicodeType
):
raise
AttributeError
(
"invalid %s type"
%
self
.
_type
)
if
type
(
self
.
__invalidre
)
==
StringType
:
self
.
__invalidre
=
re
.
compile
(
self
.
__invalidre
)
if
self
.
__invalidre
.
search
(
data
):
raise
ValueError
(
"invalid %s value"
%
self
.
_type
)
return
data
class
normalizedStringType
(
anyType
):
_validURIs
=
(
NS
.
XSD3
,)
__invalidre
=
'[
\n
\r
\t
]'
def
_checkValueSpace
(
self
,
data
):
if
data
==
None
:
raise
ValueError
(
"must supply initial %s value"
%
self
.
_type
)
if
type
(
data
)
not
in
(
StringType
,
UnicodeType
):
raise
AttributeError
(
"invalid %s type"
%
self
.
_type
)
if
type
(
self
.
__invalidre
)
==
StringType
:
self
.
__invalidre
=
re
.
compile
(
self
.
__invalidre
)
if
self
.
__invalidre
.
search
(
data
):
raise
ValueError
(
"invalid %s value"
%
self
.
_type
)
return
data
class
CDATAType
(
normalizedStringType
):
_validURIs
=
(
NS
.
XSD2
,)
class
booleanType
(
anyType
):
def
__int__
(
self
):
return
self
.
_data
__nonzero__
=
__int__
def
_marshalData
(
self
):
return
[
'false'
,
'true'
][
self
.
_data
]
def
_checkValueSpace
(
self
,
data
):
if
data
==
None
:
raise
ValueError
(
"must supply initial %s value"
%
self
.
_type
)
if
data
in
(
0
,
'0'
,
'false'
,
''
):
return
0
if
data
in
(
1
,
'1'
,
'true'
):
return
1
raise
ValueError
(
"invalid %s value"
%
self
.
_type
)
class
decimalType
(
anyType
):
def
_checkValueSpace
(
self
,
data
):
if
data
==
None
:
raise
ValueError
(
"must supply initial %s value"
%
self
.
_type
)
if
type
(
data
)
not
in
(
IntType
,
LongType
,
FloatType
):
raise
Error
(
"invalid %s value"
%
self
.
_type
)
return
data
class
floatType
(
anyType
):
def
_checkValueSpace
(
self
,
data
):
if
data
==
None
:
raise
ValueError
(
"must supply initial %s value"
%
self
.
_type
)
if
type
(
data
)
not
in
(
IntType
,
LongType
,
FloatType
)
or
\
data
<
-
3.4028234663852886E+38
or
\
data
>
3.4028234663852886E+38
:
raise
ValueError
(
"invalid %s value"
%
self
.
_type
)
return
data
def
_marshalData
(
self
):
return
"%.18g"
%
self
.
_data
# More precision
class
doubleType
(
anyType
):
def
_checkValueSpace
(
self
,
data
):
if
data
==
None
:
raise
ValueError
(
"must supply initial %s value"
%
self
.
_type
)
if
type
(
data
)
not
in
(
IntType
,
LongType
,
FloatType
)
or
\
data
<
-
1.7976931348623158E+308
or
\
data
>
1.7976931348623157E+308
:
raise
ValueError
(
"invalid %s value"
%
self
.
_type
)
return
data
def
_marshalData
(
self
):
return
"%.18g"
%
self
.
_data
# More precision
class
durationType
(
anyType
):
_validURIs
=
(
NS
.
XSD3
,)
def
_checkValueSpace
(
self
,
data
):
if
data
==
None
:
raise
ValueError
(
"must supply initial %s value"
%
self
.
_type
)
try
:
# A tuple or a scalar is OK, but make them into a list
if
type
(
data
)
==
TupleType
:
data
=
list
(
data
)
elif
type
(
data
)
!=
ListType
:
data
=
[
data
]
if
len
(
data
)
>
6
:
raise
Exception
(
"too many values"
)
# Now check the types of all the components, and find
# the first nonzero element along the way.
f
=
-
1
for
i
in
range
(
len
(
data
)):
if
data
[
i
]
==
None
:
data
[
i
]
=
0
continue
if
type
(
data
[
i
])
not
in
\
(
IntType
,
LongType
,
FloatType
):
raise
Exception
(
"element %d a bad type"
%
i
)
if
data
[
i
]
and
f
==
-
1
:
f
=
i
# If they're all 0, just use zero seconds.
if
f
==
-
1
:
self
.
_cache
=
'PT0S'
return
(
0
,)
*
6
# Make sure only the last nonzero element has a decimal fraction
# and only the first element is negative.
d
=
-
1
for
i
in
range
(
f
,
len
(
data
)):
if
data
[
i
]:
if
d
!=
-
1
:
raise
Exception
(
"all except the last nonzero element must be "
\
"integers"
)
if
data
[
i
]
<
0
and
i
>
f
:
raise
Exception
(
"only the first nonzero element can be negative"
)
elif
data
[
i
]
!=
int
(
data
[
i
]):
d
=
i
# Pad the list on the left if necessary.
if
len
(
data
)
<
6
:
n
=
6
-
len
(
data
)
f
+=
n
d
+=
n
data
=
[
0
]
*
n
+
data
# Save index of the first nonzero element and the decimal
# element for _marshalData.
self
.
__firstnonzero
=
f
self
.
__decimal
=
d
except
Exception
as
e
:
raise
ValueError
(
"invalid %s value - %s"
%
(
self
.
_type
,
e
))
return
tuple
(
data
)
def
_marshalData
(
self
):
if
self
.
_cache
==
None
:
d
=
self
.
_data
t
=
0
if
d
[
self
.
__firstnonzero
]
<
0
:
s
=
'-P'
else
:
s
=
'P'
t
=
0
for
i
in
range
(
self
.
__firstnonzero
,
len
(
d
)):
if
d
[
i
]:
if
i
>
2
and
not
t
:
s
+=
'T'
t
=
1
if
self
.
__decimal
==
i
:
s
+=
"%g"
%
abs
(
d
[
i
])
else
:
s
+=
"%d"
%
int
(
abs
(
d
[
i
]))
s
+=
[
'Y'
,
'M'
,
'D'
,
'H'
,
'M'
,
'S'
][
i
]
self
.
_cache
=
s
return
self
.
_cache
class
timeDurationType
(
durationType
):
_validURIs
=
(
NS
.
XSD
,
NS
.
XSD2
,
NS
.
ENC
)
class
dateTimeType
(
anyType
):
_validURIs
=
(
NS
.
XSD3
,)
def
_checkValueSpace
(
self
,
data
):
try
:
if
data
==
None
:
data
=
time
.
time
()
if
(
type
(
data
)
in
(
IntType
,
LongType
)):
data
=
list
(
time
.
gmtime
(
data
)[:
6
])
elif
(
type
(
data
)
==
FloatType
):
f
=
data
-
int
(
data
)
data
=
list
(
time
.
gmtime
(
int
(
data
))[:
6
])
data
[
5
]
+=
f
elif
type
(
data
)
in
(
ListType
,
TupleType
):
if
len
(
data
)
<
6
:
raise
Exception
(
"not enough values"
)
if
len
(
data
)
>
9
:
raise
Exception
(
"too many values"
)
data
=
list
(
data
[:
6
])
cleanDate
(
data
)
else
:
raise
Exception
(
"invalid type"
)
except
Exception
as
e
:
raise
ValueError
(
"invalid %s value - %s"
%
(
self
.
_type
,
e
))
return
tuple
(
data
)
def
_marshalData
(
self
):
if
self
.
_cache
==
None
:
d
=
self
.
_data
s
=
"%04d-%02d-%02dT%02d:%02d:%02d"
%
((
abs
(
d
[
0
]),)
+
d
[
1
:])
if
d
[
0
]
<
0
:
s
=
'-'
+
s
f
=
d
[
5
]
-
int
(
d
[
5
])
if
f
!=
0
:
s
+=
(
"%g"
%
f
)[
1
:]
s
+=
'Z'
self
.
_cache
=
s
return
self
.
_cache
class
recurringInstantType
(
anyType
):
_validURIs
=
(
NS
.
XSD
,)
def
_checkValueSpace
(
self
,
data
):
try
:
if
data
==
None
:
data
=
list
(
time
.
gmtime
(
time
.
time
())[:
6
])
if
(
type
(
data
)
in
(
IntType
,
LongType
)):
data
=
list
(
time
.
gmtime
(
data
)[:
6
])
elif
(
type
(
data
)
==
FloatType
):
f
=
data
-
int
(
data
)
data
=
list
(
time
.
gmtime
(
int
(
data
))[:
6
])
data
[
5
]
+=
f
elif
type
(
data
)
in
(
ListType
,
TupleType
):
if
len
(
data
)
<
1
:
raise
Exception
(
"not enough values"
)
if
len
(
data
)
>
9
:
raise
Exception
(
"too many values"
)
data
=
list
(
data
[:
6
])
if
len
(
data
)
<
6
:
data
+=
[
0
]
*
(
6
-
len
(
data
))
f
=
len
(
data
)
for
i
in
range
(
f
):
if
data
[
i
]
==
None
:
if
f
<
i
:
raise
Exception
(
"only leftmost elements can be none"
)
else
:
f
=
i
break
cleanDate
(
data
,
f
)
else
:
raise
Exception
(
"invalid type"
)
except
Exception
as
e
:
raise
ValueError
(
"invalid %s value - %s"
%
(
self
.
_type
,
e
))
return
tuple
(
data
)
def
_marshalData
(
self
):
if
self
.
_cache
==
None
:
d
=
self
.
_data
e
=
list
(
d
)
neg
=
''
if
e
[
0
]
<
0
:
neg
=
'-'
e
[
0
]
=
abs
(
e
[
0
])
if
not
e
[
0
]:
e
[
0
]
=
'--'
elif
e
[
0
]
<
100
:
e
[
0
]
=
'-'
+
"%02d"
%
e
[
0
]
else
:
e
[
0
]
=
"%04d"
%
e
[
0
]
for
i
in
range
(
1
,
len
(
e
)):
if
e
[
i
]
==
None
or
(
i
<
3
and
e
[
i
]
==
0
):
e
[
i
]
=
'-'
else
:
if
e
[
i
]
<
0
:
neg
=
'-'
e
[
i
]
=
abs
(
e
[
i
])
e
[
i
]
=
"%02d"
%
e
[
i
]
if
d
[
5
]:
f
=
abs
(
d
[
5
]
-
int
(
d
[
5
]))
if
f
:
e
[
5
]
+=
(
"%g"
%
f
)[
1
:]
s
=
"%s%s-%s-%sT%s:%s:%sZ"
%
((
neg
,)
+
tuple
(
e
))
self
.
_cache
=
s
return
self
.
_cache
class
timeInstantType
(
dateTimeType
):
_validURIs
=
(
NS
.
XSD
,
NS
.
XSD2
,
NS
.
ENC
)
class
timePeriodType
(
dateTimeType
):
_validURIs
=
(
NS
.
XSD2
,
NS
.
ENC
)
class
timeType
(
anyType
):
def
_checkValueSpace
(
self
,
data
):
try
:
if
data
==
None
:
data
=
time
.
gmtime
(
time
.
time
())[
3
:
6
]
elif
(
type
(
data
)
==
FloatType
):
f
=
data
-
int
(
data
)
data
=
list
(
time
.
gmtime
(
int
(
data
))[
3
:
6
])
data
[
2
]
+=
f
elif
type
(
data
)
in
(
IntType
,
LongType
):
data
=
time
.
gmtime
(
data
)[
3
:
6
]
elif
type
(
data
)
in
(
ListType
,
TupleType
):
if
len
(
data
)
==
9
:
data
=
data
[
3
:
6
]
elif
len
(
data
)
>
3
:
raise
Exception
(
"too many values"
)
data
=
[
None
,
None
,
None
]
+
list
(
data
)
if
len
(
data
)
<
6
:
data
+=
[
0
]
*
(
6
-
len
(
data
))
cleanDate
(
data
,
3
)
data
=
data
[
3
:]
else
:
raise
Exception
(
"invalid type"
)
except
Exception
as
e
:
raise
ValueError
(
"invalid %s value - %s"
%
(
self
.
_type
,
e
))
return
tuple
(
data
)
def
_marshalData
(
self
):
if
self
.
_cache
==
None
:
d
=
self
.
_data
s
=
''
s
=
time
.
strftime
(
"%H:%M:%S"
, (
0
,
0
,
0
)
+
d
+
(
0
,
0
,
-
1
))
f
=
d
[
2
]
-
int
(
d
[
2
])
if
f
!=
0
:
s
+=
(
"%g"
%
f
)[
1
:]
s
+=
'Z'
self
.
_cache
=
s
return
self
.
_cache
class
dateType
(
anyType
):
def
_checkValueSpace
(
self
,
data
):
try
:
if
data
==
None
:
data
=
time
.
gmtime
(
time
.
time
())[
0
:
3
]
elif
type
(
data
)
in
(
IntType
,
LongType
,
FloatType
):
data
=
time
.
gmtime
(
data
)[
0
:
3
]
elif
type
(
data
)
in
(
ListType
,
TupleType
):
if
len
(
data
)
==
9
:
data
=
data
[
0
:
3
]
elif
len
(
data
)
>
3
:
raise
Exception
(
"too many values"
)
data
=
list
(
data
)
if
len
(
data
)
<
3
:
data
+=
[
1
,
1
,
1
][
len
(
data
):]
data
+=
[
0
,
0
,
0
]
cleanDate
(
data
)
data
=
data
[:
3
]
else
:
raise
Exception
(
"invalid type"
)
except
Exception
as
e
:
raise
ValueError
(
"invalid %s value - %s"
%
(
self
.
_type
,
e
))
return
tuple
(
data
)
def
_marshalData
(
self
):
if
self
.
_cache
==
None
:
d
=
self
.
_data
s
=
"%04d-%02d-%02dZ"
%
((
abs
(
d
[
0
]),)
+
d
[
1
:])
if
d
[
0
]
<
0
:
s
=
'-'
+
s
self
.
_cache
=
s
return
self
.
_cache
class
gYearMonthType
(
anyType
):
_validURIs
=
(
NS
.
XSD3
,)
def
_checkValueSpace
(
self
,
data
):
try
:
if
data
==
None
:
data
=
time
.
gmtime
(
time
.
time
())[
0
:
2
]
elif
type
(
data
)
in
(
IntType
,
LongType
,
FloatType
):
data
=
time
.
gmtime
(
data
)[
0
:
2
]
elif
type
(
data
)
in
(
ListType
,
TupleType
):
if
len
(
data
)
==
9
:
data
=
data
[
0
:
2
]
elif
len
(
data
)
>
2
:
raise
Exception
(
"too many values"
)
data
=
list
(
data
)
if
len
(
data
)
<
2
:
data
+=
[
1
,
1
][
len
(
data
):]
data
+=
[
1
,
0
,
0
,
0
]
cleanDate
(
data
)
data
=
data
[:
2
]
else
:
raise
Exception
(
"invalid type"
)
except
Exception
as
e
:
raise
ValueError
(
"invalid %s value - %s"
%
(
self
.
_type
,
e
))
return
tuple
(
data
)
def
_marshalData
(
self
):
if
self
.
_cache
==
None
:
d
=
self
.
_data
s
=
"%04d-%02dZ"
%
((
abs
(
d
[
0
]),)
+
d
[
1
:])
if
d
[
0
]
<
0
:
s
=
'-'
+
s
self
.
_cache
=
s
return
self
.
_cache
class
gYearType
(
anyType
):
_validURIs
=
(
NS
.
XSD3
,)
def
_checkValueSpace
(
self
,
data
):
try
:
if
data
==
None
:
data
=
time
.
gmtime
(
time
.
time
())[
0
:
1
]
elif
type
(
data
)
in
(
IntType
,
LongType
,
FloatType
):
data
=
[
data
]
if
type
(
data
)
in
(
ListType
,
TupleType
):
if
len
(
data
)
==
9
:
data
=
data
[
0
:
1
]
elif
len
(
data
)
<
1
:
raise
Exception
(
"too few values"
)
elif
len
(
data
)
>
1
:
raise
Exception
(
"too many values"
)
if
type
(
data
[
0
])
==
FloatType
:
try
:
s
=
int
(
data
[
0
])
except
:
s
=
int
(
data
[
0
])
if
s
!=
data
[
0
]:
raise
Exception
(
"not integral"
)
data
=
[
s
]
elif
type
(
data
[
0
])
not
in
(
IntType
,
LongType
):
raise
Exception
(
"bad type"
)
else
:
raise
Exception
(
"invalid type"
)
except
Exception
as
e
:
raise
ValueError
(
"invalid %s value - %s"
%
(
self
.
_type
,
e
))
return
data
[
0
]
def
_marshalData
(
self
):
if
self
.
_cache
==
None
:
d
=
self
.
_data
s
=
"%04dZ"
%
abs
(
d
)
if
d
<
0
:
s
=
'-'
+
s
self
.
_cache
=
s
return
self
.
_cache
class
centuryType
(
anyType
):
_validURIs
=
(
NS
.
XSD2
,
NS
.
ENC
)
def
_checkValueSpace
(
self
,
data
):
try
:
if
data
==
None
:
data
=
time
.
gmtime
(
time
.
time
())[
0
:
1
]
/
100
elif
type
(
data
)
in
(
IntType
,
LongType
,
FloatType
):
data
=
[
data
]
if
type
(
data
)
in
(
ListType
,
TupleType
):
if
len
(
data
)
==
9
:
data
=
data
[
0
:
1
]
/
100
elif
len
(
data
)
<
1
:
raise
Exception
(
"too few values"
)
elif
len
(
data
)
>
1
:
raise
Exception
(
"too many values"
)
if
type
(
data
[
0
])
==
FloatType
:
try
:
s
=
int
(
data
[
0
])
except
:
s
=
int
(
data
[
0
])
if
s
!=
data
[
0
]:
raise
Exception
(
"not integral"
)
data
=
[
s
]
elif
type
(
data
[
0
])
not
in
(
IntType
,
LongType
):
raise
Exception
(
"bad type"
)
else
:
raise
Exception
(
"invalid type"
)
except
Exception
as
e
:
raise
ValueError
(
"invalid %s value - %s"
%
(
self
.
_type
,
e
))
return
data
[
0
]
def
_marshalData
(
self
):
if
self
.
_cache
==
None
:
d
=
self
.
_data
View remainder of file in raw view
Footer
© 2026 GitHub, Inc.
Footer navigation
Terms
Privacy
Security
Status
Community
Docs
Contact
You can’t perform that action at this time.
Back
|
FazBrowse Home
|
New Git URL