StringGenerator 0.4.4__tar.gz → 0.5.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.
@@ -0,0 +1,29 @@
1
+ Copyright (c) 2014, Yewleaf Ltd.
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are
6
+ met:
7
+
8
+ * Redistributions of source code must retain the above copyright
9
+ notice, this list of conditions and the following disclaimer.
10
+
11
+ * Redistributions in binary form must reproduce the above copyright
12
+ notice, this list of conditions and the following disclaimer in the
13
+ documentation and/or other materials provided with the distribution.
14
+
15
+ * Neither the name of Yewleaf Ltd. nor the names of its contributors
16
+ may be used to endorse or promote products derived from this
17
+ software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
+ HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,189 @@
1
+ Metadata-Version: 2.4
2
+ Name: StringGenerator
3
+ Version: 0.5.1
4
+ Summary: Generate randomized strings of characters using a template
5
+ Home-page: https://github.com/paul-wolf/strgen
6
+ Author: Paul Wolf
7
+ Author-email: paul.wolf@yewleaf.com
8
+ License: BSD
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: BSD License
12
+ Classifier: Programming Language :: Python
13
+ Classifier: Programming Language :: Python :: 3.7
14
+ Classifier: Programming Language :: Python :: 3.8
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Requires-Python: >=3.7
21
+ Description-Content-Type: text/x-rst
22
+ License-File: LICENSE
23
+ Dynamic: author
24
+ Dynamic: author-email
25
+ Dynamic: classifier
26
+ Dynamic: description
27
+ Dynamic: description-content-type
28
+ Dynamic: home-page
29
+ Dynamic: license
30
+ Dynamic: license-file
31
+ Dynamic: requires-python
32
+ Dynamic: summary
33
+
34
+ strgen
35
+ ======
36
+
37
+ |Python package| |RTD build|
38
+
39
+ .. image:: https://img.shields.io/pypi/pyversions/StringGenerator?color=brightgreen
40
+ :alt: PyPI - Python Version
41
+
42
+ .. image:: https://badge.fury.io/py/StringGenerator.svg
43
+ :target: https://badge.fury.io/py/StringGenerator
44
+ :alt: PyPi Version
45
+
46
+
47
+ Generate test data, unique ids, passwords, vouchers or other randomized
48
+ textual data very quickly using a template language. The template
49
+ language is superficially similar to regular expressions but instead of
50
+ defining how to match or capture strings, it defines how to generate
51
+ randomized strings. A very simple invocation to produce a random string
52
+ with word characters of 30 characters length:
53
+
54
+ .. code:: python
55
+
56
+ from strgen import StringGenerator as SG
57
+ SG(r"[\w]{30}").render()
58
+ 'wQjLVRIj1sjjslORpqLJyDObaCnDR2'
59
+
60
+ `Full documentation <https://strgen.readthedocs.io>`__
61
+
62
+ The current package requires Python 3.7 or higher. Use version 0.3.4 or
63
+ earlier if you want to use Python 2.7 or an earlier Python 3 version.
64
+
65
+ NB: with version 0.4.2, the preferred method for generating a unique
66
+ list is ``StringGenerator.render_set()`` instead of ``render_list()``.
67
+ Generate 50000 unique secure tokens in a few seconds:
68
+
69
+ .. code:: python
70
+
71
+ secure_tokens = SG(r"[\p\w]{32}").render_set(50000)
72
+
73
+ ``render_set()`` does not support a progress callback.
74
+
75
+ Performance and secure generation
76
+ ---------------------------------
77
+
78
+ By default ``StringGenerator`` uses ``random.SystemRandom`` (cryptographically
79
+ secure), which reads from the operating system entropy pool on every draw. That
80
+ is the right default for passwords, keys and tokens, but the per-draw syscall
81
+ makes very large batches slow.
82
+
83
+ For large batches you have two faster options:
84
+
85
+ - If you do **not** need cryptographic randomness (e.g. test data), pass a seed
86
+ or a plain ``random.Random`` to use the much faster Mersenne Twister:
87
+
88
+ .. code:: python
89
+
90
+ SG(r"[\d]{10}", seed=1).render_set(1_000_000)
91
+
92
+ - If you **do** need cryptographic randomness, use ``BufferedSecureRandom``. It
93
+ draws the same ``os.urandom`` entropy as ``SystemRandom`` but reads it in bulk
94
+ to avoid a syscall per draw, making secure bulk generation many times faster.
95
+ It is reachable without an extra import:
96
+
97
+ .. code:: python
98
+
99
+ SG(r"[\w\p]{32}", randomizer=SG.BufferedSecureRandom()).render_set(50000)
100
+
101
+ There is a rich feature set to randomize strings in situ or include
102
+ external data.
103
+
104
+ The purpose of this module is to save the Python developer from having
105
+ to write verbose code around the same pattern every time to generate
106
+ passwords, keys, tokens, test data, etc. of this sort:
107
+
108
+ .. code:: python
109
+
110
+ my_secret_key = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(30))
111
+
112
+ that is:
113
+
114
+ 1. Hard to read even at this simplistic level.
115
+
116
+ 2. Hard to safely change quickly. Even modest additions to the
117
+ requirements need unreasonably verbose solutions.
118
+
119
+ 3. Doesn’t use safe encryption standards.
120
+
121
+ 4. Doesn’t provide the implied minimal guarantees of character
122
+ occurance.
123
+
124
+ 5. Hard to track back to requirements (“must be between x and y in
125
+ length and have characters from sets Q, R and S”).
126
+
127
+ The template uses short forms similar to those of regular expressions.
128
+ An example template for generating a strong password:
129
+
130
+ ::
131
+
132
+ [\w\p]{20}
133
+
134
+ will generate something like the following:
135
+
136
+ ::
137
+
138
+ P{:45Ec5$3)2!I68x`{6
139
+
140
+ Guarantee at least two “special” characters in a string:
141
+
142
+ ::
143
+
144
+ [\w\p]{10}&[\p]{2}
145
+
146
+ You can also generate useful test data, like fake emails with plenty of
147
+ variation:
148
+
149
+ ::
150
+
151
+ [\c]{10}.[\c]{5:10}@[\c]{3:12}.(com|net|org)
152
+
153
+ Requirements
154
+ ------------
155
+
156
+ From version 0.4.0, support for Python 2 is dropped. If you still need
157
+ support for Python 2, use version 0.3.4.
158
+
159
+ There are no dependencies beyond the Python Standard Library.
160
+
161
+ Installation
162
+ ------------
163
+
164
+ Install as standard for Python packages from PyPi:
165
+
166
+ .. code:: shell
167
+
168
+ pip install StringGenerator
169
+
170
+ License
171
+ -------
172
+
173
+ Released under the BSD license.
174
+
175
+ Acknowledgements
176
+ ----------------
177
+
178
+ Thanks to Robert LeBlanc who caught some important errors in escaping
179
+ special characters. Thanks to Andreas Motl for the progress counter.
180
+
181
+ Original Author: paul.wolf@yewleaf.com
182
+
183
+ .. |Python package| image:: https://github.com/paul-wolf/strgen/actions/workflows/main.yml/badge.svg
184
+ :target: https://github.com/paul-wolf/strgen/actions/workflows/main.yml
185
+
186
+ .. |RTD build| image:: https://readthedocs.org/projects/strgen/badge/?version=latest
187
+ :target: https://strgen.readthedocs.io/en/latest/?badge=latest
188
+ :alt: Documentation Status
189
+
@@ -26,7 +26,7 @@ with word characters of 30 characters length:
26
26
 
27
27
  `Full documentation <https://strgen.readthedocs.io>`__
