kongalib 1.12.0__cp39-cp39-win_amd64.whl → 2.0.0.post1__cp39-cp39-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of kongalib might be problematic. Click here for more details.
- _kongalib.cp39-win_amd64.pdb +0 -0
- _kongalib.cp39-win_amd64.pyd +0 -0
- kongalib/__init__.py +22 -36
- kongalib/async_client.py +63 -65
- kongalib/client.py +51 -20
- kongalib/constants.py +110 -1842
- kongalib/data_dictionary.py +3 -12
- kongalib/db.py +7 -8
- kongalib/expression.py +29 -24
- kongalib/json.py +1 -2
- kongalib/scripting.py +54 -31
- {kongalib-1.12.0.dist-info → kongalib-2.0.0.post1.dist-info}/METADATA +29 -26
- kongalib-2.0.0.post1.dist-info/RECORD +21 -0
- {kongalib-1.12.0.dist-info → kongalib-2.0.0.post1.dist-info}/WHEEL +1 -1
- {kongalib-1.12.0.dist-info → kongalib-2.0.0.post1.dist-info}/top_level.txt +1 -0
- kongaui.py +4 -55
- kongautil.py +17 -13
- kongalib/_kongalib.cp39-win_amd64.pdb +0 -0
- kongalib/_kongalib.cp39-win_amd64.pyd +0 -0
- kongalib/compat.py +0 -492
- kongalib/parsetab.py +0 -41
- kongalib-1.12.0.dist-info/RECORD +0 -23
- {kongalib-1.12.0.dist-info → kongalib-2.0.0.post1.dist-info/licenses}/LICENSE +0 -0
- {kongalib-1.12.0.dist-info → kongalib-2.0.0.post1.dist-info}/zip-safe +0 -0
kongaui.py
CHANGED
|
@@ -28,14 +28,6 @@ import kongautil
|
|
|
28
28
|
from kongalib.scripting import _TimeoutBlocker
|
|
29
29
|
from kongalib.scripting import proxy as _proxy
|
|
30
30
|
|
|
31
|
-
PY3 = (sys.version_info[0] >= 3)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if PY3:
|
|
35
|
-
basestring = str
|
|
36
|
-
else:
|
|
37
|
-
input = raw_input
|
|
38
|
-
|
|
39
31
|
|
|
40
32
|
|
|
41
33
|
BUTTON_OK = 0x0001 #: Bottone "Ok"
|
|
@@ -75,47 +67,8 @@ if not _proxy.is_valid():
|
|
|
75
67
|
|
|
76
68
|
|
|
77
69
|
def _get_term_width():
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return shutil.get_terminal_size(fallback=(80, 24))[0]
|
|
81
|
-
else:
|
|
82
|
-
# from https://stackoverflow.com/questions/566746/how-to-get-linux-console-window-width-in-python
|
|
83
|
-
if sys.platform == 'win32':
|
|
84
|
-
try:
|
|
85
|
-
from ctypes import windll, create_string_buffer
|
|
86
|
-
h = windll.kernel32.GetStdHandle(-12)
|
|
87
|
-
csbi = create_string_buffer(22)
|
|
88
|
-
res = windll.kernel32.GetConsoleScreenBufferInfo(h, csbi)
|
|
89
|
-
except:
|
|
90
|
-
res = None
|
|
91
|
-
if res:
|
|
92
|
-
import struct
|
|
93
|
-
(bufx, bufy, curx, cury, wattr, left, top, right, bottom, maxx, maxy) = struct.unpack("hhhhHhhhhhh", csbi.raw)
|
|
94
|
-
return right - left + 1
|
|
95
|
-
else:
|
|
96
|
-
return 80
|
|
97
|
-
else:
|
|
98
|
-
def ioctl_GWINSZ(fd):
|
|
99
|
-
try:
|
|
100
|
-
import fcntl, termios, struct
|
|
101
|
-
cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234'))
|
|
102
|
-
except:
|
|
103
|
-
return None
|
|
104
|
-
return cr
|
|
105
|
-
cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
|
|
106
|
-
if not cr:
|
|
107
|
-
try:
|
|
108
|
-
fd = os.open(os.ctermid(), os.O_RDONLY)
|
|
109
|
-
cr = ioctl_GWINSZ(fd)
|
|
110
|
-
os.close(fd)
|
|
111
|
-
except:
|
|
112
|
-
pass
|
|
113
|
-
if not cr:
|
|
114
|
-
try:
|
|
115
|
-
cr = (env['LINES'], env['COLUMNS'])
|
|
116
|
-
except:
|
|
117
|
-
return 80
|
|
118
|
-
return int(cr[1])
|
|
70
|
+
import shutil
|
|
71
|
+
return shutil.get_terminal_size(fallback=(80, 24))[0]
|
|
119
72
|
|
|
120
73
|
|
|
121
74
|
|
|
@@ -338,11 +291,7 @@ def set_progress(progress=None, message=None, state=None):
|
|
|
338
291
|
tick = ('\\', '|', '/', '-')[int(time.time() * 5) % 4]
|
|
339
292
|
bar = '%s %s' % (elide(', '.join(text), term_width - 3), tick)
|
|
340
293
|
else:
|
|
341
|
-
|
|
342
|
-
block = u'\u2588'
|
|
343
|
-
else:
|
|
344
|
-
block = '#'
|
|
345
|
-
progress = (block * int((progress * 30) // 100))
|
|
294
|
+
progress = ('\u2588' * int((progress * 30) // 100))
|
|
346
295
|
bar = '|%-30s| %s' % (progress, elide(', '.join(text), term_width - 34))
|
|
347
296
|
print('\033[2K\r' + bar, end='')
|
|
348
297
|
sys.stdout.flush()
|
|
@@ -494,7 +443,7 @@ def execute_form(form_data, title=None, message=None, condition=None):
|
|
|
494
443
|
raise InvalidInput('Expected iso date (YYYY-MM-DD)')
|
|
495
444
|
elif wtype in ('choice', 'listbox', 'combobox'):
|
|
496
445
|
items = entry.get('items', [])
|
|
497
|
-
if (not isinstance(items, (tuple, list))) or (not all([ isinstance(item,
|
|
446
|
+
if (not isinstance(items, (tuple, list))) or (not all([ isinstance(item, str) for item in items ])):
|
|
498
447
|
raise RuntimeError("Expected list of strings as 'items' value")
|
|
499
448
|
print(label)
|
|
500
449
|
for index, item in enumerate(items):
|
kongautil.py
CHANGED
|
@@ -53,13 +53,8 @@ class PrintError(RuntimeError):
|
|
|
53
53
|
"""Eccezione lanciata se ci sono errori nell'esecuzione di una stampa con la funzione :func:`print_layout`."""
|
|
54
54
|
def __init__(self, log):
|
|
55
55
|
self._log = log
|
|
56
|
-
def __unicode__(self):
|
|
57
|
-
return u'Log:\n%s' % ('\n'.join([ (' %s' % line) for line in kongalib.ensure_text(self._log.dumps()).split(u'\n') ]))
|
|
58
56
|
def __str__(self):
|
|
59
|
-
|
|
60
|
-
return self.__unicode__()
|
|
61
|
-
else:
|
|
62
|
-
return self.__unicode__().encode('utf-8')
|
|
57
|
+
return 'Log:\n%s' % ('\n'.join([ (' %s' % line) for line in kongalib.ensure_text(self._log.dumps()).split(u'\n') ]))
|
|
63
58
|
def get_log(self):
|
|
64
59
|
"""Ottiene un oggetto di classe :class:`kongalib.Log` contenente gli errori di stampa."""
|
|
65
60
|
return self._log
|
|
@@ -144,7 +139,7 @@ def connect(host=None, port=None, driver=None, database=None, username=None, pas
|
|
|
144
139
|
parametri come variabili all'interno di un file di configurazione, nella sezione ``[kongautil.connect]``; tale file deve avere
|
|
145
140
|
il nome passato a questa funzione con il parametro ``config``, altrimenti verranno ricercati nell'ordine anche il file con lo
|
|
146
141
|
stesso nome dello script lanciato da terminale, ma con estensione ``.cfg``, il file ``kongalib.cfg`` sempre nella stessa directory
|
|
147
|
-
da cui si esegue lo script e infine il file ``~/.kongalib`` (sotto Unix) o ``%userprofile
|
|
142
|
+
da cui si esegue lo script e infine il file ``~/.kongalib`` (sotto Unix) o ``%userprofile%\\kongalib.cfg`` (sotto Windows)."""
|
|
148
143
|
if _proxy.is_valid():
|
|
149
144
|
info = _proxy.util.get_connection_info()
|
|
150
145
|
if info is not None:
|
|
@@ -162,10 +157,7 @@ def connect(host=None, port=None, driver=None, database=None, username=None, pas
|
|
|
162
157
|
client = kongalib.Client()
|
|
163
158
|
if host is None:
|
|
164
159
|
import argparse
|
|
165
|
-
|
|
166
|
-
import configparser
|
|
167
|
-
except:
|
|
168
|
-
import ConfigParser as configparser
|
|
160
|
+
import configparser
|
|
169
161
|
files = [
|
|
170
162
|
os.path.abspath(os.path.expanduser(os.path.join('~', 'kongalib.cfg' if sys.platform == 'win32' else '.kongalib'))),
|
|
171
163
|
os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), 'kongalib.cfg'),
|
|
@@ -394,7 +386,7 @@ def print_layout(command_or_layout, builtins=None, code_azienda=None, code_eserc
|
|
|
394
386
|
log = kongalib.Log()
|
|
395
387
|
if not filename:
|
|
396
388
|
raise ValueError("Output filename must be specified")
|
|
397
|
-
if isinstance(command_or_layout,
|
|
389
|
+
if isinstance(command_or_layout, str) and (command_or_layout.strip().startswith('<?xml') or command_or_layout.strip().startswith('<layout')):
|
|
398
390
|
import tempfile
|
|
399
391
|
temp = tempfile.NamedTemporaryFile(mode='w', delete=False)
|
|
400
392
|
with temp:
|
|
@@ -431,7 +423,7 @@ def print_log(log, title, target=PRINT_TARGET_PREVIEW, filename=None):
|
|
|
431
423
|
:func:`print_layout`, passando i parametri *target* e *filename*; viceversa se si esegue fuori da Konga, il log verrà stampato su terminale."""
|
|
432
424
|
if _proxy.is_valid():
|
|
433
425
|
template = """<?xml version='1.0' encoding='utf-8'?>
|
|
434
|
-
<layout version="
|
|
426
|
+
<layout version="3" name="%(title)s" title="%(title)s" orientation="vertical" margin_top="75" margin_right="75" margin_bottom="75" margin_left="75">
|
|
435
427
|
<init>
|
|
436
428
|
<![CDATA[set_datasource(Datasource(['id', 'type', 'message'], DATA, 'Master'))
|
|
437
429
|
]]></init>
|
|
@@ -497,6 +489,18 @@ def print_log(log, title, target=PRINT_TARGET_PREVIEW, filename=None):
|
|
|
497
489
|
|
|
498
490
|
|
|
499
491
|
|
|
492
|
+
def show_log(log, title, size=None, iconsize=32):
|
|
493
|
+
"""Visualizza il contenuto dell'oggetto *log* di classe :class:`kongalib.Log`; se si esegue questa funzione dall'interno di Konga, il log verrà
|
|
494
|
+
visualizzato in una finestra dedicata; viceversa se si esegue fuori da Konga, il comportamento di questa funzione equivale a chiamare
|
|
495
|
+
:func:`print_log` con gli stessi argomenti. La finestra del log mostrerà *title* come messaggio informativo e se specificato avrà dimensione *size*;
|
|
496
|
+
è possibile specificare anche la dimensione delle icone dei singoli messaggi tramite il parametro *iconsize*."""
|
|
497
|
+
if _proxy.is_valid():
|
|
498
|
+
log = _proxy.util.show_log(log.get_messages(), title, size, iconsize)
|
|
499
|
+
else:
|
|
500
|
+
print_log(log, title)
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
|
|
500
504
|
def suspend_timeout():
|
|
501
505
|
"""Sospende il timeout di esecuzione dello script. La funzione non comporta eccezioni ma non ha alcun effetto se eseguita al di fuori di Konga."""
|
|
502
506
|
if _proxy.is_valid():
|
|
Binary file
|
|
Binary file
|
kongalib/compat.py
DELETED
|
@@ -1,492 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
# _ _ _ _
|
|
3
|
-
# | | | (_) |
|
|
4
|
-
# | | _____ _ __ __ _ __ _| |_| |__
|
|
5
|
-
# | |/ / _ \| '_ \ / _` |/ _` | | | '_ \
|
|
6
|
-
# | < (_) | | | | (_| | (_| | | | |_) |
|
|
7
|
-
# |_|\_\___/|_| |_|\__, |\__,_|_|_|_.__/
|
|
8
|
-
# __/ |
|
|
9
|
-
# |___/
|
|
10
|
-
#
|
|
11
|
-
# Konga client library, by EasyByte Software
|
|
12
|
-
#
|
|
13
|
-
# https://github.com/easybyte-software/kongalib
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
from __future__ import print_function
|
|
17
|
-
|
|
18
|
-
import sys
|
|
19
|
-
import io
|
|
20
|
-
|
|
21
|
-
from xml.etree import ElementTree as ET
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
PY3 = (sys.version_info[0] > 2)
|
|
26
|
-
|
|
27
|
-
if PY3:
|
|
28
|
-
text_base_types = (str,)
|
|
29
|
-
text_type = str
|
|
30
|
-
data_base_types = (bytes,)
|
|
31
|
-
data_type = bytes
|
|
32
|
-
int_base_types = (int,)
|
|
33
|
-
int_type = int
|
|
34
|
-
file_type = io.IOBase
|
|
35
|
-
def reraise(tp, value, tb=None):
|
|
36
|
-
if value is None:
|
|
37
|
-
value = tp()
|
|
38
|
-
if value.__traceback__ is not tb:
|
|
39
|
-
raise value.with_traceback(tb)
|
|
40
|
-
raise value
|
|
41
|
-
unichr = chr
|
|
42
|
-
buffer = bytes
|
|
43
|
-
else:
|
|
44
|
-
text_base_types = (basestring,)
|
|
45
|
-
text_type = unicode
|
|
46
|
-
data_base_types = (basestring, buffer)
|
|
47
|
-
data_type = bytes
|
|
48
|
-
int_base_types = (int, long)
|
|
49
|
-
int_type = long
|
|
50
|
-
file_type = file
|
|
51
|
-
exec("def reraise(tp, value, tb=None):\n raise tp, value, tb\n")
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
def ensure_text(text, error='replace'):
|
|
56
|
-
if not isinstance(text, text_base_types):
|
|
57
|
-
try:
|
|
58
|
-
text = unicode(text)
|
|
59
|
-
except:
|
|
60
|
-
if isinstance(text, data_base_types):
|
|
61
|
-
text = str(text, 'utf-8', 'replace')
|
|
62
|
-
else:
|
|
63
|
-
text = str(text)
|
|
64
|
-
if isinstance(text, data_type):
|
|
65
|
-
text = text_type(text, 'utf-8', error)
|
|
66
|
-
return text
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
def _patch_etree():
|
|
71
|
-
OriginalElementTree = ET.ElementTree
|
|
72
|
-
Original_serialize_xml = ET._serialize_xml
|
|
73
|
-
|
|
74
|
-
if PY3:
|
|
75
|
-
import warnings
|
|
76
|
-
import collections
|
|
77
|
-
import collections.abc
|
|
78
|
-
|
|
79
|
-
Original_iterparse = ET.iterparse
|
|
80
|
-
Original_parse = ET.parse
|
|
81
|
-
|
|
82
|
-
def OriginalSubElement(parent, tag, attrib={}, **extra):
|
|
83
|
-
"""Subelement factory which creates an element instance, and appends it
|
|
84
|
-
to an existing parent.
|
|
85
|
-
|
|
86
|
-
The element tag, attribute names, and attribute values can be either
|
|
87
|
-
bytes or Unicode strings.
|
|
88
|
-
|
|
89
|
-
*parent* is the parent element, *tag* is the subelements name, *attrib* is
|
|
90
|
-
an optional directory containing element attributes, *extra* are
|
|
91
|
-
additional attributes given as keyword arguments.
|
|
92
|
-
|
|
93
|
-
"""
|
|
94
|
-
attrib = attrib.copy()
|
|
95
|
-
attrib.update(extra)
|
|
96
|
-
element = parent.makeelement(tag, attrib)
|
|
97
|
-
parent.append(element)
|
|
98
|
-
return element
|
|
99
|
-
|
|
100
|
-
class OriginalTreeBuilder:
|
|
101
|
-
"""Generic element structure builder.
|
|
102
|
-
|
|
103
|
-
This builder converts a sequence of start, data, and end method
|
|
104
|
-
calls to a well-formed element structure.
|
|
105
|
-
|
|
106
|
-
You can use this class to build an element structure using a custom XML
|
|
107
|
-
parser, or a parser for some other XML-like format.
|
|
108
|
-
|
|
109
|
-
*element_factory* is an optional element factory which is called
|
|
110
|
-
to create new Element instances, as necessary.
|
|
111
|
-
|
|
112
|
-
"""
|
|
113
|
-
def __init__(self, element_factory=None):
|
|
114
|
-
self._data = [] # data collector
|
|
115
|
-
self._elem = [] # element stack
|
|
116
|
-
self._last = None # last element
|
|
117
|
-
self._tail = None # true if we're after an end tag
|
|
118
|
-
if element_factory is None:
|
|
119
|
-
element_factory = ET._Element_Py
|
|
120
|
-
self._factory = element_factory
|
|
121
|
-
|
|
122
|
-
def close(self):
|
|
123
|
-
"""Flush builder buffers and return toplevel document Element."""
|
|
124
|
-
assert len(self._elem) == 0, "missing end tags"
|
|
125
|
-
assert self._last is not None, "missing toplevel element"
|
|
126
|
-
return self._last
|
|
127
|
-
|
|
128
|
-
def _flush(self):
|
|
129
|
-
if self._data:
|
|
130
|
-
if self._last is not None:
|
|
131
|
-
text = "".join(self._data)
|
|
132
|
-
if self._tail:
|
|
133
|
-
assert self._last.tail is None, "internal error (tail)"
|
|
134
|
-
self._last.tail = text
|
|
135
|
-
else:
|
|
136
|
-
assert self._last.text is None, "internal error (text)"
|
|
137
|
-
self._last.text = text
|
|
138
|
-
self._data = []
|
|
139
|
-
|
|
140
|
-
def data(self, data):
|
|
141
|
-
"""Add text to current element."""
|
|
142
|
-
self._data.append(data)
|
|
143
|
-
|
|
144
|
-
def start(self, tag, attrs):
|
|
145
|
-
"""Open new element and return it.
|
|
146
|
-
|
|
147
|
-
*tag* is the element name, *attrs* is a dict containing element
|
|
148
|
-
attributes.
|
|
149
|
-
|
|
150
|
-
"""
|
|
151
|
-
self._flush()
|
|
152
|
-
self._last = elem = self._factory(tag, attrs)
|
|
153
|
-
if self._elem:
|
|
154
|
-
self._elem[-1].append(elem)
|
|
155
|
-
self._elem.append(elem)
|
|
156
|
-
self._tail = 0
|
|
157
|
-
return elem
|
|
158
|
-
|
|
159
|
-
def end(self, tag):
|
|
160
|
-
"""Close and return current Element.
|
|
161
|
-
|
|
162
|
-
*tag* is the element name.
|
|
163
|
-
|
|
164
|
-
"""
|
|
165
|
-
self._flush()
|
|
166
|
-
self._last = self._elem.pop()
|
|
167
|
-
assert self._last.tag == tag,\
|
|
168
|
-
"end tag mismatch (expected %s, got %s)" % (
|
|
169
|
-
self._last.tag, tag)
|
|
170
|
-
self._tail = 1
|
|
171
|
-
return self._last
|
|
172
|
-
|
|
173
|
-
class OriginalXMLTreeBuilder(object):
|
|
174
|
-
def __init__(self, html=0, target=None, encoding=None):
|
|
175
|
-
try:
|
|
176
|
-
from xml.parsers import expat
|
|
177
|
-
except ImportError:
|
|
178
|
-
try:
|
|
179
|
-
import pyexpat as expat
|
|
180
|
-
except ImportError:
|
|
181
|
-
raise ImportError(
|
|
182
|
-
"No module named expat; use SimpleXMLTreeBuilder instead"
|
|
183
|
-
)
|
|
184
|
-
parser = expat.ParserCreate(encoding, "}")
|
|
185
|
-
if target is None:
|
|
186
|
-
target = OriginalTreeBuilder(ET._Element_Py)
|
|
187
|
-
|
|
188
|
-
self.parser = self._parser = parser
|
|
189
|
-
self.target = self._target = target
|
|
190
|
-
self._error = expat.error
|
|
191
|
-
self._names = {}
|
|
192
|
-
parser.DefaultHandlerExpand = self._default
|
|
193
|
-
if hasattr(target, 'start'):
|
|
194
|
-
parser.StartElementHandler = self._start
|
|
195
|
-
if hasattr(target, 'end'):
|
|
196
|
-
parser.EndElementHandler = self._end
|
|
197
|
-
if hasattr(target, 'data'):
|
|
198
|
-
parser.CharacterDataHandler = target.data
|
|
199
|
-
if hasattr(target, 'comment'):
|
|
200
|
-
parser.CommentHandler = target.comment
|
|
201
|
-
if hasattr(target, 'pi'):
|
|
202
|
-
parser.ProcessingInstructionHandler = target.pi
|
|
203
|
-
parser.buffer_text = 1
|
|
204
|
-
parser.ordered_attributes = 1
|
|
205
|
-
parser.specified_attributes = 1
|
|
206
|
-
self._doctype = None
|
|
207
|
-
self.entity = {}
|
|
208
|
-
try:
|
|
209
|
-
self.version = "Expat %d.%d.%d" % expat.version_info
|
|
210
|
-
except AttributeError:
|
|
211
|
-
pass
|
|
212
|
-
|
|
213
|
-
def _setevents(self, events_queue, events_to_report):
|
|
214
|
-
parser = self._parser
|
|
215
|
-
append = events_queue.append
|
|
216
|
-
for event_name in events_to_report:
|
|
217
|
-
if event_name == "start":
|
|
218
|
-
parser.ordered_attributes = 1
|
|
219
|
-
parser.specified_attributes = 1
|
|
220
|
-
def handler(tag, attrib_in, event=event_name, append=append, start=self._start):
|
|
221
|
-
append((event, start(tag, attrib_in)))
|
|
222
|
-
parser.StartElementHandler = handler
|
|
223
|
-
elif event_name == "end":
|
|
224
|
-
def handler(tag, event=event_name, append=append, end=self._end):
|
|
225
|
-
append((event, end(tag)))
|
|
226
|
-
parser.EndElementHandler = handler
|
|
227
|
-
elif event_name == "start-ns":
|
|
228
|
-
def handler(prefix, uri, event=event_name, append=append):
|
|
229
|
-
append((event, (prefix or "", uri or "")))
|
|
230
|
-
parser.StartNamespaceDeclHandler = handler
|
|
231
|
-
elif event_name == "end-ns":
|
|
232
|
-
def handler(prefix, event=event_name, append=append):
|
|
233
|
-
append((event, None))
|
|
234
|
-
parser.EndNamespaceDeclHandler = handler
|
|
235
|
-
else:
|
|
236
|
-
raise ValueError("unknown event %r" % event_name)
|
|
237
|
-
|
|
238
|
-
def _raiseerror(self, value):
|
|
239
|
-
err = ET.ParseError(value)
|
|
240
|
-
err.code = value.code
|
|
241
|
-
err.position = value.lineno, value.offset
|
|
242
|
-
raise err
|
|
243
|
-
|
|
244
|
-
def _fixname(self, key):
|
|
245
|
-
try:
|
|
246
|
-
name = self._names[key]
|
|
247
|
-
except KeyError:
|
|
248
|
-
name = key
|
|
249
|
-
if "}" in name:
|
|
250
|
-
name = "{" + name
|
|
251
|
-
self._names[key] = name
|
|
252
|
-
return name
|
|
253
|
-
|
|
254
|
-
def _fixtext(self, text):
|
|
255
|
-
return text
|
|
256
|
-
|
|
257
|
-
def _start(self, tag, attr_list):
|
|
258
|
-
fixname = self._fixname
|
|
259
|
-
tag = fixname(tag)
|
|
260
|
-
attrib = {}
|
|
261
|
-
if attr_list:
|
|
262
|
-
for i in range(0, len(attr_list), 2):
|
|
263
|
-
attrib[fixname(attr_list[i])] = attr_list[i+1]
|
|
264
|
-
e = self.target.start(tag, attrib)
|
|
265
|
-
return e
|
|
266
|
-
|
|
267
|
-
def _end(self, tag):
|
|
268
|
-
return self.target.end(self._fixname(tag))
|
|
269
|
-
|
|
270
|
-
def _default(self, text):
|
|
271
|
-
prefix = text[:1]
|
|
272
|
-
if prefix == "&":
|
|
273
|
-
try:
|
|
274
|
-
data_handler = self.target.data
|
|
275
|
-
except AttributeError:
|
|
276
|
-
return
|
|
277
|
-
try:
|
|
278
|
-
data_handler(self.entity[text[1:-1]])
|
|
279
|
-
except KeyError:
|
|
280
|
-
from xml.parsers import expat
|
|
281
|
-
err = expat.error(
|
|
282
|
-
"undefined entity %s: line %d, column %d" %
|
|
283
|
-
(text, self.parser.ErrorLineNumber,
|
|
284
|
-
self.parser.ErrorColumnNumber)
|
|
285
|
-
)
|
|
286
|
-
err.code = 11 # XML_ERROR_UNDEFINED_ENTITY
|
|
287
|
-
err.lineno = self.parser.ErrorLineNumber
|
|
288
|
-
err.offset = self.parser.ErrorColumnNumber
|
|
289
|
-
raise err
|
|
290
|
-
elif prefix == "<" and text[:9] == "<!DOCTYPE":
|
|
291
|
-
self._doctype = []
|
|
292
|
-
elif self._doctype is not None:
|
|
293
|
-
if prefix == ">":
|
|
294
|
-
self._doctype = None
|
|
295
|
-
return
|
|
296
|
-
text = text.strip()
|
|
297
|
-
if not text:
|
|
298
|
-
return
|
|
299
|
-
self._doctype.append(text)
|
|
300
|
-
n = len(self._doctype)
|
|
301
|
-
if n > 2:
|
|
302
|
-
type = self._doctype[1]
|
|
303
|
-
if type == "PUBLIC" and n == 4:
|
|
304
|
-
name, type, pubid, system = self._doctype
|
|
305
|
-
if pubid:
|
|
306
|
-
pubid = pubid[1:-1]
|
|
307
|
-
elif type == "SYSTEM" and n == 3:
|
|
308
|
-
name, type, system = self._doctype
|
|
309
|
-
pubid = None
|
|
310
|
-
else:
|
|
311
|
-
return
|
|
312
|
-
if hasattr(self.target, "doctype"):
|
|
313
|
-
self.target.doctype(name, pubid, system[1:-1])
|
|
314
|
-
elif self.doctype != self._XMLParser__doctype:
|
|
315
|
-
# warn about deprecated call
|
|
316
|
-
# self._XMLParser__doctype(name, pubid, system[1:-1])
|
|
317
|
-
self.doctype(name, pubid, system[1:-1])
|
|
318
|
-
self._doctype = None
|
|
319
|
-
|
|
320
|
-
def doctype(self, name, pubid, system):
|
|
321
|
-
warnings.warn("This method of XMLParser is deprecated. Define doctype() method on the TreeBuilder target.", DeprecationWarning)
|
|
322
|
-
|
|
323
|
-
__doctype = doctype
|
|
324
|
-
_XMLParser__doctype = doctype
|
|
325
|
-
|
|
326
|
-
def feed(self, data):
|
|
327
|
-
try:
|
|
328
|
-
self.parser.Parse(data, 0)
|
|
329
|
-
except self._error as v:
|
|
330
|
-
self._raiseerror(v)
|
|
331
|
-
|
|
332
|
-
def close(self):
|
|
333
|
-
try:
|
|
334
|
-
self.parser.Parse("", 1) # end of data
|
|
335
|
-
except self._error as v:
|
|
336
|
-
self._raiseerror(v)
|
|
337
|
-
try:
|
|
338
|
-
close_handler = self.target.close
|
|
339
|
-
except AttributeError:
|
|
340
|
-
pass
|
|
341
|
-
else:
|
|
342
|
-
return close_handler()
|
|
343
|
-
finally:
|
|
344
|
-
del self.parser, self._parser
|
|
345
|
-
del self.target, self._target
|
|
346
|
-
|
|
347
|
-
def XML(text, parser=None):
|
|
348
|
-
"""Parse XML document from string constant.
|
|
349
|
-
|
|
350
|
-
This function can be used to embed "XML Literals" in Python code.
|
|
351
|
-
|
|
352
|
-
*text* is a string containing XML data, *parser* is an
|
|
353
|
-
optional parser instance, defaulting to the standard XMLParser.
|
|
354
|
-
|
|
355
|
-
Returns an Element instance.
|
|
356
|
-
|
|
357
|
-
"""
|
|
358
|
-
if not parser:
|
|
359
|
-
parser = PatchedXMLTreeBuilder(OriginalTreeBuilder(ET._Element_Py))
|
|
360
|
-
parser.feed(text)
|
|
361
|
-
return parser.close()
|
|
362
|
-
|
|
363
|
-
def iterparse(source, events=None, parser=None):
|
|
364
|
-
if parser is None:
|
|
365
|
-
parser = PatchedXMLTreeBuilder(OriginalTreeBuilder(ET._Element_Py))
|
|
366
|
-
return Original_iterparse(source, events, parser)
|
|
367
|
-
|
|
368
|
-
def parse(source, parser=None):
|
|
369
|
-
if parser is None:
|
|
370
|
-
parser = PatchedXMLTreeBuilder(OriginalTreeBuilder(ET._Element_Py))
|
|
371
|
-
return Original_parse(source, parser)
|
|
372
|
-
|
|
373
|
-
def serialize_xml(write, elem, qnames, namespaces, short_empty_elements, **kwargs):
|
|
374
|
-
if getattr(elem, '_is_cdata', False):
|
|
375
|
-
if elem.text:
|
|
376
|
-
write("<![CDATA[%s]]>" % elem.text)
|
|
377
|
-
if elem.tail:
|
|
378
|
-
write(elem.tail)
|
|
379
|
-
else:
|
|
380
|
-
Original_serialize_xml(write, elem, qnames, namespaces, short_empty_elements, **kwargs)
|
|
381
|
-
|
|
382
|
-
ET.Element = ET._Element_Py
|
|
383
|
-
ET.SubElement = OriginalSubElement
|
|
384
|
-
ET.XML = ET.fromstring = XML
|
|
385
|
-
ET.iterparse = iterparse
|
|
386
|
-
ET.parse = parse
|
|
387
|
-
ET._serialize_xml = serialize_xml
|
|
388
|
-
|
|
389
|
-
else:
|
|
390
|
-
def serialize_xml(write, elem, encoding, qnames, namespaces, **kwargs):
|
|
391
|
-
if getattr(elem, '_is_cdata', False):
|
|
392
|
-
if elem.text:
|
|
393
|
-
text = elem.text.encode(encoding)
|
|
394
|
-
write("<![CDATA[%s]]>" % text)
|
|
395
|
-
if elem.tail:
|
|
396
|
-
write(elem.tail)
|
|
397
|
-
else:
|
|
398
|
-
Original_serialize_xml(write, elem, encoding, qnames, namespaces, **kwargs)
|
|
399
|
-
|
|
400
|
-
OriginalXMLTreeBuilder = ET.XMLTreeBuilder
|
|
401
|
-
ET._serialize_xml = serialize_xml
|
|
402
|
-
ET._Element_Py = ET.Element
|
|
403
|
-
|
|
404
|
-
class PatchedXMLTreeBuilder(OriginalXMLTreeBuilder):
|
|
405
|
-
def __init__(self, html=0, target=None, remove_comments=True, parse_comments=False, strip_cdata=True):
|
|
406
|
-
OriginalXMLTreeBuilder.__init__(self, html, target)
|
|
407
|
-
self._parser.StartCdataSectionHandler = self._start_cdata
|
|
408
|
-
self._parser.EndCdataSectionHandler = self._end_cdata
|
|
409
|
-
self._parser.CharacterDataHandler = self._data
|
|
410
|
-
if (not parse_comments) or remove_comments:
|
|
411
|
-
self._parser.CommentHandler = None
|
|
412
|
-
else:
|
|
413
|
-
self._parser.CommentHandler = self._handle_comment
|
|
414
|
-
self._parser.ProcessingInstructionHandler = self._handle_pi
|
|
415
|
-
self._cdataSection = False
|
|
416
|
-
self._cdataBuffer = None
|
|
417
|
-
self._strip_cdata = strip_cdata
|
|
418
|
-
|
|
419
|
-
def _start(self, tag, attrib_in):
|
|
420
|
-
elem = OriginalXMLTreeBuilder._start(self, tag, attrib_in)
|
|
421
|
-
if isinstance(elem, ET._Element_Py):
|
|
422
|
-
elem.sourceline = elem.lineno = self._parser.CurrentLineNumber
|
|
423
|
-
elem.offset = elem.column = self._parser.CurrentColumnNumber
|
|
424
|
-
return elem
|
|
425
|
-
|
|
426
|
-
def _start_list(self, tag, attrib_in):
|
|
427
|
-
elem = OriginalXMLTreeBuilder._start_list(self, tag, attrib_in)
|
|
428
|
-
if isinstance(elem, ET._Element_Py):
|
|
429
|
-
elem.sourceline = elem.lineno = self._parser.CurrentLineNumber
|
|
430
|
-
elem.offset = elem.column = self._parser.CurrentColumnNumber
|
|
431
|
-
return elem
|
|
432
|
-
|
|
433
|
-
def _start_cdata(self):
|
|
434
|
-
"""
|
|
435
|
-
A CDATA section beginning has been recognized - start collecting
|
|
436
|
-
character data.
|
|
437
|
-
"""
|
|
438
|
-
self._cdataSection = True
|
|
439
|
-
self._cdataBuffer = []
|
|
440
|
-
|
|
441
|
-
def _end_cdata(self):
|
|
442
|
-
"""
|
|
443
|
-
The CDATA section has ended - join the character data we collected
|
|
444
|
-
and add a CDATA element to the target tree.
|
|
445
|
-
"""
|
|
446
|
-
self._cdataSection = False
|
|
447
|
-
if not self._strip_cdata:
|
|
448
|
-
text = "".join(self._cdataBuffer)
|
|
449
|
-
if not PY3:
|
|
450
|
-
text = self._fixtext(text)
|
|
451
|
-
elem = self._target.start(None, {})
|
|
452
|
-
elem._is_cdata = True
|
|
453
|
-
self._target.data(text)
|
|
454
|
-
self._target.end(None)
|
|
455
|
-
elem.text = text
|
|
456
|
-
self._cdataBuffer = []
|
|
457
|
-
# print("created cdata with content:\n---\n%s\n---" % text)
|
|
458
|
-
|
|
459
|
-
def _handle_comment(self, data):
|
|
460
|
-
return ET.Comment(self._fixtext(data))
|
|
461
|
-
|
|
462
|
-
def _handle_pi(self, target, data):
|
|
463
|
-
return ET.PI(self._fixtext(target), self._fixtext(data))
|
|
464
|
-
|
|
465
|
-
def _data(self, text):
|
|
466
|
-
"""
|
|
467
|
-
If we are in the middle of a CDATA section, collect the data into a
|
|
468
|
-
special buffer, otherwise treat it as before.
|
|
469
|
-
"""
|
|
470
|
-
if self._cdataSection:
|
|
471
|
-
self._cdataBuffer.append(text)
|
|
472
|
-
else:
|
|
473
|
-
self._target.data(text)
|
|
474
|
-
|
|
475
|
-
def CDATA(text=None):
|
|
476
|
-
element = ET.Element(None)
|
|
477
|
-
element.text = text
|
|
478
|
-
element._is_cdata = True
|
|
479
|
-
return element
|
|
480
|
-
|
|
481
|
-
ET.XMLTreeBuilder = ET.XMLParser = PatchedXMLTreeBuilder
|
|
482
|
-
ET._serialize['xml'] = ET._serialize_xml
|
|
483
|
-
ET.CDATA = CDATA
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
try:
|
|
488
|
-
from xml.etree.ElementTree import CDATA
|
|
489
|
-
except:
|
|
490
|
-
_patch_etree()
|
|
491
|
-
|
|
492
|
-
|
kongalib/parsetab.py
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
# parsetab.py
|
|
3
|
-
# This file is automatically generated. Do not edit.
|
|
4
|
-
_tabversion = '3.2'
|
|
5
|
-
|
|
6
|
-
_lr_method = 'LALR'
|
|
7
|
-
|
|
8
|
-
_lr_signature = '\xa4\x8ah\xbf\x8b\xde\x16d;\x84\xd8\x0b\xf7}\x1b\x86'
|
|
9
|
-
|
|
10
|
-
_lr_action_items = {'AND':([4,10,11,14,16,19,20,21,22,23,24,27,],[12,-4,12,-8,-6,-3,-5,-1,12,-7,-9,-10,]),'RPAREN':([10,11,14,16,19,20,21,22,23,24,25,26,27,29,],[-4,20,-8,-6,-3,-5,-1,-2,-7,-9,27,-11,-10,-12,]),'LIKE':([1,7,],[5,17,]),'IS':([1,],[6,]),'VALUE':([5,9,17,18,28,],[14,19,24,26,26,]),'OR':([4,10,11,14,16,19,20,21,22,23,24,27,],[13,-4,13,-8,-6,-3,-5,-1,-2,-7,-9,-10,]),'OPERAND':([1,],[9,]),'COMMA':([26,],[28,]),'LPAREN':([0,2,3,8,12,13,],[3,3,3,18,3,3,]),'IN':([1,],[8,]),'NOT':([0,1,2,3,6,12,13,],[2,7,2,2,15,2,2,]),'NULL':([6,15,],[16,23,]),'ID':([0,2,3,12,13,],[1,1,1,1,1,]),'$end':([4,10,14,16,19,20,21,22,23,24,27,],[0,-4,-8,-6,-3,-5,-1,-2,-7,-9,-10,]),}
|
|
11
|
-
|
|
12
|
-
_lr_action = { }
|
|
13
|
-
for _k, _v in _lr_action_items.items():
|
|
14
|
-
for _x,_y in zip(_v[0],_v[1]):
|
|
15
|
-
if not _x in _lr_action: _lr_action[_x] = { }
|
|
16
|
-
_lr_action[_x][_k] = _y
|
|
17
|
-
del _lr_action_items
|
|
18
|
-
|
|
19
|
-
_lr_goto_items = {'valueslist':([18,28,],[25,29,]),'expression':([0,2,3,12,13,],[4,10,11,21,22,]),}
|
|
20
|
-
|
|
21
|
-
_lr_goto = { }
|
|
22
|
-
for _k, _v in _lr_goto_items.items():
|
|
23
|
-
for _x,_y in zip(_v[0],_v[1]):
|
|
24
|
-
if not _x in _lr_goto: _lr_goto[_x] = { }
|
|
25
|
-
_lr_goto[_x][_k] = _y
|
|
26
|
-
del _lr_goto_items
|
|
27
|
-
_lr_productions = [
|
|
28
|
-
("S' -> expression","S'",1,None,None,None),
|
|
29
|
-
('expression -> expression AND expression','expression',3,'p_expression_and','expression.py',66),
|
|
30
|
-
('expression -> expression OR expression','expression',3,'p_expression_or','expression.py',70),
|
|
31
|
-
('expression -> ID OPERAND VALUE','expression',3,'p_expression_binop','expression.py',74),
|
|
32
|
-
('expression -> NOT expression','expression',2,'p_expression_not','expression.py',78),
|
|
33
|
-
('expression -> LPAREN expression RPAREN','expression',3,'p_expression_paren','expression.py',82),
|
|
34
|
-
('expression -> ID IS NULL','expression',3,'p_expression_is_null','expression.py',86),
|
|
35
|
-
('expression -> ID IS NOT NULL','expression',4,'p_expression_is_not_null','expression.py',90),
|
|
36
|
-
('expression -> ID LIKE VALUE','expression',3,'p_expression_like','expression.py',94),
|
|
37
|
-
('expression -> ID NOT LIKE VALUE','expression',4,'p_expression_not_like','expression.py',98),
|
|
38
|
-
('expression -> ID IN LPAREN valueslist RPAREN','expression',5,'p_expression_in','expression.py',102),
|
|
39
|
-
('valueslist -> VALUE','valueslist',1,'p_valueslist_single','expression.py',111),
|
|
40
|
-
('valueslist -> VALUE COMMA valueslist','valueslist',3,'p_valueslist_multi','expression.py',115),
|
|
41
|
-
]
|