xhtm 0.5__tar.gz → 0.7__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.
Files changed (30) hide show
  1. {xhtm-0.5 → xhtm-0.7}/PKG-INFO +3 -2
  2. {xhtm-0.5 → xhtm-0.7}/xhtm.egg-info/PKG-INFO +3 -2
  3. xhtm-0.7/xhtm.egg-info/requires.txt +3 -0
  4. {xhtm-0.5 → xhtm-0.7}/xhtml/attribute.py +1 -1
  5. {xhtm-0.5 → xhtm-0.7}/xhtml/header/accept.py +1 -1
  6. {xhtm-0.5 → xhtm-0.7}/xhtml/header/headers.py +27 -0
  7. {xhtm-0.5 → xhtm-0.7}/xhtml/locale/template.py +4 -3
  8. {xhtm-0.5 → xhtm-0.7}/xhtml/resource/__init__.py +28 -12
  9. {xhtm-0.5 → xhtm-0.7}/xhtml/template/__init__.py +4 -2
  10. xhtm-0.5/xhtm.egg-info/requires.txt +0 -2
  11. {xhtm-0.5 → xhtm-0.7}/LICENSE +0 -0
  12. {xhtm-0.5 → xhtm-0.7}/README.md +0 -0
  13. {xhtm-0.5 → xhtm-0.7}/setup.cfg +0 -0
  14. {xhtm-0.5 → xhtm-0.7}/setup.py +0 -0
  15. {xhtm-0.5 → xhtm-0.7}/xhtm.egg-info/SOURCES.txt +0 -0
  16. {xhtm-0.5 → xhtm-0.7}/xhtm.egg-info/dependency_links.txt +0 -0
  17. {xhtm-0.5 → xhtm-0.7}/xhtm.egg-info/top_level.txt +0 -0
  18. {xhtm-0.5 → xhtm-0.7}/xhtm.egg-info/zip-safe +0 -0
  19. {xhtm-0.5 → xhtm-0.7}/xhtml/__init__.py +0 -0
  20. {xhtm-0.5 → xhtm-0.7}/xhtml/element/__init__.py +0 -0
  21. {xhtm-0.5 → xhtm-0.7}/xhtml/element/attr.py +0 -0
  22. {xhtm-0.5 → xhtm-0.7}/xhtml/element/css.py +0 -0
  23. {xhtm-0.5 → xhtm-0.7}/xhtml/element/doc.py +0 -0
  24. {xhtm-0.5 → xhtm-0.7}/xhtml/element/tag.py +0 -0
  25. {xhtm-0.5 → xhtm-0.7}/xhtml/header/__init__.py +0 -0
  26. {xhtm-0.5 → xhtm-0.7}/xhtml/header/content.py +0 -0
  27. {xhtm-0.5 → xhtm-0.7}/xhtml/locale/__init__.py +0 -0
  28. {xhtm-0.5 → xhtm-0.7}/xhtml/resource/favicon.ico +0 -0
  29. {xhtm-0.5 → xhtm-0.7}/xhtml/resource/logo.svg +0 -0
  30. {xhtm-0.5 → xhtm-0.7}/xhtml/template/hello.html +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: xhtm
3
- Version: 0.5
3
+ Version: 0.7
4
4
  Summary: Rendering HTML Text
5
5
  Home-page: https://github.com/bondbox/xhtm
6
6
  Author: Mingzhe Zou
@@ -16,7 +16,8 @@ Classifier: Programming Language :: Python :: 3
16
16
  Requires-Python: >=3.8
17
17
  Description-Content-Type: text/markdown
18
18
  License-File: LICENSE
19
- Requires-Dist: xlc>=0.6
19
+ Requires-Dist: xkits-lib>=0.2
20
+ Requires-Dist: xlc>=1.0
20
21
  Requires-Dist: jinja2
21
22
 
22
23
  # xhtm
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: xhtm
3
- Version: 0.5
3
+ Version: 0.7
4
4
  Summary: Rendering HTML Text
