-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebForms.py
More file actions
2011 lines (1550 loc) · 77.1 KB
/
WebForms.py
File metadata and controls
2011 lines (1550 loc) · 77.1 KB
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
# WebForms.py 2.0 - The Back-End Part of WebForms Core Technology, Owned by Elanat (https://elanat.net)
# Compatible with WebFormsJS version 2.0
import re
import time
from typing import Optional, List, Union
class WebForms:
def __init__(self):
self.web_forms_data = []
def _add(self, name: str, value: str = ""):
if value:
self.web_forms_data.append(f"{name}={value}")
else:
self.web_forms_data.append(name)
def _get_line_by_index(self, index: int) -> str:
if not self.web_forms_data or index >= len(self.web_forms_data):
return ""
if index < 0:
index = len(self.web_forms_data) + index
if index < 0 or index >= len(self.web_forms_data):
return ""
return self.web_forms_data[index]
def _update_line_by_index(self, index: int, name: str, value: str = ""):
if not self.web_forms_data or index >= len(self.web_forms_data):
return
if index < 0:
index = len(self.web_forms_data) + index
if index < 0 or index >= len(self.web_forms_data):
return
if value:
self.web_forms_data[index] = f"{name}={value}"
else:
self.web_forms_data[index] = name
# For Extension
def add_line(self, name: str, value: str):
self._add(name, value)
# Add
def add_id(self, input_place: str, element_id: str):
self._add(f"ai{input_place}", element_id)
def add_name(self, input_place: str, name: str):
self._add(f"an{input_place}", name)
def add_value(self, input_place: str, value: str):
self._add(f"av{input_place}", value)
def add_class(self, input_place: str, class_name: str):
self._add(f"ac{input_place}", class_name)
def add_style(self, input_place: str, style: str):
self._add(f"as{input_place}", style)
def add_style_property(self, input_place: str, name: str, value: str):
self._add(f"as{input_place}", f"{name}:{value}")
def add_option_tag(self, input_place: str, text: str, value: str, selected: bool = False):
self._add(f"ao{input_place}", f"{value}|{text}" + ("|1" if selected else ""))
def add_checkbox_tag(self, input_place: str, text: str, value: str, checked: bool = False):
self._add(f"ak{input_place}", f"{value}|{text}" + ("|1" if checked else ""))
def add_title(self, input_place: str, title: str):
self._add(f"al{input_place}", title)
def add_label(self, input_place: str, label: str):
self._add(f"aA{input_place}", label)
def add_text(self, input_place: str, text: str):
self._add(f"at{input_place}", text.replace('\n', '$[ln];'))
def add_text_to_up(self, input_place: str, text: str):
self._add(f"pt{input_place}", text.replace('\n', '$[ln];'))
def add_attribute(self, input_place: str, attribute: str, value: str = "", splitter: str = '\0'):
splitter_str = splitter if splitter != '\0' else ""
self._add(f"aa{input_place}", f"{attribute}|{splitter_str}" + (f"|{value}" if value else ""))
def add_tag(self, input_place: str, tag_name: str, element_id: str = ""):
self._add(f"nt{input_place}", tag_name + (f"|{element_id}" if element_id else ""))
def add_tag_to_up(self, input_place: str, tag_name: str, element_id: str = ""):
self._add(f"ut{input_place}", tag_name + (f"|{element_id}" if element_id else ""))
def add_tag_before(self, input_place: str, tag_name: str, element_id: str = ""):
self._add(f"bt{input_place}", tag_name + (f"|{element_id}" if element_id else ""))
def add_tag_after(self, input_place: str, tag_name: str, element_id: str = ""):
self._add(f"ft{input_place}", tag_name + (f"|{element_id}" if element_id else ""))
def add_hidden(self, input_place: str, value: str, element_id: str = ""):
self._add(f"ah{input_place}", value + (f"|{element_id}" if element_id else ""))
# Set
def set_id(self, input_place: str, element_id: str):
self._add(f"si{input_place}", element_id)
def set_name(self, input_place: str, name: str):
self._add(f"sn{input_place}", name)
def set_value(self, input_place: str, value: str):
self._add(f"sv{input_place}", value)
def set_class(self, input_place: str, class_name: str):
self._add(f"sc{input_place}", class_name)
def set_style(self, input_place: str, style: str):
self._add(f"ss{input_place}", style)
def set_style_property(self, input_place: str, name: str, value: str):
self._add(f"ss{input_place}", f"{name}:{value}")
def set_option_tag(self, input_place: str, text: str, value: str, selected: bool = False):
self._add(f"so{input_place}", f"{value}|{text}" + ("|1" if selected else ""))
def set_checked(self, input_place: str, checked: bool = False):
self._add(f"sk{input_place}", "1" if checked else "0")
def set_checkbox_tag(self, input_place: str, text: str, value: str, checked: bool = False):
self._add(f"sk{input_place}", f"{value}|{text}" + ("|1" if checked else ""))
def set_title(self, input_place: str, title: str):
self._add(f"sl{input_place}", title)
def set_label(self, input_place: str, label: str):
self._add(f"sA{input_place}", label)
def set_text(self, input_place: str, text: str):
self._add(f"st{input_place}", text.replace('\n', '$[ln];'))
def set_attribute(self, input_place: str, attribute: str, value: str = ""):
self._add(f"sa{input_place}", f"{attribute}" + (f"|{value}" if value else ""))
def set_width(self, input_place: str, width: Union[str, int]):
if isinstance(width, int):
width = f"{width}px"
self._add(f"sw{input_place}", width)
def set_height(self, input_place: str, height: Union[str, int]):
if isinstance(height, int):
height = f"{height}px"
self._add(f"sh{input_place}", height)
def set_background_color(self, input_place: str, color: str):
self._add(f"bc{input_place}", color)
def set_text_color(self, input_place: str, color: str):
self._add(f"tc{input_place}", color)
def set_font_name(self, input_place: str, name: str):
self._add(f"fn{input_place}", name)
def set_font_size(self, input_place: str, size: Union[str, int]):
if isinstance(size, int):
size = f"{size}px"
self._add(f"fs{input_place}", size)
def set_font_bold(self, input_place: str, bold: bool):
self._add(f"fb{input_place}", "1" if bold else "0")
def set_visible(self, input_place: str, visible: bool):
self._add(f"vi{input_place}", "1" if visible else "0")
def set_text_align(self, input_place: str, align: str):
self._add(f"ta{input_place}", align)
def set_read_only(self, input_place: str, read_only: bool):
self._add(f"sr{input_place}", "1" if read_only else "0")
def set_disabled(self, input_place: str, disabled: bool):
self._add(f"sd{input_place}", "1" if disabled else "0")
def set_focus(self, input_place: str, focus: bool):
self._add(f"sf{input_place}", "1" if focus else "0")
def set_min_length(self, input_place: str, length: int):
self._add(f"mn{input_place}", str(length))
def set_max_length(self, input_place: str, length: int):
self._add(f"mx{input_place}", str(length))
def set_selected_value(self, input_place: str, value: str):
self._add(f"ts{input_place}", value)
def set_selected_index(self, input_place: str, index: int):
self._add(f"ti{input_place}", str(index))
def set_checked_value(self, input_place: str, value: str, selected: bool):
self._add(f"ks{input_place}", f"{value}|{'1' if selected else '0'}")
def set_checked_index(self, input_place: str, index: int, selected: bool):
self._add(f"ki{input_place}", f"{index}|{'1' if selected else '0'}")
# Insert
def insert_id(self, input_place: str, element_id: str):
self._add(f"ii{input_place}", element_id)
def insert_name(self, input_place: str, name: str):
self._add(f"in{input_place}", name)
def insert_value(self, input_place: str, value: str):
self._add(f"iv{input_place}", value)
def insert_class(self, input_place: str, class_name: str):
self._add(f"ic{input_place}", class_name)
def insert_style(self, input_place: str, style: str):
self._add(f"is{input_place}", style)
def insert_style_property(self, input_place: str, name: str, value: str):
self._add(f"is{input_place}", f"{name}:{value}")
def insert_option_tag(self, input_place: str, text: str, value: str, selected: bool = False):
self._add(f"io{input_place}", f"{value}|{text}" + ("|1" if selected else ""))
def insert_checkbox_tag(self, input_place: str, text: str, value: str, checked: bool = False):
self._add(f"ik{input_place}", f"{value}|{text}" + ("|1" if checked else ""))
def insert_title(self, input_place: str, title: str):
self._add(f"il{input_place}", title)
def insert_label(self, input_place: str, label: str):
self._add(f"iA{input_place}", label)
def insert_text(self, input_place: str, text: str):
self._add(f"it{input_place}", text.replace('\n', '$[ln];'))
def insert_attribute(self, input_place: str, attribute: str, value: str = "", splitter: str = '\0'):
splitter_str = splitter if splitter != '\0' else ""
self._add(f"ia{input_place}", f"{attribute}|{splitter_str}" + (f"|{value}" if value else ""))
# Delete
def delete_id(self, input_place: str):
self._add(f"di{input_place}")
def delete_name(self, input_place: str):
self._add(f"dn{input_place}")
def delete_value(self, input_place: str):
self._add(f"dv{input_place}")
def delete_class(self, input_place: str, class_name: str):
self._add(f"dc{input_place}", class_name)
def delete_style(self, input_place: str, style_name: str):
self._add(f"ds{input_place}", style_name)
def delete_option_tag(self, input_place: str, value: str):
self._add(f"do{input_place}", value)
def delete_all_option_tag(self, input_place: str):
self._add(f"do{input_place}", "*")
def delete_checkbox_tag(self, input_place: str, value: str):
self._add(f"dk{input_place}", value)
def delete_all_checkbox_tag(self, input_place: str):
self._add(f"dk{input_place}", "*")
def delete_title(self, input_place: str):
self._add(f"dl{input_place}")
def delete_label(self, input_place: str):
self._add(f"dA{input_place}")
def delete_text(self, input_place: str):
self._add(f"dt{input_place}")
def delete_attribute(self, input_place: str, attribute: str):
self._add(f"da{input_place}", attribute)
def delete(self, input_place: str):
self._add(f"de{input_place}")
def delete_parent(self, input_place: str):
self._add(f"dp{input_place}")
# Tag
def swap_tag(self, input_place: str, output_place: str):
self._add(f"sp{input_place}", output_place)
def set_reflection(self, input_place: str, tag: str):
self._add(f"sR{input_place}", tag)
def set_reflection_by_output_place(self, input_place: str, output_place: str):
self._add(f"iR{input_place}", output_place)
# Browser
def change_url(self, url: str):
self._add("cu", url)
def set_head_title(self, title: str):
self._add("ht", title)
def clipboard_write_text(self, text: str):
self._add("nw", text)
def scroll_to(self, x: int, y: int):
self._add("ws", f"{x}|{y}")
def history_go(self, steps: int):
self._add("wg", str(steps))
def reload_page(self):
self._add("lr")
def redirect(self, path: str):
self._add("lh", path)
# Increase
def increase_min_length(self, input_place: str, value: int):
self._add(f"+n{input_place}", str(value))
def increase_max_length(self, input_place: str, value: int):
self._add(f"+x{input_place}", str(value))
def increase_font_size(self, input_place: str, value: int):
self._add(f"+f{input_place}", str(value))
def increase_width(self, input_place: str, value: int):
self._add(f"+w{input_place}", str(value))
def increase_height(self, input_place: str, value: int):
self._add(f"+h{input_place}", str(value))
def increase_value(self, input_place: str, value: int):
self._add(f"+v{input_place}", str(value))
# Decrease
def decrease_min_length(self, input_place: str, value: int):
self._add(f"-n{input_place}", str(value))
def decrease_max_length(self, input_place: str, value: int):
self._add(f"-x{input_place}", str(value))
def decrease_font_size(self, input_place: str, value: int):
self._add(f"-f{input_place}", str(value))
def decrease_width(self, input_place: str, value: int):
self._add(f"-w{input_place}", str(value))
def decrease_height(self, input_place: str, value: int):
self._add(f"-h{input_place}", str(value))
def decrease_value(self, input_place: str, value: int):
self._add(f"-v{input_place}", str(value))
# Event
def trigger_event(self, input_place: str, html_event_listener: str, constructor_name: Optional[str] = None):
value = html_event_listener
if constructor_name:
value += f"|{constructor_name}"
self._add(f"TE{input_place}", value)
def set_post_event(self, input_place: str, html_event: str):
self._add(f"Ep{input_place}", html_event)
def set_post_event_view(self, input_place: str, html_event: str):
self._add(f"Ep{input_place}", f"{html_event}|+")
def set_post_event_to(self, input_place: str, html_event: str, output_place: str):
self._add(f"Ep{input_place}", f"{html_event}|{output_place}")
def set_post_event_listener(self, input_place: str, html_event_listener: str):
self._add(f"EP{input_place}", html_event_listener)
def set_post_event_listener_view(self, input_place: str, html_event_listener: str):
self._add(f"EP{input_place}", f"{html_event_listener}|+")
def set_post_event_listener_to(self, input_place: str, html_event_listener: str, output_place: str):
self._add(f"EP{input_place}", f"{html_event_listener}|{output_place}")
def set_get_event(self, input_place: str, html_event: str, path: Optional[str] = None, output_place: Optional[str] = None):
path_str = path if path else "#"
if output_place:
self._add(f"Eg{input_place}", f"{html_event}|{path_str}|{output_place}")
else:
self._add(f"Eg{input_place}", f"{html_event}|{path_str}")
def set_get_event_listener(self, input_place: str, html_event_listener: str, path: Optional[str] = None, output_place: Optional[str] = None):
path_str = path if path else "#"
if output_place:
self._add(f"EG{input_place}", f"{html_event_listener}|{path_str}|{output_place}")
else:
self._add(f"EG{input_place}", f"{html_event_listener}|{path_str}")
def set_patch_event(self, input_place: str, html_event: str, path: Optional[str] = None, output_place: Optional[str] = None):
path_str = path if path else "#"
if output_place:
self._add(f"Ea{input_place}", f"{html_event}|{path_str}|{output_place}")
else:
self._add(f"Ea{input_place}", f"{html_event}|{path_str}")
def set_patch_event_listener(self, input_place: str, html_event_listener: str, path: Optional[str] = None, output_place: Optional[str] = None):
path_str = path if path else "#"
if output_place:
self._add(f"EA{input_place}", f"{html_event_listener}|{path_str}|{output_place}")
else:
self._add(f"EA{input_place}", f"{html_event_listener}|{path_str}")
def set_delete_event(self, input_place: str, html_event: str, path: Optional[str] = None, output_place: Optional[str] = None):
path_str = path if path else "#"
if output_place:
self._add(f"El{input_place}", f"{html_event}|{path_str}|{output_place}")
else:
self._add(f"El{input_place}", f"{html_event}|{path_str}")
def set_delete_event_listener(self, input_place: str, html_event_listener: str, path: Optional[str] = None, output_place: Optional[str] = None):
path_str = path if path else "#"
if output_place:
self._add(f"EL{input_place}", f"{html_event_listener}|{path_str}|{output_place}")
else:
self._add(f"EL{input_place}", f"{html_event_listener}|{path_str}")
def set_options_event(self, input_place: str, html_event: str, path: Optional[str] = None, output_place: Optional[str] = None):
path_str = path if path else "#"
if output_place:
self._add(f"Eo{input_place}", f"{html_event}|{path_str}|{output_place}")
else:
self._add(f"Eo{input_place}", f"{html_event}|{path_str}")
def set_options_event_listener(self, input_place: str, html_event_listener: str, path: Optional[str] = None, output_place: Optional[str] = None):
path_str = path if path else "#"
if output_place:
self._add(f"EO{input_place}", f"{html_event_listener}|{path_str}|{output_place}")
else:
self._add(f"EO{input_place}", f"{html_event_listener}|{path_str}")
def set_trace_event(self, input_place: str, html_event: str, path: Optional[str] = None, output_place: Optional[str] = None):
path_str = path if path else "#"
if output_place:
self._add(f"Er{input_place}", f"{html_event}|{path_str}|{output_place}")
else:
self._add(f"Er{input_place}", f"{html_event}|{path_str}")
def set_trace_event_listener(self, input_place: str, html_event_listener: str, path: Optional[str] = None, output_place: Optional[str] = None):
path_str = path if path else "#"
if output_place:
self._add(f"ER{input_place}", f"{html_event_listener}|{path_str}|{output_place}")
else:
self._add(f"ER{input_place}", f"{html_event_listener}|{path_str}")
def set_connect_event(self, input_place: str, html_event: str, path: Optional[str] = None, output_place: Optional[str] = None):
path_str = path if path else "#"
if output_place:
self._add(f"Ec{input_place}", f"{html_event}|{path_str}|{output_place}")
else:
self._add(f"Ec{input_place}", f"{html_event}|{path_str}")
def set_connect_event_listener(self, input_place: str, html_event_listener: str, path: Optional[str] = None, output_place: Optional[str] = None):
path_str = path if path else "#"
if output_place:
self._add(f"EC{input_place}", f"{html_event_listener}|{path_str}|{output_place}")
else:
self._add(f"EC{input_place}", f"{html_event_listener}|{path_str}")
def set_head_event(self, input_place: str, html_event: str, path: Optional[str] = None):
path_str = path if path else "#"
self._add(f"Eh{input_place}", f"{html_event}|{path_str}")
def set_head_event_listener(self, input_place: str, html_event_listener: str, path: Optional[str] = None):
path_str = path if path else "#"
self._add(f"EH{input_place}", f"{html_event_listener}|{path_str}")
def set_tag_event(self, input_place: str, html_event: str, output_place: str):
self._add(f"Et{input_place}", f"{html_event}|{output_place}")
def set_tag_event_listener(self, input_place: str, html_event_listener: str, output_place: str):
self._add(f"ET{input_place}", f"{html_event_listener}|{output_place}")
def set_comment_event(self, input_place: str, html_event: str, index: Optional[Union[str, int]] = None, output_place: Optional[str] = None):
index_str = str(index) if index is not None else ""
output_str = output_place if output_place else ""
self._add(f"Eb{input_place}", f"{html_event}|{index_str}|{output_str}")
def set_comment_event_listener(self, input_place: str, html_event_listener: str, index: Optional[Union[str, int]] = None, output_place: Optional[str] = None):
index_str = str(index) if index is not None else ""
output_str = output_place if output_place else ""
self._add(f"EB{input_place}", f"{html_event_listener}|{index_str}|{output_str}")
def set_wasm_event(self, input_place: str, html_event: str, wasm_language: str, wasm_url: str,
method_name: str, args: Optional[List[str]] = None, output_place: Optional[str] = None):
args_join = ",".join(args) if args else ""
output_str = output_place if output_place else ""
self._add(f"Ey{input_place}", f"{html_event}|{wasm_language}|{wasm_url}|{method_name}|{args_join}|{output_str}")
def set_wasm_event_listener(self, input_place: str, html_event_listener: str, wasm_language: str, wasm_url: str,
method_name: str, args: Optional[List[str]] = None, output_place: Optional[str] = None):
args_join = ",".join(args) if args else ""
output_str = output_place if output_place else ""
self._add(f"EY{input_place}", f"{html_event_listener}|{wasm_language}|{wasm_url}|{method_name}|{args_join}|{output_str}")
def set_websocket_event(self, input_place: str, html_event: str, path: str):
self._add(f"Ew{input_place}", f"{html_event}|{path}")
def set_websocket_event_listener(self, input_place: str, html_event_listener: str, path: str):
self._add(f"EW{input_place}", f"{html_event_listener}|{path}")
def set_sse_event(self, input_place: str, html_event: str, path: str, should_reconnect: bool = True,
reconnect_try_timeout: int = 3000, output_place: Optional[str] = None):
value = f"{html_event}|{path}|{'1' if should_reconnect else '0'}|{reconnect_try_timeout}"
if output_place:
value += f"|{output_place}"
self._add(f"Ee{input_place}", value)
def set_sse_event_listener(self, input_place: str, html_event_listener: str, path: str, should_reconnect: bool = True,
reconnect_try_timeout: int = 3000, output_place: Optional[str] = None):
value = f"{html_event_listener}|{path}|{'1' if should_reconnect else '0'}|{reconnect_try_timeout}"
if output_place:
value += f"|{output_place}"
self._add(f"EE{input_place}", value)
def set_front_event(self, input_place: str, html_event: str, module_path: str,
args: Optional[List[str]] = None, output_place: Optional[str] = None):
args_join = "|" + "|".join(args) if args else ""
output_str = output_place if output_place else ""
self._add(f"Ej{input_place}", f"{html_event}|{module_path}|{output_str}{args_join}")
def set_front_event_listener(self, input_place: str, html_event_listener: str, module_path: str,
args: Optional[List[str]] = None, output_place: Optional[str] = None):
args_join = "|" + "|".join(args) if args else ""
output_str = output_place if output_place else ""
self._add(f"EJ{input_place}", f"{html_event_listener}|{module_path}|{output_str}{args_join}")
def set_send_event(self, input_place: str, html_event: str, data: str, path: Optional[str] = None,
method: str = "POST", is_multi_part: bool = False, content_type: str = "text/plain",
output_place: Optional[str] = None):
path_str = path if path else "#"
data_safe = data.replace('\n', '$[ln];').replace('"', '$[dq];').replace("'", '$[sq];')
output_str = output_place if output_place else ""
self._add(f"En{input_place}", f"{html_event}|{data_safe}|{path_str}|{method}|{'1' if is_multi_part else '0'}|{content_type}|{output_str}")
def set_send_event_listener(self, input_place: str, html_event_listener: str, data: str, path: Optional[str] = None,
method: str = "POST", is_multi_part: bool = False, content_type: str = "text/plain",
output_place: Optional[str] = None):
path_str = path if path else "#"
data_safe = data.replace('\n', '$[ln];')
output_str = output_place if output_place else ""
self._add(f"EN{input_place}", f"{html_event_listener}|{data_safe}|{path_str}|{method}|{'1' if is_multi_part else '0'}|{content_type}|{output_str}")
def set_master_pages_event(self, input_place: str, html_event: str, output_place: Optional[str] = None):
value = html_event
if output_place:
value += f"|{output_place}"
self._add(f"Eu{input_place}", value)
def set_master_pages_event_listener(self, input_place: str, html_event_listener: str, output_place: Optional[str] = None):
value = html_event_listener
if output_place:
value += f"|{output_place}"
self._add(f"EU{input_place}", value)
def set_prevent_default_event(self, input_place: str, html_event: str):
self._add(f"Ed{input_place}", html_event)
def set_prevent_default_event_listener(self, input_place: str, html_event_listener: str):
self._add(f"ED{input_place}", html_event_listener)
def set_stop_propagation_event(self, input_place: str, html_event: str):
self._add(f"Es{input_place}", html_event)
def set_stop_propagation_event_listener(self, input_place: str, html_event_listener: str):
self._add(f"ES{input_place}", html_event_listener)
def set_method_event(self, input_place: str, html_event: str, method_name: str, args: Optional[List[str]] = None):
args_join = "|" + "|".join(args) if args else ""
self._add(f"Em{input_place}", f"{html_event}|{method_name}{args_join}")
def set_method_event_listener(self, input_place: str, html_event_listener: str, method_name: str, args: Optional[List[str]] = None):
args_join = "|" + "|".join(args) if args else ""
self._add(f"EM{input_place}", f"{html_event_listener}|{method_name}{args_join}")
def set_module_method_event(self, input_place: str, html_event: str, method_name: str, args: Optional[List[str]] = None):
args_join = "|" + "|".join(args) if args else ""
self._add(f"Ex{input_place}", f"{html_event}|{method_name}{args_join}")
def set_module_method_event_listener(self, input_place: str, html_event_listener: str, method_name: str, args: Optional[List[str]] = None):
args_join = "|" + "|".join(args) if args else ""
self._add(f"EX{input_place}", f"{html_event_listener}|{method_name}{args_join}")
def assign_confirm_event(self, input_place: str, html_event: str, text: str = "Are you sure you want to proceed?",
type_: str = "none", title: str = "Confirm", ok_text: str = "OK", cancel_text: str = "Cancel"):
text_str = "" if text == "Are you sure you want to proceed?" else text
type_str = "" if type_ == "none" else type_
title_str = "" if title == "Confirm" else title
ok_str = "" if ok_text == "OK" else ok_text
cancel_str = "" if cancel_text == "Cancel" else cancel_text
self._add(f"Ef{input_place}", f"{html_event}|{text_str}|{type_str}|{title_str}|{ok_str}|{cancel_str}")
def remove_post_event(self, input_place: str, html_event: str):
self._add(f"Rp{input_place}", html_event)
def remove_post_event_listener(self, input_place: str, html_event_listener: str):
self._add(f"RP{input_place}", html_event_listener)
# Note: Many more remove methods would be added here following the same pattern
# For brevity, I'm showing a few examples
def remove_get_event(self, input_place: str, html_event: str):
self._add(f"Rg{input_place}", html_event)
def remove_get_event_listener(self, input_place: str, html_event_listener: str):
self._add(f"RG{input_place}", html_event_listener)
# Custom Event
def create_custom_dom_event(self, input_place: str, event_name: str, watch: str, key: str,
compare: str, value: str, range_: str, immediate: bool = False, delay: int = 0):
self._add(f"eC{input_place}", f"{event_name}|{watch}|{key}|{compare}|{value}|{range_}|{'1' if immediate else '0'}|{delay}")
def enable_scroll_bottom_event(self, enable: bool = True):
self._add("eb", "1" if enable else "0")
def enable_reached_element_event(self, input_place: str, once: bool, enable: bool = True):
self._add(f"er{input_place}", f"{'1' if once else '0'}|{'1' if enable else '0'}")
# Module
def load_module(self, module_path: str, methods: List[str]):
methods_str = "|" + "|".join(methods) if methods else ""
self._add("Ml", f"{module_path}{methods_str}")
def unload_module(self, module_path: str):
self._add("Mu", module_path)
def delete_module_method(self, method_name: str):
self._add("Md", method_name)
# Unit Testing
def assert_equal(self, input_place: str, tag: str):
self._add(f"At{input_place}", tag.replace('\n', '$[ln];'))
def assert_equal_by_output_place(self, input_place: str, output_place: str):
self._add(f"Ao{input_place}", output_place)
# Service Worker
def service_worker_register(self, path: Optional[str] = None, scope_path: Optional[str] = None):
self._add("wR", f"{path if path else ''}|{scope_path if scope_path else ''}")
def service_worker_pre_cache_static(self, path_list: List[str]):
self._add("wp", "|".join(path_list))
def service_worker_dynamic_cache(self, path: str, seconds: int = 0):
value = path
if seconds > 0:
value += f"|{seconds}"
self._add("wc", value)
def service_worker_delete_dynamic_cache(self, path: Optional[str] = None):
if path:
self._add("wd", path)
else:
self._add("wd")
def service_worker_dynamic_cache_ttl_update(self, path: str, seconds: int = 0):
value = path
if seconds > 0:
value += f"|{seconds}"
self._add("wt", value)
def service_worker_route_set(self, path: str, type_: str, cache_dynamic: bool = False):
self._add("wr", f"{path}|{type_}" + ("|1" if cache_dynamic else ""))
def service_worker_route_alias(self, path: str, to: str):
self._add("wa", f"{path}|{to}")
def service_worker_delete_route_alias(self, path: Optional[str] = None):
self._add("wC", path if path else "")
def service_worker_delete_route(self, path: Optional[str] = None):
if path:
self._add("wD", path)
else:
self._add("wD")
# SSE
def disconnect_sse(self, path: Optional[str] = None):
if path:
self._add("Ds", path)
else:
self._add("Ds")
# State
def add_state(self, path: Optional[str] = None, title: Optional[str] = None):
self._add("AS", f"{path if path else ''}|{title if title else ''}")
def delete_state(self, path: Optional[str] = None):
if path:
self._add("DS", path)
else:
self._add("DS", "*")
def delete_all_state(self):
self._add("DS", "*")
# Cookie
def set_cookie(self, key: str, value: str, seconds: int, path: Optional[str] = None):
value_str = f"{key}|{value}|{seconds}"
if path:
value_str += f"|{path}"
self._add("sC", value_str)
# Save/Session Cache
def save_id(self, input_place: str, key: str = "."):
self._add(f"@gi{input_place}", key)
def save_name(self, input_place: str, key: str = "."):
self._add(f"@gn{input_place}", key)
def save_value(self, input_place: str, key: str = "."):
self._add(f"@gv{input_place}", key)
def save_value_length(self, input_place: str, key: str = "."):
self._add(f"@ge{input_place}", key)
def save_class(self, input_place: str, key: str = "."):
self._add(f"@gc{input_place}", key)
def save_style(self, input_place: str, key: str = "."):
self._add(f"@gs{input_place}", key)
def save_title(self, input_place: str, key: str = "."):
self._add(f"@gl{input_place}", key)
def save_label(self, input_place: str, key: str = "."):
self._add(f"@gA{input_place}", key)
def save_text(self, input_place: str, key: str = "."):
self._add(f"@gt{input_place}", key)
def save_outer_text(self, input_place: str, key: str = "."):
self._add(f"@go{input_place}", key)
def save_text_length(self, input_place: str, key: str = "."):
self._add(f"@gg{input_place}", key)
def save_attribute(self, input_place: str, attribute: str, key: str = "."):
self._add(f"@ga{input_place}", f"{key}|{attribute}")
def save_width(self, input_place: str, key: str = "."):
self._add(f"@gw{input_place}", key)
def save_height(self, input_place: str, key: str = "."):
self._add(f"@gh{input_place}", key)
def save_read_only(self, input_place: str, key: str = "."):
self._add(f"@gr{input_place}", key)
def save_selected_index(self, input_place: str, key: str = "."):
self._add(f"@gx{input_place}", key)
def save_text_align(self, input_place: str, key: str = "."):
self._add(f"@gT{input_place}", key)
def save_node_length(self, input_place: str, key: str = "."):
self._add(f"@gL{input_place}", key)
def save_visible(self, input_place: str, key: str = "."):
self._add(f"@gV{input_place}", key)
def save_url(self, url: str, fetch_script: bool = False, key: str = "."):
self._add(f"@gu", f"{key}|{url}" + ("|1" if fetch_script else ""))
def save_index(self, input_place: str, key: str = "."):
self._add(f"@gI{input_place}", key)
def remove_session_cache(self, cache_key: str):
self._add("rs", cache_key)
def remove_all_session_cache(self):
self._add("rs", "*")
def set_session_cache(self):
self._add("cs", "*")
def add_session_cache_value(self, cache_key: str, value: str):
self._add("SA", f"{cache_key}|{value.replace(chr(10), '$[ln];')}")
def insert_session_cache_value(self, cache_key: str, value: str):
self._add("SI", f"{cache_key}|{value.replace(chr(10), '$[ln];')}")
# Cache
def cache_id(self, input_place: str, key: str = "."):
self._add(f"@ci{input_place}", key)
def cache_name(self, input_place: str, key: str = "."):
self._add(f"@cn{input_place}", key)
def cache_value(self, input_place: str, key: str = "."):
self._add(f"@cv{input_place}", key)
def cache_value_length(self, input_place: str, key: str = "."):
self._add(f"@ce{input_place}", key)
def cache_class(self, input_place: str, key: str = "."):
self._add(f"@cc{input_place}", key)
def cache_style(self, input_place: str, key: str = "."):
self._add(f"@cs{input_place}", key)
def cache_title(self, input_place: str, key: str = "."):
self._add(f"@cl{input_place}", key)
def cache_label(self, input_place: str, key: str = "."):
self._add(f"@cA{input_place}", key)
def cache_text(self, input_place: str, key: str = "."):
self._add(f"@ct{input_place}", key)
def cache_outer_text(self, input_place: str, key: str = "."):
self._add(f"@co{input_place}", key)
def cache_text_length(self, input_place: str, key: str = "."):
self._add(f"@cg{input_place}", key)
def cache_attribute(self, input_place: str, attribute: str, key: str = "."):
self._add(f"@ca{input_place}", f"{key}|{attribute}")
def cache_width(self, input_place: str, key: str = "."):
self._add(f"@cw{input_place}", key)
def cache_height(self, input_place: str, key: str = "."):
self._add(f"@ch{input_place}", key)
def cache_read_only(self, input_place: str, key: str = "."):
self._add(f"@cr{input_place}", key)
def cache_selected_index(self, input_place: str, key: str = "."):
self._add(f"@cx{input_place}", key)
def cache_text_align(self, input_place: str, key: str = "."):
self._add(f"@cT{input_place}", key)
def cache_node_length(self, input_place: str, key: str = "."):
self._add(f"@cL{input_place}", key)
def cache_visible(self, input_place: str, key: str = "."):
self._add(f"@cV{input_place}", key)
def cache_url(self, url: str, fetch_script: bool = False, key: str = "."):
self._add(f"@cu", f"{key}|{url}" + ("|1" if fetch_script else ""))
def cache_index(self, input_place: str, key: str = "."):
self._add(f"@cI{input_place}", key)
def remove_cache(self, cache_key: str):
self._add("rd", cache_key)
def remove_all_cache(self):
self._add("rd", "*")
def set_cache(self, seconds: Optional[int] = None):
if seconds is not None:
self._add("cd", str(seconds))
else:
self._add("cd", "*")
def add_cache_value(self, cache_key: str, value: str):
self._add("CA", f"{cache_key}|{value.replace(chr(10), '$[ln];')}")
def insert_cache_value(self, cache_key: str, value: str):
self._add("CI", f"{cache_key}|{value.replace(chr(10), '$[ln];')}")
# Call
def load_url(self, input_place: str, url: str):
self._add(f"lu{input_place}", url)
def run_action_controls(self, action_controls: str, index: Optional[Union[str, int]] = None,
without_webforms_section: bool = False, use_current_event: bool = True):
index_str = str(index) if index is not None else ""
self._add("lA", f"{'1' if use_current_event else '0'}|{'1' if without_webforms_section else '0'}|{index_str}|{action_controls}")
def call_script(self, script_text: str):
self._add("_", script_text.replace(chr(10), '$[ln];'))
def call_method(self, method_name: str, args: Optional[List[str]] = None):
args_str = "|" + "|".join(args) if args else ""
self._add("lm", f"{method_name}{args_str}")
def call_module_method(self, method_name: str, args: Optional[List[str]] = None):
args_str = "|" + "|".join(args) if args else ""
self._add("lM", f"{method_name}{args_str}")
def call_post_back(self, form_input_place: str, output_place: Optional[str] = None):
value = f"1|{form_input_place}"
if output_place:
value += f"|{output_place}"
self._add("Lp", value)
def call_tag_back(self, output_place: Optional[str] = None, use_current_event: bool = True):
value = "1" if use_current_event else "0"
if output_place:
value += f"|{output_place}"
self._add("Lt", value)
def call_comment_back(self, index: Optional[Union[str, int]] = None, output_place: Optional[str] = None,
use_current_event: bool = True):
index_str = str(index) if index is not None else ""
output_str = output_place if output_place else ""
self._add("LC", f"{'1' if use_current_event else '0'}|{index_str}|{output_str}")
def call_wasm_back(self, wasm_language: str, wasm_url: str, method_name: str,
args: Optional[List[str]] = None, output_place: Optional[str] = None,
use_current_event: bool = True):
args_join = ",".join(args) if args else ""
output_str = output_place if output_place else ""
self._add("Ly", f"{'1' if use_current_event else '0'}|{wasm_language}|{wasm_url}|{method_name}|{args_join}|{output_str}")
def call_websocket_back(self, path: str, use_current_event: bool = True):
self._add("Lw", f"{'1' if use_current_event else '0'}|{path}")
def call_sse_back(self, path: str, output_place: Optional[str] = None, use_current_event: bool = True,
should_reconnect: bool = True, reconnect_try_timeout: int = 3000):
value = f"{'1' if use_current_event else '0'}|{path}|{'1' if should_reconnect else '0'}|{reconnect_try_timeout}"
if output_place:
value += f"|{output_place}"
self._add("Ls", value)
def call_front(self, module_path: str, args: Optional[List[str]] = None, output_place: Optional[str] = None,
use_current_event: bool = True):
args_str = "|" + "|".join(args) if args else ""
output_str = output_place if output_place else ""
self._add("Lj", f"{'1' if use_current_event else '0'}|{module_path}|{output_str}{args_str}")
def call_get_back(self, path: str, output_place: Optional[str] = None, use_current_event: bool = True):
value = f"{'1' if use_current_event else '0'}|{path}"
if output_place:
value += f"|{output_place}"
self._add("Lg", value)
def call_put_back(self, path: str, output_place: Optional[str] = None, use_current_event: bool = True):
value = f"{'1' if use_current_event else '0'}|{path}"
if output_place:
value += f"|{output_place}"
self._add("Lu", value)
def call_patch_back(self, path: str, output_place: Optional[str] = None, use_current_event: bool = True):
value = f"{'1' if use_current_event else '0'}|{path}"
if output_place:
value += f"|{output_place}"
self._add("LP", value)
def call_delete_back(self, path: str, output_place: Optional[str] = None, use_current_event: bool = True):
value = f"{'1' if use_current_event else '0'}|{path}"
if output_place:
value += f"|{output_place}"
self._add("Ld", value)
def call_head_back(self, path: str, output_place: Optional[str] = None, use_current_event: bool = True):
value = f"{'1' if use_current_event else '0'}|{path}"
if output_place:
value += f"|{output_place}"
self._add("Lh", value)
def call_options_back(self, path: str, output_place: Optional[str] = None, use_current_event: bool = True):
value = f"{'1' if use_current_event else '0'}|{path}"
if output_place:
value += f"|{output_place}"
self._add("Lo", value)
def call_trace_back(self, path: str, output_place: Optional[str] = None, use_current_event: bool = True):
value = f"{'1' if use_current_event else '0'}|{path}"
if output_place:
value += f"|{output_place}"
self._add("LT", value)
def call_connect_back(self, path: str, output_place: Optional[str] = None, use_current_event: bool = True):
value = f"{'1' if use_current_event else '0'}|{path}"
if output_place:
value += f"|{output_place}"
self._add("Lc", value)
def call_send_back(self, path: str, method: str, is_multi_part: bool, content_type: str, data: str,
output_place: Optional[str] = None, use_current_event: bool = True):
data_safe = data.replace(chr(10), '$[ln];').replace('|', '$[vb];')
value = f"{'1' if use_current_event else '0'}|{path}|{method}|{'1' if is_multi_part else '0'}|{content_type}|{data_safe}"
if output_place:
value += f"|{output_place}"
self._add("LS", value)
# Update
def increase(self, input_place: str, value: float):
self._add(f"gt{input_place}", f"i|{value}")
def decrease(self, input_place: str, value: float):
self._add(f"gt{input_place}", f"i|{-value}")
def replace(self, input_place: str, value: str, new_value: str, also_start_tag: bool = False, deep: bool = False):
if value and value.startswith('@'):
value = "$[at];" + value[1:]