28
28
 
29
- The current package requires Python 3.6 or higher. Use version 0.3.4 or
29
+ The current package requires Python 3.7 or higher. Use version 0.3.4 or
30
30
  earlier if you want to use Python 2.7 or an earlier Python 3 version.
31
31
 
32
32
  NB: with version 0.4.2, the preferred method for generating a unique
@@ -35,10 +35,36 @@ Generate 50000 unique secure tokens in a few seconds:
35
35
 
36
36
  .. code:: python
37
37
 
38
- secure_tokens = SG("[\p\w]{32}").render_set(50000)
38
+ secure_tokens = SG(r"[\p\w]{32}").render_set(50000)
39
39
 
40
40
  ``render_set()`` does not support a progress callback.
41
41
 
42
+ Performance and secure generation
43
+ ---------------------------------
44
+
45
+ By default ``StringGenerator`` uses ``random.SystemRandom`` (cryptographically
46
+ secure), which reads from the operating system entropy pool on every draw. That
47
+ is the right default for passwords, keys and tokens, but the per-draw syscall
48
+ makes very large batches slow.
49
+
50
+ For large batches you have two faster options:
51
+
52
+ - If you do **not** need cryptographic randomness (e.g. test data), pass a seed
53
+ or a plain ``random.Random`` to use the much faster Mersenne Twister:
54
+
55
+ .. code:: python
56
+
57
+ SG(r"[\d]{10}", seed=1).render_set(1_000_000)
58
+
59
+ - If you **do** need cryptographic randomness, use ``BufferedSecureRandom``. It
60
+ draws the same ``os.urandom`` entropy as ``SystemRandom`` but reads it in bulk
61
+ to avoid a syscall per draw, making secure bulk generation many times faster.
62
+ It is reachable without an extra import:
63
+
64
+ .. code:: python
65
+
66
+ SG(r"[\w\p]{32}", randomizer=SG.BufferedSecureRandom()).render_set(50000)
67
+
42
68
  There is a rich feature set to randomize strings in situ or include