5
5
  Home-page: https://github.com/bondbox/xhtm
6
6
  Author: Mingzhe Zou
@@ -16,7 +16,8 @@ Classifier: Programming Language :: Python :: 3
16
16
  Requires-Python: >=3.8
17
17
  Description-Content-Type: text/markdown
18
18
  License-File: LICENSE
19
- Requires-Dist: xlc>=0.6
19
+ Requires-Dist: xkits-lib>=0.2
20
+ Requires-Dist: xlc>=1.0
20
21
  Requires-Dist: jinja2
21
22
 
22
23
  # xhtm
@@ -0,0 +1,3 @@
1
+ xkits-lib>=0.2
2
+ xlc>=1.0
3
+ jinja2
@@ -1,7 +1,7 @@
1
1
  # coding:utf-8
2
2
 
3
3
  __project__ = "xhtm"
4
- __version__ = "0.5"
4
+ __version__ = "0.7"
5
5
  __urlhome__ = "https://github.com/bondbox/xhtm"
6
6
  __description__ = "Rendering HTML Text"
7
7
 
@@ -41,7 +41,7 @@ class AcceptLanguage():
41
41
  def __contains__(self, langtag: LangT) -> bool:
42
42
  return LangTag.get_name(langtag) in self.__languages
43
43
 
44
- def __iter__(self) -> Iterator[LangTag]:
44
+ def __iter__(self) -> Iterator[str]:
45
45
  return iter(self.__languages)
46
46
 
47
47
  def __len__(self) -> int:
@@ -1,6 +1,8 @@
1
1
  # coding:utf-8
2
2
 
3
3
  from enum import Enum
4
+ from typing import Dict
5
+ from typing import Iterator
4
6
 
5
7
 
6
8
  class Headers(Enum):
@@ -65,3 +67,28 @@ class Headers(Enum):
65
67
  VARY = "Vary"
66
68
  VIA = "Via"
67
69
  WARNING = "Warning"
70
+
71
+
72
+ class Cookies():
73
+ def __init__(self, *cookies: str):
74
+ self.__cookies: Dict[str, str] = {}
75
+ for items in cookies:
76
+ for item in items.split(";"):
77
+ if cookie := item.strip():
78
+ k, v = cookie.split("=", maxsplit=1)
79
+ self.__cookies[k.strip()] = v.strip()
80
+
81
+ def __len__(self) -> int:
82
+ return len(self.__cookies)
83
+
84
+ def __iter__(self) -> Iterator[str]:
85
+ return iter(self.__cookies)
86
+
87
+ def __getitem__(self, key: str) -> str:
88
+ return self.__cookies[key]
89
+
90
+ def __contains__(self, key: str) -> bool:
91
+ return key in self.__cookies
92
+
93
+ def get(self, key: str, default: str = "") -> str:
94
+ return self.__cookies.get(key, default)
@@ -2,6 +2,7 @@
2
2
 
3
3
  from os.path import join
4
4
 
5
+ from xkits_lib import TimeUnit
5
6
  from xlc.language.message import Message
6
7
  from xlc.language.segment import Section
7
8
 
@@ -10,9 +11,9 @@ from xhtml.template import Template
10
11
 
11
12
 
12
13
  class LocaleTemplate(Template):
13
- def __init__(self, base: str):
14
- self.__message: Message = Message.load(join(base, "locale"))
15
- super().__init__(base)
14
+ def __init__(self, base: str, lifetime: TimeUnit = 0):
15
+ self.__message: Message = Message(join(base, "locale"))
16
+ super().__init__(base=base, lifetime=lifetime)
16
17
 
17
18
  def search(self, accept_language: str, section: str) -> Section:
18
19
  language: AcceptLanguage = AcceptLanguage(accept_language)
@@ -9,6 +9,9 @@ from os.path import splitext
9
9
  from typing import Optional
10
10
 
11
11
  from jinja2 import Environment
12
+ from xkits_lib import CacheMiss
13
+ from xkits_lib import CachePool
14
+ from xkits_lib import TimeUnit
12
15
 
