-
Notifications
You must be signed in to change notification settings - Fork 5
/
domhtml.py
1638 lines (1407 loc) · 59.1 KB
/
domhtml.py
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
""" Fully compliant (I think) DOM 2 HTML implementation.
Currently requires pxdom (http://doxdesk.com/software/py/pxdom.html)
Licence (new-BSD-style)
Copyright (C) 2008, Paul Bonser. 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 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.
* The name of the copyright holder may not be used to endorse or
promote products derived from this software without specific prior
written permission.
This software is provided by the copyright holder 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 copyright
owner 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.
"""
# Extend the DOM with DOM 2 HTML, DOM 2 View, and DOM 2 CSS/Style support
#TODO get rid of as much dependence on pxdom as possible for portability between
# DOM implementations in the future
import pxdom as dom
from cssutils import css
import urlparse, string, re
def parseString(str, uri=''):
di = getDOMImplementation()
parser = di.createLSParser(di.MODE_SYNCHRONOUS, None)
input = di.createLSInput()
input.stringData = str
input.systemId= uri
document = HTMLDocument()
parser.parseWithContext(input, document,
parser.ACTION_REPLACE_CHILDREN)
return document
class HTMLDOMImplementation(dom.DOMImplementation):
""" Add the View, HTML, and CSS/Style (not yet implemented) features """
def __init__(self):
self._features['views'] = ['2.0']
self._features['html'] = ['2.0']
self._features['stylesheets'] = ['2.0']
def createDocument(self, namespaceURI, qualifiedName, doctype):
if namespaceURI=='':
namespaceURI= None
document = HTMLDocument()
if doctype is not None:
document.appendChild(doctype)
if qualifiedName is not None:
root = document.createElementNS(namespaceURI, qualifiedName)
document.appendChild(root)
return document
_html_implementation = HTMLDOMImplementation()
def getDOMImplementation(features= ''):
""" DOM 3 Core hook to get the Implementation object. If features is
supplied, only return the implementation if all features are satisfied.
"""
fv = string.split(features, ' ')
for index in range(0, len(fv)-1, 2):
if not _html_implementation.hasFeature(fv[index], fv[index+1]):
return None
return _html_implementation
def getDOMImplementationList(features= ''):
""" DOM 3 Core method to get implementations in a list.
This will be either pxdom's implementation or this extended one
"""
domimplementation = dom.getDOMImplementation(features)
htmldomimplementation = getDOMImplementation(features)
implementationList = DOMImplementationList()
if domimplementation is not None:
implementationList._append(domimplementation)
if htmldomimplementation is not None:
implementationList._append(htmldomimplementation)
implementationList.readonly= True
return implementationList
# Some constants for use below
_KEY = 0
_TYPE = 1
_PERMISSIONS = 2
class DOMObject:
def __init__(self, readonly= False):
self.__dict__['_attr'] = {
'id': ['id', 'string', 'rw'],
'title': ['title', 'string', 'rw'],
'lang': ['lang', 'string', 'rw'],
'dir': ['dir', 'string', 'rw'],
'className': ['class', 'string', 'rw'],
'computed_style': ['_computed_style', 'local_string', 'rw']
}
self._readonly= readonly
self._sub_element = None
def _get_readonly(self):
return self._readonly
def _set_readonly(self, value):
self._readonly= value
def __getattr__(self, key):
attr = self._attr.get(key)
if attr and 'r' in attr[_PERMISSIONS]:
if attr[_TYPE] == 'string':
return self.getAttribute(attr[_KEY])
elif attr[_TYPE] == 'bool':
return self.hasAttribute(attr[_KEY])
elif attr[_TYPE] == 'long':
try:
return int(self.getAttribute(attr[_KEY]))
except ValueError:
return 0
elif attr[_TYPE] == 'local_string':
return self.__dict__[attr[_KEY]]
elif attr[_TYPE] == 'local_bool':
return self.__dict__[attr[_KEY]]
elif attr[_TYPE] == 'local_long':
try:
return int(self.__dict__[attr[_KEY]])
except ValueError:
return 0
else:
return self.getAttribute(attr[_KEY])
if key[:1]=='_':
raise AttributeError, key
try:
getter= getattr(self, '_get_'+key)
except AttributeError:
if self._sub_element:
return getattr(self._sub_element, key)
raise AttributeError, key
return getter()
def __setattr__(self, key, value):
attr = self._attr.get(key)
if attr:
if 'w' in attr[_PERMISSIONS]:
if attr[_TYPE] == 'string':
self.setAttribute(attr[_KEY], value)
elif attr[_TYPE] == 'bool':
if value:
self.setAttribute(attr[_KEY], '')
else:
self.removeAttribute(attr[_KEY])
elif attr[_TYPE] == 'long':
try:
val = int(value)
except ValueError:
val = 0
self.setAttribute(attr[_KEY], val)
elif attr[_TYPE] == 'local_string':
self.__dict__[attr[_KEY]] = value
elif attr[_TYPE] == 'local_bool':
if value:
self.__dict__[attr[_KEY]] = True
else:
self.__dict__[attr[_KEY]] = False
elif attr[_TYPE] == 'local_long':
try:
val = int(value)
except ValueError:
val = 0
self.__dict__[attr[_KEY]] = val
else:
self.setAttribute(attr[_KEY], value)
else:
raise NoModificationAllowedErr(self, key)
if key[:1]=='_' or hasattr(self, key):
self.__dict__[key]= value
return
if self._readonly and key not in ('readonly', 'nodeValue',
'textContent'):
raise NoModificationAllowedErr(self, key)
try:
setter= getattr(self, '_set_'+key)
except AttributeError:
if hasattr(self, '_get_'+key):
raise NoModificationAllowedErr(self, key)
if self._sub_element:
setattr(self._sub_element, key, value)
raise AttributeError, key
setter(value)
class FilterCollection(dom.NodeListByTagName):
""" Works just like NodeListByTagName, but rather than just filtering by
tagName, it takes a list of functions to run the check each node against
"""
def __init__(self, ownerNode, namespaceURI, *checks):
dom.NodeListByTagName.__init__(self, ownerNode, namespaceURI, '')
self._checks = checks
def _walk(self, element):
""" Recursively add a node's child elements to the internal node list
when they match the conditions passed to the constructor
"""
for childNode in element.childNodes:
if childNode.nodeType==dom.Node.ELEMENT_NODE:
passed = True
for check in self._checks:
check_passed = check(childNode)
if not check_passed:
passed = False
if passed:
self._list.append(childNode)
if childNode.nodeType in (dom.Node.ELEMENT_NODE,
dom.Node.ENTITY_REFERENCE_NODE):
self._walk(childNode)
class TableRowCollection(dom.NodeListByTagName):
""" Works like NodeListByTagName, but gets the rows of a table in
logical order
"""
def __init__(self, ownerNode):
dom.NodeListByTagName.__init__(self, ownerNode, dom.NONS, '')
self._checks = checks
def _walk(self, element):
th = element.tHead
if th:
self._list.extend(th.rows)
tbs = element.tBodies
if tbs.length:
for tb in tbs:
self._list.extend(tb.rows)
tf = element.tFoot
if tf:
self._list.extend(tf.rows)
# DOM 2 Views
# -----------
class AbstractView(DOMObject):
""" Implements the DOM View interface """
def __init__(self, document):
DOMObject.__init__(self)
self._document = document
self._readonly = True
def _get_document(self):
return self._document
# DOM 2 HTML
# ----------
class HTMLCollection(DOMObject):
def __init__(self, nodelist, html_mode=False):
DOMObject.__init__(self)
self._nodelist = nodelist
def _get_length(self):
return self._nodelist.length
def item(self, index):
return self._nodelist.item(index)
def namedItem(self, name):
for elem in self._nodelist:
if elem.id == name:
return elem
if html_mode and elem.getAttribute('name') == name:
return elem
# Python-style methods
#
def __len__(self):
return len(self._nodelist)
def __getitem__(self, index):
return self._nodelist[index]
def __setitem__(self, index, value):
raise dom.NoModificationAllowedErr(self, 'item(%s)' % str(index))
def __delitem__(self, index):
raise dom.NoModificationAllowedErr(self, 'item(%s)' % str(index))
class HTMLElement(DOMObject, dom.Element):
def __init__(self, *args, **kwargs):
DOMObject.__init__(self)
dom.Element.__init__(self, *args, **kwargs)
def isSupported(self, feature, version):
return _html_implementation.hasFeature(feature, version)
def getFeature(self, feature, version):
if _html_implementation.hasFeature(feature, version):
return self
return None
class _HTMLDisabledElement(HTMLElement):
def __init__(self, *args, **kwargs):
HTMLElement.__init__(self, *args, **kwargs)
self._disabled = False
def _get_disabled(self):
return self._disabled
def _set_disabled(self, disabled):
self._disabled = disabled
class _HTMLTextElement(HTMLElement):
def _get_text(self):
return self.textContent
def _set_text(self, text):
self.textContent = text
class _HTMLFocusBlurElement(HTMLElement):
def blur(self):
if self.ownerDocument:
self.ownerDocument._handler.element_blur(self)
def focus(self):
if self.ownerDocument:
self.ownerDocument._handler.element_focus(self)
class _HTMLClickElement(HTMLElement):
def click(self):
if self.ownerDocument:
self.ownerDocument._handler.element_click(self)
class _HTMLSelectElement(HTMLElement):
def select(self):
if self.ownerDocument:
self.ownerDocument._handler.element_select(self)
class _HTMLBaseFormElement(HTMLElement):
def _get_form(self):
""" Returns the FORM element containing this control. Returns null if
this control is not within the context of a form. """
parent = self.parentNode
while parent and parent.tagName != 'form':
parent = parent.parentNode
return parent
def _reset(self):
pass
class _HTMLFormControlElement(_HTMLBaseFormElement,_HTMLFocusBlurElement):
def __init__(self, *args, **kwargs):
_HTMLBaseFormElement.__init__(self, *args, **kwargs)
class _HTMLFormValueElement(_HTMLFormControlElement):
""" Base class for form controls where value and defaultValue are attributes
"""
def __init__(self, *args, **kwargs):
_HTMLFormControlElement.__init__(self, *args, **kwargs)
def setAttributeNode(self, attr):
if attr.name == 'value':
self.__dict__['defaultValue'] = attr.value
_HTMLFormControlElement.setAttributeNode(self, attr)
def _reset(self):
""" Basic function to reset form value """
self.value = self.defaultValue
class HTMLHtmlElement(HTMLElement):
def __init__(self, *args, **kwargs):
HTMLElement.__init__(self, *args, **kwargs)
self._attr.update({'version': ['version', 'string', 'rw']})
class HTMLHeadElement(HTMLElement):
def __init__(self, *args, **kwargs):
HTMLElement.__init__(self, *args, **kwargs)
self._attr.update({'profile': ['profile', 'string', 'rw']})
class HTMLLinkElement(_HTMLDisabledElement):
def __init__(self, *args, **kwargs):
_HTMLDisabledElement.__init__(self, *args, **kwargs)
self._attr.update({
# DOM HTML Attributes
'charset': ['charset', 'string', 'rw'],
'href': ['href', 'string', 'rw'],
'hreflang': ['hreflang', 'string', 'rw'],
'media': ['media', 'string', 'rw'],
'rel': ['rel', 'string', 'rw'],
'rev': ['rev', 'string', 'rw'],
'target': ['target', 'string', 'rw'],
'type': ['type', 'string', 'rw']
})
if self.getAttribute('rel') == 'stylesheet':
self._attr.update({'sheet': ['_sheet', 'local_string', 'r']})
if self.getAttribute('type') == 'text/css':
self._sheet = CSSStyleSheet(self)
else:
self._sheet = StyleSheet(self)
class HTMLTitleElement(_HTMLTextElement):
pass
class HTMLMetaElement(HTMLElement):
def __init__(self, *args, **kwargs):
HTMLElement.__init__(self, *args, **kwargs)
self._attr.update({
'content': ['content', 'string', 'rw'],
'httpEquiv': ['http-equiv', 'string', 'rw'],
'name': ['name', 'string', 'rw'],
'scheme': ['scheme', 'string', 'rw']
})
class HTMLBaseElement(HTMLElement):
def __init__(self, *args, **kwargs):
HTMLElement.__init__(self, *args, **kwargs)
self._attr.update({
'href': ['href', 'string', 'rw'],
'target': ['target', 'string', 'rw'],
})
class HTMLIsIndexElement(_HTMLBaseFormElement):
def __init__(self, *args, **kwargs):
_HTMLBaseFormElement.__init__(self, *args, **kwargs)
self._attr.update({'prompt': ['prompt', 'string', 'rw']})
class HTMLStyleElement(_HTMLDisabledElement):
def __init__(self, *args, **kwargs):
_HTMLDisabledElement.__init__(self, *args, **kwargs)
self._attr.update({
'media': ['media', 'string', 'rw'],
'type': ['type', 'string', 'rw'],
# DOM StyleSheet Attributes
'sheet': ['_sheet', 'local_string', 'r']
})
self._sheet = StyleSheet(self)
class HTMLBodyElement(HTMLElement):
def __init__(self, *args, **kwargs):
HTMLElement.__init__(self, *args, **kwargs)
self._attr.update({
'aLink': ['alink', 'string', 'rw'],
'background': ['background', 'string', 'rw'],
'bgColor': ['bgcolor', 'string', 'rw'],
'link': ['link', 'string', 'rw'],
'text': ['text', 'string', 'rw'],
'vLink': ['vlink', 'string', 'rw'],
})
class HTMLFormElement(HTMLElement):
def __init__(self, *args, **kwargs):
HTMLElement.__init__(self, *args, **kwargs)
self._attr.update({
'name': ['name', 'string', 'rw'],
'acceptCharset': ['accept-charset', 'string', 'rw'],
'action': ['action', 'string', 'rw'],
'enctype': ['enctype', 'string', 'rw'],
'method': ['method', 'string', 'rw'],
'target': ['target', 'string', 'rw']
})
def _get_elements(self):
""" Returns a collection of all form control elements in the form. """
return HTMLCollection(
FilterCollection(self, dom.NONS,
lambda node: node.tagName in
('input', 'button', 'select', 'optgroup',
'option', 'textarea', 'isindex', 'fieldset'))
)
def _get_length(self):
return self.elements.length
def submit(self):
if self.ownerDocument:
self.ownerDocument._event.form_submit(self)
def reset(self):
for element in self.elements:
element._reset()
class HTMLSelectElement(_HTMLFormControlElement):
def __init__(self, *args, **kwargs):
_HTMLFormControlElement.__init__(self, *args, **kwargs)
self._attr.update({
'name': ['name', 'string', 'rw'],
'disabled': ['disabled', 'bool', 'rw'],
'multiple': ['multiple', 'bool', 'rw'],
'size': ['size', 'long', 'rw'],
'tabIndex': ['tabindex', 'long', 'rw']
})
def _get_type(self):
if self.muliple:
return 'select-multiple'
return 'select-one'
def _get_selectedIndex(self):
options = self.options
for i in range(0, self.options.length):
if options[i].selected: return i
return -1
def _set_selectedIndex(self, index):
options = self.options
for option in options:
option.selected = False
options[index].selected = True
def _get_value(self):
si = self.selectedIndex
if si != -1:
return self.options[si].value
else: return ''
def _set_value(self, value):
pass
def _get_length(self):
return self.options.length
def _get_options(self):
return self.getElementsByTagName('option')
def _get_multiple(self):
return self.hasAttribute('multiple')
def _set_multiple(self, multiple):
if multiple:
self.setAttribute('multiple', '')
else:
self.removeAttribute('multiple')
def add(self, element, before):
if element.tagName not in ('option', 'optgroup'):
return
if before:
self.insertBefore(element, before)
else:
self.appendChild(element)
def remove(self, index):
option = self.options.item(index)
if option:
self.removeChild(option)
class HTMLOptGroupElement(HTMLElement):
def __init__(self, *args, **kwargs):
HTMLElement.__init__(self, *args, **kwargs)
self._attr.update({
'disabled': ['disabled', 'bool', 'rw'],
'label': ['label', 'string', 'rw'],
})
class HTMLOptionElement(_HTMLBaseFormElement,_HTMLTextElement):
def __init__(self, *args, **kwargs):
_HTMLBaseFormElement.__init__(self, *args, **kwargs)
self.defaultSelected = self.hasAttribute('selected')
self._selected = self.defaultSelected
self._attr.update({
'disabled': ['disabled', 'bool', 'rw'],
'label': ['label', 'string', 'rw'],
})
def _reset(self):
self.selected = self.defaultSelected
def _set_text(self, text):
raise NoModificationAllowedErr(self, 'text')
def _get_index(self):
parent = self.parentNode
while parent and parent.tagName != 'select':
parent = parent.parentNode
if parent:
options = parent.options
for i in range(parent.length):
if options[i] is self:
return i
return None
def _get_selected(self):
return self._selected
def _set_selected(self, selected):
if selected:
self._selected = True
else:
self._selected = False
def _get_value(self):
val = self.getAttributeNode('value')
if val:
return val.value
return self.text
def _set_value(self, value):
self.setAttributeNode('value', value)
class HTMLInputElement(_HTMLFormValueElement,_HTMLFocusBlurElement,
_HTMLClickElement,_HTMLSelectElement):
def __init__(self, *args, **kwargs):
_HTMLFormValueElement.__init__(self, *args, **kwargs)
self._attr.update({
'accept': ['accept', 'string', 'rw'],
'accessKey': ['accesskey', 'string', 'rw'],
'align': ['align', 'string', 'rw'],
'alt': ['alt', 'string', 'rw'],
'checked': ['_checked', 'local_bool', 'rw'],
'disabled': ['disabled', 'bool', 'rw'],
'maxLength': ['maxlength', 'long', 'rw'],
'name': ['name', 'string', 'rw'],
'readOnly': ['readonly', 'boolean', 'rw'],
'size': ['size', 'long', 'rw'],
'src': ['src', 'string', 'rw'],
'tabIndex': ['tabindex', 'long', 'rw'],
'type': ['type', 'string', 'rw'],
'useMap': ['usemap', 'string', 'rw'],
'value': ['_value', 'local_string', 'rw']
})
self.__dict__['defaultChecked'] = False
self.__dict__['_checked'] = False
def _reset(self):
_HTMLFormValueElement._reset(self)
self.checked = self.defaultChecked
_attrs_to_catch = {
'value': ('_value',),
'checked': ('_checked', 'defaultChecked')
}
def setAttributeNode(self, attr):
tc = self._attrs_to_catch.get(attr.name, None)
if tc:
for item in tc:
self.__dict__[item] = attr.value
_HTMLFormValueElement.setAttributeNode(self, attr)
class HTMLTextAreaElement(_HTMLFormControlElement,_HTMLFocusBlurElement,
_HTMLSelectElement):
def __init__(self, *args, **kwargs):
_HTMLFormControlElement.__init__(self, *args, **kwargs)
self.defaultValue = self.textContent
self.value = self.defaultValue
self._attr.update({
'accessKey': ['accesskey', 'string', 'rw'],
'cols': ['cols', 'long', 'rw'],
'disabled': ['disabled', 'bool', 'rw'],
'name': ['name', 'string', 'rw'],
'readOnly': ['readonly', 'boolean', 'rw'],
'rows': ['rows', 'long', 'rw'],
'tabIndex': ['tabindex', 'long', 'rw'],
'type': ['type', 'string', 'rw'],
})
def _reset(self):
""" Basic function to reset form value """
self.value = self.defaultValue
def _get_type(self):
return 'textarea'
class HTMLButtonElement(_HTMLBaseFormElement):
def __init__(self, *args, **kwargs):
_HTMLBaseFormElement.__init__(self, *args, **kwargs)
self._attr.update({
'accessKey': ['accesskey', 'string', 'rw'],
'disabled': ['disabled', 'bool', 'rw'],
'name': ['name', 'string', 'rw'],
'tabIndex': ['tabindex', 'long', 'rw'],
'type': ['type', 'string', 'r'],
'value': ['value', 'string', 'rw']
})
class HTMLLabelElement(_HTMLBaseFormElement):
def __init__(self, *args, **kwargs):
_HTMLBaseFormElement.__init__(self, *args, **kwargs)
self._attr.update({
'accessKey': ['accesskey', 'string', 'rw'],
'htmlFor': ['for', 'string', 'rw']
})
class HTMLFieldSetElement(_HTMLBaseFormElement):pass
class HTMLLegendElement(_HTMLBaseFormElement):
def __init__(self, *args, **kwargs):
_HTMLBaseFormElement.__init__(self, *args, **kwargs)
self._attr.update({
'accessKey': ['accesskey', 'string', 'rw'],
'align': ['align', 'string', 'rw']
})
class HTMLULstElement(HTMLElement):
def __init__(self, *args, **kwargs):
HTMLElement.__init__(self, *args, **kwargs)
self._attr.update({
'compact': ['compact', 'bool', 'rw'],
'type': ['type', 'string', 'rw']
})
class HTMLOLstElement(HTMLElement):
def __init__(self, *args, **kwargs):
HTMLElement.__init__(self, *args, **kwargs)
self._attr.update({
'compact': ['compact', 'bool', 'rw'],
'start': ['start', 'long', 'rw'],
'type': ['type', 'string', 'rw']
})
class HTMLDListElement(HTMLElement):
def __init__(self, *args, **kwargs):
HTMLElement.__init__(self, *args, **kwargs)
self._attr.update({'compact': ['compact', 'bool', 'rw']})
class HTMLDirectoryElement(HTMLElement):
def __init__(self, *args, **kwargs):
HTMLElement.__init__(self, *args, **kwargs)
self._attr.update({'compact': ['compact', 'bool', 'rw']})
class HTMLMenuElement(HTMLElement):
def __init__(self, *args, **kwargs):
HTMLElement.__init__(self, *args, **kwargs)
self._attr.update({'compact': ['compact', 'bool', 'rw']})
class HTMLLIElement(HTMLElement):
def __init__(self, *args, **kwargs):
HTMLElement.__init__(self, *args, **kwargs)
self._attr.update({
'type': ['type', 'string', 'rw'],
'value': ['value', 'long', 'rw']
})
class HTMLDivElement(HTMLElement):
def __init__(self, *args, **kwargs):
HTMLElement.__init__(self, *args, **kwargs)
self._attr.update({'align': ['align', 'string', 'rw']})
class HTMLParagraphElement(HTMLElement):
def __init__(self, *args, **kwargs):
HTMLElement.__init__(self, *args, **kwargs)
self._attr.update({'align': ['align', 'string', 'rw']})
class HTMLHeadingElement(HTMLElement):
def __init__(self, *args, **kwargs):
HTMLElement.__init__(self, *args, **kwargs)
self._attr.update({'align': ['align', 'string', 'rw']})
class HTMLQuoteElement(HTMLElement):
def __init__(self, *args, **kwargs):
HTMLElement.__init__(self, *args, **kwargs)
self._attr.update({'cite': ['cite', 'string', 'rw']})
class HTMLPreElement(HTMLElement):
def __init__(self, *args, **kwargs):
HTMLElement.__init__(self, *args, **kwargs)
self._attr.update({'width': ['width', 'long', 'rw']})
class HTMLBRElement(HTMLElement):
def __init__(self, *args, **kwargs):
HTMLElement.__init__(self, *args, **kwargs)
self._attr.update({'clear': ['clear', 'string', 'rw']})
class HTMLBaseFontElement(HTMLElement):
def __init__(self, *args, **kwargs):
HTMLElement.__init__(self, *args, **kwargs)
self._attr.update({
'color': ['color', 'string', 'rw'],
'face': ['face', 'string', 'rw'],
'size': ['size', 'long', 'rw']
})
class HTMLFontElement(HTMLBaseFontElement):pass
class HTMLHRElement(HTMLElement):
def __init__(self, *args, **kwargs):
HTMLElement.__init__(self, *args, **kwargs)
self._attr.update({
'align': ['align', 'string', 'rw'],
'noShade': ['noshade', 'boolean', 'rw'],
'size': ['size', 'string', 'rw'],
'width': ['width', 'string', 'rw']
})
class HTMLModElement(HTMLElement):
def __init__(self, *args, **kwargs):
HTMLElement.__init__(self, *args, **kwargs)
self._attr.update({
'cite': ['cite', 'string', 'rw'],
'dateTime': ['datetime', 'string', 'rw']
})
class HTMLAnchorElement(_HTMLFocusBlurElement):
def __init__(self, *args, **kwargs):
_HTMLFocusBlurElement.__init__(self, *args, **kwargs)
self._attr.update({
'accessKey': ['accesskey', 'string', 'rw'],
'charset': ['charset', 'string', 'rw'],
'coords': ['coords', 'string', 'rw'],
'href': ['href', 'string', 'rw'],
'hreflang': ['hreflang', 'string', 'rw'],
'name': ['name', 'string', 'rw'],
'rel': ['rel', 'string', 'rw'],
'rev': ['rev', 'string', 'rw'],
'shape': ['shape', 'string', 'rw'],
'tabIndex': ['tabindex', 'long', 'rw'],
'target': ['target', 'string', 'rw'],
'type': ['type', 'string', 'rw']
})
class HTMLImageElement(HTMLElement):
def __init__(self, *args, **kwargs):
HTMLElement.__init__(self, *args, **kwargs)
self._attr.update({
'name': ['name', 'string', 'rw'],
'align': ['align', 'string', 'rw'],
'alt': ['alt', 'string', 'rw'],
'border': ['border', 'string', 'rw'],
'height': ['height', 'long', 'rw'],
'hspace': ['hspace', 'long', 'rw'],
'isMap': ['ismap', 'bool', 'rw'],
'longDesc': ['longdesc', 'string', 'rw'],
'src': ['src', 'string', 'rw'],
'useMap': ['usemap', 'string', 'rw'],
'vspace': ['vspace', 'long', 'rw'],
'width': ['width', 'long', 'rw']
})
class HTMLObjectElement(_HTMLBaseFormElement):
def __init__(self, *args, **kwargs):
_HTMLBaseFormElement.__init__(self, *args, **kwargs)
self._attr.update({
'code': ['code', 'string', 'rw'],
'align': ['align', 'string', 'rw'],
'archive': ['archive', 'string', 'rw'],
'border': ['border', 'string', 'rw'],
'codeBase': ['codebase', 'string', 'rw'],
'codeType': ['codetype', 'string', 'rw'],
'data': ['data', 'string', 'rw'],
'declare': ['declare', 'bool', 'rw'],
'height': ['height', 'string', 'rw'],
'hspace': ['hspace', 'long', 'rw'],
'name': ['name', 'string', 'rw'],
'standby': ['standby', 'string', 'rw'],
'tabIndex': ['tabindex', 'long', 'rw'],
'type': ['type', 'string', 'rw'],
'useMap': ['usemap', 'string', 'rw'],
'vspace': ['vspace', 'long', 'rw'],
'width': ['width', 'long', 'rw']
})
self._contentDocument = None
def _get_contentDocument(self):
return self._contentDocument
class HTMLParamElement(HTMLElement):
def __init__(self, *args, **kwargs):
HTMLElement.__init__(self, *args, **kwargs)
self._attr.update({
'name': ['name', 'string', 'rw'],
'type': ['type', 'string', 'rw'],
'value': ['value', 'string', 'rw'],
'valueType': ['valuetype', 'string', 'rw']
})
class HTMLAppletElement (HTMLElement):
def __init__(self, *args, **kwargs):
_HTMLBaseFormElement.__init__(self, *args, **kwargs)
self._attr.update({
'align': ['align', 'string', 'rw'],
'alt': ['alt', 'string', 'rw'],
'archive': ['archive', 'string', 'rw'],
'code': ['code', 'string', 'rw'],
'codeBase': ['codebase', 'string', 'rw'],
'height': ['height', 'string', 'rw'],
'hspace': ['hspace', 'long', 'rw'],
'name': ['name', 'string', 'rw'],
'object': ['object', 'string', 'rw'],
'vspace': ['vspace', 'long', 'rw'],
'width': ['width', 'long', 'rw']
})
class HTMLMapElement(HTMLElement):
def __init__(self, *args, **kwargs):
HTMLElement.__init__(self, *args, **kwargs)
self._attr.update({'name': ['name', 'string', 'rw']})
def _get_areas(self):
return self.getElementsByTagName('area')
class HTMLAreaElement(HTMLElement):
def __init__(self, *args, **kwargs):
HTMLElement.__init__(self, *args, **kwargs)
self._attr.update({
'accessKey': ['accesskey', 'string', 'rw'],
'alt': ['alt', 'string', 'rw'],
'coords': ['coords', 'string', 'rw'],
'href': ['href', 'string', 'rw'],
'noHref': ['nohref', 'bool', 'rw'],
'shape': ['shape', 'string', 'rw'],
'tabIndex': ['tabindex', 'long', 'rw'],
'target': ['target', 'string', 'rw']
})
class HTMLScriptElement(HTMLElement):
def __init__(self, *args, **kwargs):
HTMLElement.__init__(self, *args, **kwargs)
self._attr.update({
'text': ['text', 'string', 'rw'],
'htmlFor': ['for', 'string', 'rw'],
'event': ['event', 'string', 'rw'],
'charset': ['charset', 'string', 'rw'],
'defer': ['defer', 'bool', 'rw'],
'src': ['src', 'string', 'rw'],
'type': ['type', 'string', 'rw']
})
class HTMLTableElement(HTMLElement):
def __init__(self, *args, **kwargs):
HTMLElement.__init__(self, *args, **kwargs)
self._attr.update({
'align': ['align', 'string', 'rw'],
'bgColor': ['bgcolor', 'string', 'rw'],
'border': ['border', 'string', 'rw'],
'cellPadding': ['cellpadding', 'string', 'rw'],
'cellSpacing': ['cellspacing', 'bool', 'rw'],
'frame': ['frame', 'string', 'rw'],
'rules': ['rules', 'string', 'rw'],
'summary': ['summary', 'string', 'rw'],
'width': ['width', 'string', 'rw']
})
def _get_caption(self):
caps = self.getElementsByTagName('caption')
if caps.length > 0:
return caps[0]
return None
def _set_caption(self, cap):
if cap.tagName != 'caption':
raise HierarchyRequestErr(self, cap)
oldcap = self.caption
if oldcap:
self.replaceChild(cap, oldcap)
else:
self.appendChild(cap)
def _get_tHead(self):
ths = self.getElementsByTagName('thead')
if ths.length > 0:
return ths[0]
return None
def _set_tHead(self, th):
if th.tagName != 'thead':
raise HierarchyRequestErr(self, th)
oldth = self.tHead
if oldth:
self.replaceChild(th, oldth)
else:
self.appendChild(th)
def _get_tFoot(self):
tfs = self.getElementsByTagName('tfoot')
if tfs.length > 0:
return tfs[0]
return None
def _set_tFoot(self, tf):
if tf.tagName != 'tfoot':
raise HierarchyRequestErr(self, tf)
oldtf = self.tFoot
if oldtf:
self.replaceChild(tf, oldtf)
else:
self.appendChild(tf)
def _get_rows(self):
return HTMLCollection(TableRowCollection(self))
def _get_tBodies(self):
return self.getElementsByTagName('tbody')
def createTHead(self):
th = self.tHead
if th:
return th
th = self.ownerDocument.createElement('thead')
self.insertBefore(th, self.firstChild)
return th
def deleteTHead(self):
th = self.tHead