43
69
  external data.
44
70
 
@@ -0,0 +1,189 @@
1
+ Metadata-Version: 2.4
2
+ Name: StringGenerator
3
+ Version: 0.5.1
4
+ Summary: Generate randomized strings of characters using a template
5
+ Home-page: https://github.com/paul-wolf/strgen
6
+ Author: Paul Wolf
7
+ Author-email: paul.wolf@yewleaf.com
8
+ License: BSD
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: BSD License
12
+ Classifier: Programming Language :: Python
13
+ Classifier: Programming Language :: Python :: 3.7
14
+ Classifier: Programming Language :: Python :: 3.8
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Requires-Python: >=3.7
21
+ Description-Content-Type: text/x-rst
22
+ License-File: LICENSE
23
+ Dynamic: author
24
+ Dynamic: author-email
25
+ Dynamic: classifier
26
+ Dynamic: description
27
+ Dynamic: description-content-type
28
+ Dynamic: home-page
29
+ Dynamic: license
30
+ Dynamic: license-file
31
+ Dynamic: requires-python
32
+ Dynamic: summary
33
+
34
+ strgen
35
+ ======
36
+
37
+ |Python package| |RTD build|
38
+
39
+ .. image:: https://img.shields.io/pypi/pyversions/StringGenerator?color=brightgreen
40
+ :alt: PyPI - Python Version
41
+
42
+ .. image:: https://badge.fury.io/py/StringGenerator.svg
43
+ :target: https://badge.fury.io/py/StringGenerator
44
+ :alt: PyPi Version
45
+
46
+
47
+ Generate test data, unique ids, passwords, vouchers or other randomized
48
+ textual data very quickly using a template language. The template
49
+ language is superficially similar to regular expressions but instead of
50
+ defining how to match or capture strings, it defines how to generate
51
+ randomized strings. A very simple invocation to produce a random string
52
+ with word characters of 30 characters length:
53
+
54
+ .. code:: python
55
+
56
+ from strgen import StringGenerator as SG
57
+ SG(r"[\w]{30}").render()
58
+ 'wQjLVRIj1sjjslORpqLJyDObaCnDR2'
59
+
60
+ `Full documentation <https://strgen.readthedocs.io>`__
61
+
62
+ The current package requires Python 3.7 or higher. Use version 0.3.4 or
63
+ earlier if you want to use Python 2.7 or an earlier Python 3 version.
64
+
65
+ NB: with version 0.4.2, the preferred method for generating a unique
66
+ list is ``StringGenerator.render_set()`` instead of ``render_list()``.
67
+ Generate 50000 unique secure tokens in a few seconds:
68
+
69
+ .. code:: python
70
+
71
+ secure_tokens = SG(r"[\p\w]{32}").render_set(50000)
72
+
73
+ ``render_set()`` does not support a progress callback.
74
+
75
+ Performance and secure generation
76
+ ---------------------------------
77
+
78
+ By default ``StringGenerator`` uses ``random.SystemRandom`` (cryptographically
79
+ secure), which reads from the operating system entropy pool on every draw. That
80
+ is the right default for passwords, keys and tokens, but the per-draw syscall
81
+ makes very large batches slow.
82
+
83
+ For large batches you have two faster options:
84
+
85
+ - If you do **not** need cryptographic randomness (e.g. test data), pass a seed
86
+ or a plain ``random.Random`` to use the much faster Mersenne Twister:
87
+
88
+ .. code:: python
89
+
90
+ SG(r"[\d]{10}", seed=1).render_set(1_000_000)
91
+
92
+ - If you **do** need cryptographic randomness, use ``BufferedSecureRandom``. It
93
+ draws the same ``os.urandom`` entropy as ``SystemRandom`` but reads it in bulk
94
+ to avoid a syscall per draw, making secure bulk generation many times faster.
95
+ It is reachable without an extra import:
96
+
97
+ .. code:: python
98
+
99
+ SG(r"[\w\p]{32}", randomizer=SG.BufferedSecureRandom()).render_set(50000)
100
+
101
+ There is a rich feature set to randomize strings in situ or include
102
+ external data.
103
+
104
+ The purpose of this module is to save the Python developer from having
105
+ to write verbose code around the same pattern every time to generate
106
+ passwords, keys, tokens, test data, etc. of this sort:
107
+
108
+ .. code:: python
109
+
110
+ my_secret_key = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(30))
111
+
112
+ that is:
113
+
114
+ 1. Hard to read even at this simplistic level.
115
+
116
+ 2. Hard to safely change quickly. Even modest additions to the
117
+ requirements need unreasonably verbose solutions.
118
+
119
+ 3. Doesn’t use safe encryption standards.
120
+
121
+ 4. Doesn’t provide the implied minimal guarantees of character
122
+ occurance.
123
+
124
+ 5. Hard to track back to requirements (“must be between x and y in
125
+ length and have characters from sets Q, R and S”).
126
+
127
+ The template uses short forms similar to those of regular expressions.
128
+ An example template for generating a strong password:
129
+
130
+ ::
131
+
132
+ [\w\p]{20}
133
+
134
+ will generate something like the following:
135
+
136
+ ::
137
+
138
+ P{:45Ec5$3)2!I68x`{6
139
+
140
+ Guarantee at least two “special” characters in a string:
141
+
142
+ ::
143
+
144
+ [\w\p]{10}&[\p]{2}
145
+
146
+ You can also generate useful test data, like fake emails with plenty of
147
+ variation:
148
+
149
+ ::
150
+
151
+ [\c]{10}.[\c]{5:10}@[\c]{3:12}.(com|net|org)
152
+
153
+ Requirements
154
+ ------------
155
+
156
+ From version 0.4.0, support for Python 2 is dropped. If you still need
157
+ support for Python 2, use version 0.3.4.
158
+
159
+ There are no dependencies beyond the Python Standard Library.
160
+
161
+ Installation
162
+ ------------
163
+
164
+ Install as standard for Python packages from PyPi:
165
+
166
+ .. code:: shell
167
+
168
+ pip install StringGenerator
169
+
170
+ License
171
+ -------
172
+
173
+ Released under the BSD license.
174
+
175
+ Acknowledgements
176
+ ----------------
177
+
178
+ Thanks to Robert LeBlanc who caught some important errors in escaping
179
+ special characters. Thanks to Andreas Motl for the progress counter.
180
+
181
+ Original Author: paul.wolf@yewleaf.com
182
+
183
+ .. |Python package| image:: https://github.com/paul-wolf/strgen/actions/workflows/main.yml/badge.svg
184
+ :target: https://github.com/paul-wolf/strgen/actions/workflows/main.yml
185
+
186
+ .. |RTD build| image:: https://readthedocs.org/projects/strgen/badge/?version=latest
187
+ :target: https://strgen.readthedocs.io/en/latest/?badge=latest
188
+ :alt: Documentation Status
189
+
@@ -0,0 +1,11 @@
1
+ LICENSE
2
+ README.rst
3
+ pyproject.toml
4
+ setup.py
5
+ StringGenerator.egg-info/PKG-INFO
6
+ StringGenerator.egg-info/SOURCES.txt
7
+ StringGenerator.egg-info/dependency_links.txt
8
+ StringGenerator.egg-info/top_level.txt
9
+ strgen/__init__.py
10
+ strgen/countries.py
11
+ strgen/tests.py
@@ -0,0 +1,36 @@
1
+ # pyproject.toml
2
+ [build-system]
3
+ requires = ["setuptools>=61"]
4
+ build-backend = "setuptools.build_meta"
5
+
6
+ [tool.pytest.ini_options]
7
+ minversion = "6.0"
8
+ norecursedirs = [".venv", ".hypothesis"]
9
+ addopts = "-ra -q"
10
+ testpaths = [
11
+ "strgen/tests.py",
12
+ ]
13
+
14
+ [tool.ruff]
15
+ line-length = 120
16
+ target-version = "py37"
17
+ exclude = [
18
+ ".venv",
19
+ "docs/_build",
20
+ "profile",
21
+ ]
22
+
23
+ [tool.ruff.lint]
24
+ select = ["E", "F", "B", "C90"]
25
+ ignore = [
26
+ "E203",
27
+ "E266",
28
+ "E501",
29
+ "F403",
30
+ "F401",
31
+ "C901",
32
+ "E731",
33
+ ]
34
+
35
+ [tool.ruff.lint.mccabe]
36
+ max-complexity = 18
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -2,7 +2,7 @@
2
2
  import io
3
3
  import codecs
4
4
  import os.path
5
- from distutils.core import setup
5
+ from setuptools import setup
6
6
 
7
7
  current_dir = os.path.abspath(os.path.dirname(__file__))
8
8
 
@@ -30,6 +30,7 @@ with io.open("README.rst", encoding="utf-8") as file:
30
30
  setup(
31
31
  name="StringGenerator",
32
32
  long_description=long_description,
33
+ long_description_content_type="text/x-rst",
33
34
  description=DESCRIPTION,
34
35
  version=VERSION,
35
36
  url="https://github.com/paul-wolf/strgen",
@@ -39,15 +40,18 @@ setup(
39
40
  "strgen",
40
41
  ],
41
42
  license="BSD",
43
+ python_requires=">=3.7",
42
44
  classifiers=[
43
45
  "Development Status :: 5 - Production/Stable",
44
46
  "Intended Audience :: Developers",
45
47
  "License :: OSI Approved :: BSD License",
46
48
  "Programming Language :: Python",
47
- "Programming Language :: Python :: 3.6",
48
49
  "Programming Language :: Python :: 3.7",
49
50
  "Programming Language :: Python :: 3.8",
50
51
  "Programming Language :: Python :: 3.9",
52
+ "Programming Language :: Python :: 3.10",
53
+ "Programming Language :: Python :: 3.11",
54
+ "Programming Language :: Python :: 3.12",
51
55
  "Topic :: Software Development :: Libraries :: Python Modules",
52
56
  ],
53
57
  )