13
16
  BASE_DIR = dirname(abspath(__file__))
14
17
 
@@ -19,6 +22,7 @@ class FileResource():
19
22
  message = f"No such file: {path}"
20
23
  raise FileNotFoundError(message)
21
24
  self.__ext: str = splitext(path)[1]
25
+ self.__data: Optional[bytes] = None
22
26
  self.__path: str = path
23
27
 
24
28
  @property
@@ -29,13 +33,14 @@ class FileResource():
29
33
  def path(self) -> str:
30
34
  return self.__path
31
35
 
32
- def loads(self) -> str:
33
- with open(self.path, "r", encoding="utf-8") as rhdl:
34
- return rhdl.read()
35
-
36
36
  def loadb(self) -> bytes:
37
- with open(self.path, "rb") as rhdl:
38
- return rhdl.read()
37
+ if self.__data is None:
38
+ with open(self.path, "rb") as rhdl:
39
+ self.__data = rhdl.read()
40
+ return self.__data
41
+
42
+ def loads(self, encoding: str = "utf-8") -> str:
43
+ return self.loadb().decode(encoding=encoding)
39
44
 
40
45
  def render(self, **context: str) -> str:
41
46
  """render html template"""
@@ -45,7 +50,8 @@ class FileResource():
45
50
  class Resource():
46
51
  FAVICON: str = "favicon.ico"
47
52
 
48
- def __init__(self, base: Optional[str] = None):
53
+ def __init__(self, base: Optional[str] = None, lifetime: TimeUnit = 0):
54
+ self.__cache: CachePool[str, FileResource] = CachePool(lifetime)
49
55
  self.__base: str = base if base and isdir(base) else BASE_DIR
50
56
 
51
57
  @property
@@ -56,13 +62,23 @@ class Resource():
56
62
  def favicon(self) -> FileResource:
57
63
  return self.seek(self.FAVICON)
58
64
 
59
- def find(self, *args: str) -> Optional[str]:
65
+ def find(self, *args: str) -> Optional[FileResource]:
60
66
  def check(base: str, real: str) -> Optional[str]:
61
67
  return path if isfile(path := join(base, real)) else check(BASE_DIR, real) if base != BASE_DIR else None # noqa:E501
62
- return check(self.base, join(*args))
68
+
69
+ if (real := join(*args)) in self.__cache:
70
+ try:
71
+ return self.__cache.get(real)
72
+ except CacheMiss:
73
+ pass
74
+
75
+ resource: Optional[FileResource] = None
76
+ if isinstance(path := check(self.base, real), str):
77
+ resource = FileResource(path)
78
+ self.__cache.put(real, resource)
79
+ return resource
63
80
 
64
81
  def seek(self, *args: str) -> FileResource:
65
- path: Optional[str] = self.find(*args)
66
- if not isinstance(path, str):
82
+ if not isinstance(resource := self.find(*args), FileResource):
67
83
  raise FileNotFoundError(f"No such file: {join(*args)}")
68
- return FileResource(path)
84
+ return resource
@@ -5,6 +5,8 @@ from os.path import dirname
5
5
  from os.path import isdir
6
6
  from typing import Optional
7
7
 
8
+ from xkits_lib import TimeUnit
9
+
8
10
  from xhtml.resource import Resource
9
11
 
10
12
  BASE_DIR = dirname(abspath(__file__))
@@ -13,5 +15,5 @@ BASE_DIR = dirname(abspath(__file__))
13
15
  class Template(Resource):
14
16
  FAVICON: str = "favicon.ico"
15
17
 
16
- def __init__(self, base: Optional[str] = None):
17
- super().__init__(base if base and isdir(base) else BASE_DIR)
18
+ def __init__(self, base: Optional[str] = None, lifetime: TimeUnit = 0):
19
+ super().__init__(base if base and isdir(base) else BASE_DIR, lifetime)
@@ -1,2 +0,0 @@
1
- xlc>=0.6
2
- jinja2
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes