libyare 1.3.1__py2.py3-none-any.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.
@@ -0,0 +1,474 @@
1
+ Metadata-Version: 2.5
2
+ Name: libyare
3
+ Version: 1.3.1
4
+ Summary: LIBrary for YARE (Yet Another Regular Expression) pattern matching
5
+ Author-email: Carlo Alessandro Verre <carlo.alessandro.verre@gmail.com>
6
+ Description-Content-Type: text/markdown
7
+ License-Expression: GPL-3.0-or-later
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Operating System :: POSIX :: Linux
12
+ Classifier: Operating System :: Microsoft :: Windows
13
+ License-File: LICENSE
14
+ Project-URL: Home, https://pypi.org/project/libyare/
15
+ Import-Name: libyare
16
+
17
+ # CONTENTS
18
+ ```
19
+ • 1. Forewords
20
+ • 1.1. Introduction
21
+ • 1.2. Installation
22
+ • 2. Functions
23
+ • 2.1. Match Functions
24
+ • 2.2. Other Functions
25
+ • 3. Patterns
26
+ • 3.1. Simple Patterns
27
+ • 3.1.1. Shell Patterns
28
+ • 3.1.2. Numeric Patterns
29
+ • 3.1.3. Charset Patterns
30
+ • 3.1.4. Filtered Patterns
31
+ • 3.2. Compound Patterns
32
+ • 4. Masks
33
+ • 4.1. The disguise() Function
34
+ • 5. Afterwords
35
+ • 5.1. Versions
36
+ • 5.2. Credits
37
+ ```
38
+ # 1. FOREWORDS
39
+ ## 1.1. INTRODUCTION
40
+ ```
41
+ LIBYARE implements YARE (Yet Another Regular Expression). YARE is a
42
+ regular expression format intended to be more readable than the standard
43
+ one. It can accept simple patterns and compound patterns.
44
+
45
+ Simple patterns can be shell patterns, charset patterns, numeric
46
+ patterns or filtered patterns.
47
+
48
+ Compound patterns are obtained by combining together simple patterns
49
+ with logical operators ('^' = not, '&' = and, ',' = or) and parenthesis
50
+ ('(' and ')').
51
+ ```
52
+ ## 1.2. INSTALLATION
53
+ ```
54
+ If for instance your Linux belongs to the Debian family, type:
55
+
56
+ $ sudo apt install pipx
57
+
58
+ Then type:
59
+
60
+ $ pipx install libyare
61
+ $ pipx ensurepath
62
+
63
+ Later you can upgrade LIBYARE to a new version by:
64
+
65
+ $ pipx upgrade libyare
66
+ ```
67
+ # 2. FUNCTIONS
68
+ ## 2.1. MATCH FUNCTIONS
69
+ ```
70
+ In order to use LIBYARE in your PyPI project, link it in your
71
+ pyproject.toml file:
72
+
73
+ ...
74
+ [project]
75
+ ...
76
+ dependencies = ["libyare", ...]
77
+ ...
78
+
79
+ Then in your program you can write:
80
+
81
+ from libyare import *
82
+
83
+ and use these four match functions:
84
+
85
+ smatch(string, pattern) # case-sensitive match
86
+
87
+ imatch(string, pattern) # case-insensitive match
88
+
89
+ dmatch(string, pattern) # case-depending match, see 3.1.1.
90
+
91
+ fmatch(string, pattern) # filename match, see 3.1.1.
92
+ ```
93
+ ## 2.2. OTHER FUNCTIONS
94
+ ```
95
+ int2human(int, length=6) # converts integer into human-readable,
96
+ # result length must be between 5 and 9
97
+
98
+ human2int(string) # converts human-readable string into integer,
99
+ # on error raises ValueError
100
+
101
+ For details about strings in human-readable integer format, see 3.1.3.
102
+
103
+ disguise(string, mask) # disguise a string by a mask
104
+ ```
105
+ # 3. PATTERNS
106
+ ## 3.1. SIMPLE PATTERNS
107
+ ### 3.1.1. SHELL PATTERNS
108
+ ```
109
+ Shell patterns are standard Unix shell patterns, see documentation of
110
+ fnmatch Python module.
111
+
112
+ General rules:
113
+
114
+ • '*' matches everything
115
+ • '?' matches any single character
116
+ • '[seq]' matches any single character in seq
117
+ • '[!seq]' matches any single character not in seq
118
+
119
+ Examples:
120
+
121
+ • pattern 'abc*' matches any string starting with 'abc'
122
+ • pattern '*abc' matches any string ending with 'abc'
123
+ • pattern '*abc*' matches any string containing 'abc'
124
+ • pattern '[az]' matches 'a' or 'z'
125
+ • pattern '[!az]' matches any single character except 'a' or 'z'
126
+ • pattern '[a-z]' matches any single character between 'a' and 'z'
127
+ ('z' included)
128
+ • pattern '[!a-z]' matches any single character not between 'a' and
129
+ 'z' ('z' included)
130
+ • pattern '[a-z0-9_]' matches any single character between 'a' and
131
+ 'z' or between '0' and '9' or equal to '_'
132
+ • pattern '[!a-z0-9_]' matches any single character not between 'a'
133
+ and 'z' and not between '0' and '9' and not equal to '_'
134
+
135
+ If a metacharacter must belong to a shell pattern with no special
136
+ meaning, it must be quoted between '[' and ']'. More exactly:
137
+
138
+ • '*' '?' '[' '^' '&' ',' '(' and ')' must always be quoted
139
+ • '!' and '-' if not between '[' and ']' have no special meaning and
140
+ don't need to be quoted
141
+ • '=' '<' and '>' need to be quoted only if in first position
142
+ • ']' only can not be quoted, but you should not need it because an
143
+ unmatched ']' has no special meaning and doesn't raise a syntax
144
+ error, while unmatched '[' '(' and ')' do
145
+
146
+ Examples:
147
+
148
+ • pattern '[(]*[)]' matches any string starting with '(' and ending
149
+ with ')'
150
+ • pattern '[[]*]' matches any string starting with '[' and ending
151
+ with ']'
152
+ • pattern '[<]*>' matches any string starting with '<' and ending
153
+ with '>'
154
+ • pattern '[=][[]?*]' matches any charset pattern, see 3.1.2.
155
+
156
+ You can quote '!' too, but not immediately after '[':
157
+
158
+ • pattern '[?!]' matches '?' and '!'
159
+ • pattern '[!?]' matches any character except '?'
160
+
161
+ You can quote metacharacter '-' too, a '-' after '[' or before ']' has
162
+ no special meaning:
163
+
164
+ • patterns '[-pr]' and '[pr-]' match '-' 'p' and 'r'
165
+ • pattern '[p-r]' matches 'p' 'q' and 'r'
166
+
167
+ '-' stands for itself even after a character interval:
168
+
169
+ • pattern '[p-rx]' matches 'p' 'q' 'r' and 'x'
170
+ • pattern '[p-r-x]' matches 'p' 'q' 'r' '-' and 'x'
171
+ • pattern '[p-rx-z]' matches 'p' 'q' 'r' 'x' 'y' and 'z'
172
+ • pattern '[p-r-x-z]' matches 'p' 'q' 'r' '-' 'x' 'y' and 'z'
173
+
174
+ Descending character intervals do not work:
175
+
176
+ • pattern '[z-z]' is accepted and is equivalent to '[z]'
177
+ • pattern '[z-a]' is accepted but it does not match anything
178
+
179
+ They are only two differences between shell patterns defined by
180
+ fnmatch() and fnmatchcase() functions in Python3 fnmatch module and
181
+ shell patterns accepted by YARE:
182
+
183
+ • unmatched '[' (as in pattern 'abc[def') is allowed by fnmatch but
184
+ is rejected by YARE as a syntax error
185
+ • null pattern '' is allowed by fnmatch but is rejected by YARE as a
186
+ syntax error (see later for a workaround to match a null string by
187
+ a not null pattern)
188
+
189
+ Match of shell patterns can be:
190
+
191
+ • case-sensitive, by yarecsmatch() function
192
+ • case-insensitive, by yarecimatch() function
193
+ • case-depending, by yarecdmatch() function
194
+ • filename, by yareosmatch() function
195
+
196
+ case-depending match is case-sensitive for shell patterns containing at
197
+ least one lowercase letter, case-insensitive for the others:
198
+
199
+ • dmatch('ram', 'RAM,?*.db') --> True
200
+ • dmatch('Ram', 'RAM,?*.db') --> True
201
+ • dmatch('x.db', 'RAM,?*.db') --> True
202
+ • dmatch('x.Db', 'RAM,?*.db') --> False
203
+
204
+ Filename match for shell patterns is case-sensitive if the current
205
+ platform requires it (namely on Linux), else is case-insensitive (namely
206
+ on Windows):
207
+
208
+ • fmatch('x.JPG', '*.jpg') --> True on MS-Windows, False on Linux
209
+ but not under Linux
210
+ ```
211
+ ### 3.1.2. NUMERIC PATTERNS
212
+ ```
213
+ A numeric pattern is made up of a comparison operator followed by an
214
+ integer in human-readable format. It matches all strings which,
215
+ converted from human-readable format into integer, satisfy the given
216
+ comparison. Allowed comparison operators are:
217
+
218
+ • '<' = less than
219
+ • '=' = equal
220
+ • '>' = greater than
221
+ • '<=' = less or equal
222
+ • '<>' = not equal
223
+ • '>=' = greater or equal
224
+
225
+ WARNING: no other comparison operator (as '==' or '!=') is accepted.
226
+
227
+ An integer in human-readable format is made up of:
228
+
229
+ • an optional plus '+' or minus '-' sign
230
+ • an integer or float literal
231
+ • an optional final alphabetic multiplier:
232
+ • 'K' = 1024
233
+ • 'M' = 1024 ** 2
234
+ • 'G' = 1024 ** 3
235
+ • 'T' = 1024 ** 4
236
+ • 'P' = 1024 ** 5
237
+ • 'E' = 1024 ** 6
238
+ • 'Z' = 1024 ** 7
239
+ • 'Y' = 1024 ** 8
240
+
241
+ Examples:
242
+
243
+ • patterns '<0.5K' and '<512' are equivalent, they match all strings
244
+ which, interpreted as a human-readable integer, give a value less
245
+ than 512
246
+ • patterns '<0.5E3' and '<500' are equivalent, they match all
247
+ strings which, interpreted as a human-readable integer, give a
248
+ value less than 500
249
+
250
+ Numeric match is always case-insensitive, the final alphabetic
251
+ multiplier and the 'E' in float literals can be uppercase or lowercase.
252
+
253
+ Both pattern and string can give an error in conversion from
254
+ human-readable format into integer. A pattern error raises a SyntaxError
255
+ exception, while a string error makes the match function return a result
256
+ of False:
257
+
258
+ • pattern '=0,<>0' matches only the strings in well-formed
259
+ human-readable integer format
260
+ ```
261
+ ### 3.1.3. CHARSET PATTERNS
262
+ ```
263
+ A charset pattern is matched by the '[=][[]*]' pattern, it starts with
264
+ '=[' and ends with ']', it is made up of a '=' character followed by a
265
+ shell pattern suitable to match a single character. It matches the null
266
+ string and all strings where each character matches the given shell
267
+ pattern, examples:
268
+
269
+ • pattern '=[0-9]' matches the null string and any string made up of
270
+ only digits (it is equivalent to '^*[!0-9]*')
271
+ • pattern '=[!0-9]' matches the null string and any string made up
272
+ of only non-digit characters (it is equivalent to '^*[0-9]*')
273
+
274
+ Charset match is always case-sensitive:
275
+
276
+ • pattern '=[a-zA-Z0-9_]&[!0-9]*' matches Python identifiers
277
+ ```
278
+ ### 3.1.4. FILTERED PATTERNS
279
+ ```
280
+ A filtered pattern is matched by the '[=][[]*]?*' pattern, it is made by
281
+ two components:
282
+
283
+ • a charset pattern...
284
+ • ...followed by a pattern of any type (also a filtered pattern, if
285
+ you think you need it)
286
+
287
+ Match is performed as follows:
288
+
289
+ • the string to be matched is filtered by the charset pattern, the
290
+ matching characters are kept, while unmatching characters are
291
+ discarded
292
+ • the resulting filtered string is matched against the following
293
+ pattern
294
+
295
+ A filtered pattern is always distinguished from a charset pattern
296
+ because the null pattern is not allowed. Examples:
297
+
298
+ • pattern '=[0-9]2026*' matches all strings whose numeric characters
299
+ make a string starting with '2026', regardless any intermixed
300
+ nonnumeric character
301
+
302
+ • pattern '=[0-9]<1000' matches all strings whose numeric characters
303
+ make a number less than 1000, regardless any intermixed nonnumeric
304
+ character
305
+
306
+ • pattern '=[a-z]???' matches all strings containing exactly three
307
+ lowercase alphabetic characters, regardless any intermixed
308
+ character of other kinds
309
+ ```
310
+ ## 3.2. COMPOUND PATTERNS
311
+ ```
312
+ A compound pattern is made by combining simple patterns with logical
313
+ operators:
314
+
315
+ • '^' = not
316
+ • '&' = and
317
+ • ',' = or
318
+
319
+ and parenthesis '(' and ')'.
320
+
321
+ In the following examples, p and q are two simple patterns:
322
+
323
+ • pattern '^p' matches any string not matched by p
324
+ • pattern 'p&q' matches any string matched by both p and q
325
+ • pattern 'p,q' matches any string matched by p or q or both
326
+ • pattern '*.jpg,*.mp4' matches any string ending with '.jpg' or
327
+ with '.mp4'
328
+ • pattern '^*' does not match anything
329
+ • pattern '?*' matches any string of one or more characters, so...
330
+ • ...pattern '^?*' matches the null string and nothing else
331
+
332
+ Two '^' characters cancel each other out:
333
+
334
+ • patterns '^^p' and 'p' are equivalent
335
+
336
+ Precedence is of course '^' > '&' > ','. Precedence can be forced by
337
+ parenthesis, so YARE follows the usual rules of Boolean algebra, namely
338
+ by the De Morgan's laws we get for each pattern p and q:
339
+
340
+ • patterns '^p&^q' and '^(p,q)' are equivalent
341
+ • patterns '^p,^q' and '^(p&q)' are equivalent
342
+
343
+ and by the distribution laws we get for each pattern p, q and r:
344
+
345
+ • patterns 'p&(q,r)' and '(p&q),(p&r)' are equivalent
346
+ • patterns 'p,(q&r)' and '(p,q)&(p,r)' are equivalent
347
+
348
+ Nesting of parenthesis has no practical limit. Example:
349
+
350
+ • pattern '=[0-9.]&=[.]...&[0-9]*[0-9]&^*..*' matches any string
351
+ containing four dot-separated unsigned decimal numbers
352
+ ```
353
+ # 4. MASKS
354
+ ## 4.1. THE disguise() FUNCTION
355
+ ```
356
+ The disguise(string, mask) function transforms a string by a mask. A
357
+ mask can contain:
358
+
359
+ • any character (except '[' and '*') which is copied as is from the
360
+ mask into the result
361
+ • index expressions between '[' and ']', which extract a single
362
+ character from the string into the result
363
+ • slice expressions between '[' and ']', which extract many
364
+ characters from the string into the result
365
+ • asterisks '*', which are simply shortcuts for the slice expression
366
+ '[:]' which copies the whole original string into the result
367
+
368
+ Indexing and slicing follow the syntax of Python's indexing and slicing.
369
+ Indexing works as follows:
370
+
371
+ • '[j]' selects the j-th character in the string
372
+
373
+ Index j must be an integer literal, can be negative and is mandatory,
374
+ '[]' is not allowed. The first character is selected by '[0]', the
375
+ second one by '[1]' and so on. A negative j means index counting from
376
+ the end, '[-1]' selects the last character, '[-2]' selects the
377
+ penultimate one, and so on. If j falls out of the string boundaries, no
378
+ error is raisen and nothing is added to the result.
379
+
380
+ Slicing works as follows:
381
+
382
+ • '[a:z]' selects all characters in the string with index j such
383
+ that a <= j < z
384
+ • '[a:z:s]' selects all items in the string with index j where j = i
385
+ + k * s, with k >= 0 and a <= j < z
386
+
387
+ Indexes a, z and s (start, end and step) must be integer literals, can
388
+ be negative and are optional, s can not be zero. Defaults are:
389
+
390
+ • default for s is 1
391
+ • if s is positive, default for a and z are start and end of the
392
+ string
393
+ • if s is negative, defaults for a and z are end and start of the
394
+ string
395
+
396
+ Examples:
397
+
398
+ • disguise('abcd', 'xy') -> 'xy'
399
+ • disguise('abcd', 'x[1]y') -> 'xby'
400
+ • disguise('abcd', 'x[11]y') -> 'xy'
401
+ • disguise('abcd', 'x[-1]y') -> 'xdy'
402
+ • disguise('abcd', 'x[:3]y') -> 'xabcy'
403
+ • disguise('abcd', 'x[1:3]y') -> 'xbcy'
404
+ • disguise('abcd', 'x[3:1]y') -> 'xy'
405
+ • disguise('abcd', 'x[3:1:-1]y') -> 'xdcy'
406
+ • disguise('abcd', 'x[9:99]y') -> 'xy'
407
+ • disguise('abcd', 'x[:]y') -> 'xabcdy'
408
+ • disguise('abcd', 'x*y') -> 'xabcdy'
409
+ • disguise('abcd', 'x**y') -> 'xabcdabcdy'
410
+ • disguise('abcd', 'x[::-1]y') -> 'xdcbay'
411
+ ```
412
+ # 5. AFTERWORDS
413
+ ## 5.1. VERSIONS
414
+ ```
415
+ • 1.3.1 (Production/Stable)
416
+ • added: filtered patterns
417
+ • added: new names for match functions: smatch() imatch()
418
+ dmatch() and fmatch()
419
+ • maintained for back-compatability: old names for match
420
+ functions yarecsmatch() yarecimatch() yarecdmatch() and
421
+ yareosmatch()
422
+ • added: disguise() is_pattern() and is_mask() functions
423
+ • bug: error in human2int() function, fixed
424
+
425
+ • 1.2.1 (Production/Stable)
426
+ • changed: algorithm to convert human-readable to int
427
+ • bug: '|' operator not allowed between dicts in Python 3.6,
428
+ fixed
429
+
430
+ • 1.2.0 (Production/Stable)
431
+ • compatible with previous version
432
+ • added: numeric patterns
433
+
434
+ • 1.1.0 (Production/Stable)
435
+ • compatible with previous version
436
+ • added: charset patterns
437
+ • added: case-depending match by yarecdmatch() function
438
+
439
+ • 1.0.0 (Production/Stable)
440
+ • incompatible with previous versions
441
+ • simplified redefined and optimized
442
+
443
+ • 0.4.3 (Experimental/Deprecated)
444
+ • updated: documentation
445
+
446
+ • 0.4.2 (Experimental/Deprecated)
447
+ • updated: documentation
448
+
449
+ • 0.4.1 (Experimental/Deprecated)
450
+ • first version published on pypi.org '
451
+ ```
452
+ ## 5.2. CREDITS
453
+ ```
454
+ LIBYARE program has been developed by Python 3.11.2 and IDLE 3.11.2.,
455
+ see:
456
+
457
+ https://www.python.org
458
+
459
+ under Debian GNU/Linux 12.11 (bookworm), see:
460
+
461
+ https://www.debian.org.
462
+
463
+ LIBYARE package has been built and published on pypi.org by FLIT 4.0.2
464
+ (a simple packaging tool for simple packages), see:
465
+
466
+ https://pypi.org/project/flit.
467
+
468
+ This help text has been written and formatted by YAWP 2.1.1 (Yet Another
469
+ Word Processor, a word processor for plain text files, with PDF export),
470
+ see:
471
+
472
+ https://pypi.org/project/yawp.
473
+ ```
474
+
@@ -0,0 +1,5 @@
1
+ libyare.py,sha256=FyujsS3fVoSRGC177V4R2Qjze3OJGTit_HFUsXCRDTw,27730
2
+ libyare-1.3.1.dist-info/licenses/LICENSE,sha256=GzeCzK17hhQQDNow0_r0L8OfLpeTKQjFQwBQU7ZUymg,32473
3
+ libyare-1.3.1.dist-info/WHEEL,sha256=V9y3ZlZtah6aABXfVoFIrrNF_4AGkuRlrqcZ3DuCRug,99
4
+ libyare-1.3.1.dist-info/METADATA,sha256=yR5BVaoReVjsjhpRUe_867YGYSvYMCioJiV0yYg0PpQ,16588
5
+ libyare-1.3.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: flit 4.0.2
3
+ Root-Is-Purelib: true
4
+ Tag: py2-none-any
5
+ Tag: py3-none-any