unicodedata-reader 1.0.1__tar.gz → 1.2.0__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 (17) hide show
  1. {unicodedata_reader-1.0.1 → unicodedata_reader-1.2.0}/PKG-INFO +1 -1
  2. {unicodedata_reader-1.0.1 → unicodedata_reader-1.2.0}/pyproject.toml +1 -1
  3. {unicodedata_reader-1.0.1 → unicodedata_reader-1.2.0}/unicodedata_reader/cli.py +5 -2
  4. {unicodedata_reader-1.0.1 → unicodedata_reader-1.2.0}/unicodedata_reader/reader.py +24 -1
  5. {unicodedata_reader-1.0.1 → unicodedata_reader-1.2.0}/unicodedata_reader/set.py +2 -0
  6. {unicodedata_reader-1.0.1 → unicodedata_reader-1.2.0}/LICENSE +0 -0
  7. {unicodedata_reader-1.0.1 → unicodedata_reader-1.2.0}/README.md +0 -0
  8. {unicodedata_reader-1.0.1 → unicodedata_reader-1.2.0}/unicodedata_reader/__init__.py +0 -0
  9. {unicodedata_reader-1.0.1 → unicodedata_reader-1.2.0}/unicodedata_reader/__main__.py +0 -0
  10. {unicodedata_reader-1.0.1 → unicodedata_reader-1.2.0}/unicodedata_reader/bidi_brackets.py +0 -0
  11. {unicodedata_reader-1.0.1 → unicodedata_reader-1.2.0}/unicodedata_reader/compressor.py +0 -0
  12. {unicodedata_reader-1.0.1 → unicodedata_reader-1.2.0}/unicodedata_reader/east_asian_width.py +0 -0
  13. {unicodedata_reader-1.0.1 → unicodedata_reader-1.2.0}/unicodedata_reader/emoji.py +0 -0
  14. {unicodedata_reader-1.0.1 → unicodedata_reader-1.2.0}/unicodedata_reader/entry.py +0 -0
  15. {unicodedata_reader-1.0.1 → unicodedata_reader-1.2.0}/unicodedata_reader/general_category.py +0 -0
  16. {unicodedata_reader-1.0.1 → unicodedata_reader-1.2.0}/unicodedata_reader/line_break.py +0 -0
  17. {unicodedata_reader-1.0.1 → unicodedata_reader-1.2.0}/unicodedata_reader/vertical_orientation.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: unicodedata-reader
3
- Version: 1.0.1
3
+ Version: 1.2.0
4
4
  Summary:
5
5
  Home-page: https://github.com/kojiishi/unicodedata-reader
6
6
  License: Apache-2.0
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
4
4
 
5
5
  [tool.poetry]
6
6
  name = "unicodedata-reader"
7
- version = "1.0.1"
7
+ version = "1.2.0"
8
8
  description = ""
9
9
  authors = ["Koji Ishii <kojii@chromium.org>"]
10
10
  readme = "README.md"
@@ -125,7 +125,8 @@ class UnicodeDataCli(object):
125
125
  parser.add_argument('text',
126
126
  nargs='*',
127
127
  help='show properties for the text')
128
- parser.add_argument('-f', '--no-cache', action='store_true')
128
+ parser.add_argument('-f', '--clear-cache', action='store_true')
129
+ parser.add_argument('-F', '--no-cache', action='store_true')
129
130
  parser.add_argument('--name', help='$NAME in the template')
130
131
  parser.add_argument('-t',
131
132
  '--template',
@@ -139,8 +140,10 @@ class UnicodeDataCli(object):
139
140
  default=0)
140
141
  parser.parse_args(namespace=self)
141
142
  _init_logging(self.verbose) # pytype: disable=attribute-error
143
+ if self.clear_cache:
144
+ UnicodeDataCachedReader.clear_cache()
142
145
  if self.no_cache:
143
- UnicodeDataReader.is_caching_allowed = False
146
+ UnicodeDataReader.default = UnicodeDataReader()
144
147
 
145
148
  def main(self):
146
149
  if self.template:
@@ -1,6 +1,7 @@
1
1
  import logging
2
2
  import pathlib
3
3
  from typing import Iterable
4
+ import shutil
4
5
  import urllib.request
5
6
 
6
7
  from unicodedata_reader.entry import *
@@ -23,6 +24,12 @@ class UnicodeDataReader(object):
23
24
  default = None
24
25
  is_caching_allowed = True
25
26
 
27
+ def __init__(
28
+ self,
29
+ url_template: str = 'https://www.unicode.org/Public/UNIDATA/{0}.txt'
30
+ ) -> None:
31
+ self.url_template = url_template
32
+
26
33
  def bidi_brackets(self) -> UnicodeDataEntries:
27
34
  name = 'BidiBrackets'
28
35
  lines = self.read_lines(name)
@@ -54,6 +61,11 @@ class UnicodeDataReader(object):
54
61
  lines = self.read_lines(name)
55
62
  return UnicodeLineBreakDataEntries(name=name, lines=lines)
56
63
 
64
+ def name(self) -> UnicodeDataEntries:
65
+ lines = self.read_lines('extracted/DerivedName')
66
+ entries = UnicodeDataEntries(name='Name', lines=lines)
67
+ return entries
68
+
57
69
  def scripts(self) -> UnicodeDataEntries:
58
70
  name = 'Scripts'
59
71
  lines = self.read_lines(name)
@@ -69,8 +81,11 @@ class UnicodeDataReader(object):
69
81
  lines = self.read_lines(name)
70
82
  return UnicodeVerticalOrientationDataEntries(name=name, lines=lines)
71
83
 
84
+ def get_url(self, name: str) -> str:
85
+ return self.url_template.format(name)
86
+
72
87
  def read_lines(self, name: str) -> Iterable[str]:
73
- url = f'https://www.unicode.org/Public/UNIDATA/{name}.txt'
88
+ url = self.get_url(name)
74
89
  _logger.debug('Downloading %s', url)
75
90
  with urllib.request.urlopen(url) as response:
76
91
  body = response.read().decode('utf-8')
@@ -107,5 +122,13 @@ class UnicodeDataCachedReader(UnicodeDataReader):
107
122
 
108
123
  return lines
109
124
 
125
+ @staticmethod
126
+ def clear_cache(ignore_errors: bool = False):
127
+ cache_dir = UnicodeDataCachedReader._cache_dir
128
+ if not cache_dir or not cache_dir.exists():
129
+ return
130
+ _logger.debug('Deleting cache %s', cache_dir)
131
+ shutil.rmtree(cache_dir, ignore_errors=ignore_errors)
132
+
110
133
 
111
134
  UnicodeDataReader.default = UnicodeDataCachedReader()
@@ -1,4 +1,6 @@
1
+ from typing import Any
1
2
  from typing import Callable
3
+ from typing import Iterable
2
4
 
3
5
  from unicodedata_reader.entry import *
4
6
  from unicodedata_reader.reader import *