lenexpy 0.0.1__tar.gz
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.
- lenexpy-0.0.1/PKG-INFO +4 -0
- lenexpy-0.0.1/lenexpy/__init__.py +2 -0
- lenexpy-0.0.1/lenexpy/adapters.py +95 -0
- lenexpy-0.0.1/lenexpy/decoder/__init__.py +2 -0
- lenexpy-0.0.1/lenexpy/decoder/decoder.py +11 -0
- lenexpy-0.0.1/lenexpy/decoder/encoder.py +13 -0
- lenexpy-0.0.1/lenexpy/decoder/lef_decoder.py +8 -0
- lenexpy-0.0.1/lenexpy/decoder/lef_encoder.py +45 -0
- lenexpy-0.0.1/lenexpy/decoder/lxf_decoder.py +14 -0
- lenexpy-0.0.1/lenexpy/decoder/lxf_encoder.py +23 -0
- lenexpy-0.0.1/lenexpy.egg-info/PKG-INFO +4 -0
- lenexpy-0.0.1/lenexpy.egg-info/SOURCES.txt +15 -0
- lenexpy-0.0.1/lenexpy.egg-info/dependency_links.txt +1 -0
- lenexpy-0.0.1/lenexpy.egg-info/requires.txt +1 -0
- lenexpy-0.0.1/lenexpy.egg-info/top_level.txt +1 -0
- lenexpy-0.0.1/setup.cfg +4 -0
- lenexpy-0.0.1/setup.py +14 -0
lenexpy-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
from datetime import datetime, date, time as dtime
|
|
2
|
+
from xmlbind.compiler import XmlCompiler
|
|
3
|
+
from xmlbind.settings import add_compiler
|
|
4
|
+
|
|
5
|
+
from .models.swimtime import SwimTime, SwimTimeAttr
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class DTimeCompiler(XmlCompiler[dtime]):
|
|
9
|
+
def __init__(self):
|
|
10
|
+
super().__init__(dtime)
|
|
11
|
+
|
|
12
|
+
def unmarshal(self, v):
|
|
13
|
+
if not v:
|
|
14
|
+
return None
|
|
15
|
+
return dtime.fromisoformat(v)
|
|
16
|
+
|
|
17
|
+
def marshal(self, v):
|
|
18
|
+
if not v:
|
|
19
|
+
return None
|
|
20
|
+
return dtime.isoformat(v)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class DateCompiler(XmlCompiler[date]):
|
|
24
|
+
def __init__(self):
|
|
25
|
+
super().__init__(date)
|
|
26
|
+
|
|
27
|
+
def unmarshal(self, v):
|
|
28
|
+
if not v:
|
|
29
|
+
return None
|
|
30
|
+
return date.fromisoformat(v)
|
|
31
|
+
|
|
32
|
+
def marshal(self, v):
|
|
33
|
+
if not v:
|
|
34
|
+
return None
|
|
35
|
+
return date.isoformat(v)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class DtCompiler(XmlCompiler[datetime]):
|
|
39
|
+
def __init__(self):
|
|
40
|
+
super().__init__(datetime)
|
|
41
|
+
|
|
42
|
+
def unmarshal(self, v):
|
|
43
|
+
if not v:
|
|
44
|
+
return None
|
|
45
|
+
return datetime.fromisoformat(v)
|
|
46
|
+
|
|
47
|
+
def marshal(self, v):
|
|
48
|
+
if not v:
|
|
49
|
+
return None
|
|
50
|
+
return datetime.isoformat(v)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class IntCompiler(XmlCompiler[int]):
|
|
54
|
+
def __init__(self):
|
|
55
|
+
super().__init__(int)
|
|
56
|
+
|
|
57
|
+
def unmarshal(self, v):
|
|
58
|
+
if not v:
|
|
59
|
+
return None
|
|
60
|
+
return int(v)
|
|
61
|
+
|
|
62
|
+
def marshal(self, v):
|
|
63
|
+
if not v:
|
|
64
|
+
return None
|
|
65
|
+
return str(v)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class SwimTimeCompiler(XmlCompiler[SwimTime]):
|
|
69
|
+
def __init__(self):
|
|
70
|
+
super().__init__(SwimTime)
|
|
71
|
+
|
|
72
|
+
def unmarshal(self, v):
|
|
73
|
+
if not v:
|
|
74
|
+
return SwimTime.from_attrib(SwimTimeAttr.NT)
|
|
75
|
+
return SwimTime._parse(v)
|
|
76
|
+
|
|
77
|
+
def marshal(self, v: SwimTime):
|
|
78
|
+
return str(v)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
add_compiler(DateCompiler())
|
|
82
|
+
add_compiler(DTimeCompiler())
|
|
83
|
+
add_compiler(DtCompiler())
|
|
84
|
+
add_compiler(IntCompiler())
|
|
85
|
+
add_compiler(SwimTimeCompiler())
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
if __name__ == '__main__':
|
|
89
|
+
comp = SwimTimeCompiler()
|
|
90
|
+
print(comp.unmarshal('NT'))
|
|
91
|
+
d = comp.unmarshal('00:00:19.35')
|
|
92
|
+
print(d)
|
|
93
|
+
|
|
94
|
+
comp = DateCompiler()
|
|
95
|
+
print(comp.unmarshal('24.12.2008'))
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
from lenexpy.decoder.lef_decoder import decode_lef
|
|
3
|
+
from lenexpy.decoder.lxf_decoder import decode_lxf
|
|
4
|
+
from lenexpy.models.lenex import Lenex
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def decode(filename: str) -> Lenex:
|
|
8
|
+
if filename.endswith(('.xml', '.lef')):
|
|
9
|
+
return decode_lef(filename)
|
|
10
|
+
if filename.endswith('.lxf'):
|
|
11
|
+
return decode_lxf(filename)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from lenexpy.models.lenex import Lenex
|
|
2
|
+
from .lef_encoder import encode_lef
|
|
3
|
+
from .lxf_encoder import encode_lxf
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def encode(lenex: Lenex, filename: str):
|
|
7
|
+
if not filename.endswith(('.lxf', '.lef', '.xml')):
|
|
8
|
+
raise TypeError('The file type must be .lxf, .lef, .xml')
|
|
9
|
+
|
|
10
|
+
if filename.endswith(('.xml', '.lef')):
|
|
11
|
+
return encode_lef(lenex, filename)
|
|
12
|
+
if filename.endswith('.lxf'):
|
|
13
|
+
return encode_lxf(lenex, filename)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import re
|
|
2
|
+
import lxml.etree as ET
|
|
3
|
+
|
|
4
|
+
from lenexpy.models.lenex import Lenex
|
|
5
|
+
|
|
6
|
+
BYTES_MODE = 'b'
|
|
7
|
+
ENCODING = 'utf-8'
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def fix_declaration(text: str):
|
|
11
|
+
def change(match: re.Match):
|
|
12
|
+
return f'{match.group(1)}="{match.group(2)}"'
|
|
13
|
+
|
|
14
|
+
return re.sub(r"([a-z]+)='([^']+)'",
|
|
15
|
+
change, text)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def get_declaration(text: str):
|
|
19
|
+
return re.findall(r"<\?xml.*\?>", text)[0]
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def change_declaration(text: str):
|
|
23
|
+
declaration = get_declaration(text)
|
|
24
|
+
declaration2 = fix_declaration(declaration)
|
|
25
|
+
return text.replace(declaration, declaration2)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def encode_base(lenex: Lenex):
|
|
29
|
+
xml_string: bytes = ET.tostring(
|
|
30
|
+
lenex.dump('LENEX'),
|
|
31
|
+
encoding=ENCODING,
|
|
32
|
+
method="xml",
|
|
33
|
+
xml_declaration=True
|
|
34
|
+
)
|
|
35
|
+
xml_string = change_declaration(xml_string.decode(ENCODING)).encode(ENCODING)
|
|
36
|
+
return xml_string
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def encode_lef(lenex: Lenex, filename: str):
|
|
40
|
+
if not filename.endswith(('.lef', '.xml')):
|
|
41
|
+
raise TypeError('The file type must be .lef, .xml')
|
|
42
|
+
|
|
43
|
+
xml_string = encode_base(lenex)
|
|
44
|
+
with open(filename, f"w{BYTES_MODE}+") as f:
|
|
45
|
+
f.write(xml_string)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import lxml.etree as ET
|
|
2
|
+
from zipfile import ZipFile
|
|
3
|
+
from lenexpy.models.lenex import Lenex
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def decode_lxf(filename: str) -> Lenex:
|
|
7
|
+
with ZipFile(filename) as zp:
|
|
8
|
+
if len(zp.filelist) != 1:
|
|
9
|
+
raise TypeError("Incorrect lenex file")
|
|
10
|
+
with zp.open(zp.filelist[0]) as file:
|
|
11
|
+
data = file.read()
|
|
12
|
+
|
|
13
|
+
element = ET.fromstring(data)
|
|
14
|
+
return Lenex._parse(element)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
import tempfile
|
|
3
|
+
from os.path import join
|
|
4
|
+
from zipfile import ZipFile, ZIP_DEFLATED
|
|
5
|
+
from lenexpy.models.lenex import Lenex
|
|
6
|
+
from .lef_encoder import encode_lef
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def encode_lxf(lenex: Lenex, filename: str):
|
|
10
|
+
if not filename.endswith('.lxf'):
|
|
11
|
+
raise TypeError('The file type must be .lxf')
|
|
12
|
+
|
|
13
|
+
fn = Path(filename).name[:-4] + '.lef'
|
|
14
|
+
with tempfile.TemporaryDirectory() as dir:
|
|
15
|
+
path = join(dir, fn)
|
|
16
|
+
encode_lef(lenex, path)
|
|
17
|
+
|
|
18
|
+
with ZipFile(
|
|
19
|
+
filename,
|
|
20
|
+
"w",
|
|
21
|
+
compression=ZIP_DEFLATED
|
|
22
|
+
) as zf:
|
|
23
|
+
zf.write(path, fn)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
setup.py
|
|
2
|
+
lenexpy/__init__.py
|
|
3
|
+
lenexpy/adapters.py
|
|
4
|
+
lenexpy.egg-info/PKG-INFO
|
|
5
|
+
lenexpy.egg-info/SOURCES.txt
|
|
6
|
+
lenexpy.egg-info/dependency_links.txt
|
|
7
|
+
lenexpy.egg-info/requires.txt
|
|
8
|
+
lenexpy.egg-info/top_level.txt
|
|
9
|
+
lenexpy/decoder/__init__.py
|
|
10
|
+
lenexpy/decoder/decoder.py
|
|
11
|
+
lenexpy/decoder/encoder.py
|
|
12
|
+
lenexpy/decoder/lef_decoder.py
|
|
13
|
+
lenexpy/decoder/lef_encoder.py
|
|
14
|
+
lenexpy/decoder/lxf_decoder.py
|
|
15
|
+
lenexpy/decoder/lxf_encoder.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
xmlbind@ file:///C:/Users/2008d/working-space/XmlDecarator
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
lenexpy
|
lenexpy-0.0.1/setup.cfg
ADDED
lenexpy-0.0.1/setup.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
setup(
|
|
5
|
+
name='lenexpy',
|
|
6
|
+
description='LenexPY handler for MEET Entry Editor',
|
|
7
|
+
version='0.0.1',
|
|
8
|
+
install_requires=[
|
|
9
|
+
'xmlbind @ file:///C:/Users/2008d/working-space/XmlDecarator'
|
|
10
|
+
],
|
|
11
|
+
packages=find_packages(),
|
|
12
|
+
# package_dir={'spherical_functions': '.'},
|
|
13
|
+
# data_files=[('lenexpy', ['FINA_Points_Table_Base_Times.xlsx'])]
|
|
14
|
+
)
|