PythonExtensionsCollection 0.2.0__py3-none-any.whl → 0.13.0__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.
- PythonExtensionsCollection/Comparison/CComparison.py +341 -0
- PythonExtensionsCollection/Comparison/__init__.py +13 -0
- PythonExtensionsCollection/File/CFile.py +326 -106
- PythonExtensionsCollection/File/__init__.py +1 -1
- PythonExtensionsCollection/Folder/CFolder.py +460 -0
- PythonExtensionsCollection/Folder/__init__.py +13 -0
- PythonExtensionsCollection/PythonExtensionsCollection.pdf +0 -0
- PythonExtensionsCollection/String/CString.py +128 -344
- PythonExtensionsCollection/String/__init__.py +1 -1
- PythonExtensionsCollection/Utils/CUtils.py +77 -74
- PythonExtensionsCollection/Utils/__init__.py +1 -1
- PythonExtensionsCollection/__init__.py +1 -1
- PythonExtensionsCollection/version.py +23 -0
- {PythonExtensionsCollection-0.2.0.dist-info → PythonExtensionsCollection-0.13.0.dist-info}/METADATA +57 -44
- PythonExtensionsCollection-0.13.0.dist-info/RECORD +18 -0
- {PythonExtensionsCollection-0.2.0.dist-info → PythonExtensionsCollection-0.13.0.dist-info}/WHEEL +1 -1
- PythonExtensionsCollection/doc/.buildinfo +0 -4
- PythonExtensionsCollection/doc/File.html +0 -315
- PythonExtensionsCollection/doc/String.html +0 -590
- PythonExtensionsCollection/doc/Utils.html +0 -209
- PythonExtensionsCollection/doc/_modules/PythonExtensionsCollection/File/CFile.html +0 -960
- PythonExtensionsCollection/doc/_modules/PythonExtensionsCollection/String/CString.html +0 -1221
- PythonExtensionsCollection/doc/_modules/PythonExtensionsCollection/Utils/CUtils.html +0 -431
- PythonExtensionsCollection/doc/_modules/index.html +0 -106
- PythonExtensionsCollection/doc/_sources/File.rst.txt +0 -28
- PythonExtensionsCollection/doc/_sources/String.rst.txt +0 -28
- PythonExtensionsCollection/doc/_sources/Utils.rst.txt +0 -28
- PythonExtensionsCollection/doc/_sources/additional_doc/Introduction.rst.txt +0 -365
- PythonExtensionsCollection/doc/_sources/index.rst.txt +0 -27
- PythonExtensionsCollection/doc/_static/_sphinx_javascript_frameworks_compat.js +0 -134
- PythonExtensionsCollection/doc/_static/alabaster.css +0 -701
- PythonExtensionsCollection/doc/_static/basic.css +0 -930
- PythonExtensionsCollection/doc/_static/custom.css +0 -1
- PythonExtensionsCollection/doc/_static/doctools.js +0 -264
- PythonExtensionsCollection/doc/_static/documentation_options.js +0 -14
- PythonExtensionsCollection/doc/_static/file.png +0 -0
- PythonExtensionsCollection/doc/_static/jquery-3.6.0.js +0 -10881
- PythonExtensionsCollection/doc/_static/jquery.js +0 -2
- PythonExtensionsCollection/doc/_static/language_data.js +0 -199
- PythonExtensionsCollection/doc/_static/minus.png +0 -0
- PythonExtensionsCollection/doc/_static/plus.png +0 -0
- PythonExtensionsCollection/doc/_static/pygments.css +0 -82
- PythonExtensionsCollection/doc/_static/searchtools.js +0 -531
- PythonExtensionsCollection/doc/_static/underscore-1.13.1.js +0 -2042
- PythonExtensionsCollection/doc/_static/underscore.js +0 -6
- PythonExtensionsCollection/doc/additional_doc/Introduction.html +0 -365
- PythonExtensionsCollection/doc/genindex.html +0 -292
- PythonExtensionsCollection/doc/index.html +0 -123
- PythonExtensionsCollection/doc/objects.inv +0 -0
- PythonExtensionsCollection/doc/py-modindex.html +0 -138
- PythonExtensionsCollection/doc/search.html +0 -127
- PythonExtensionsCollection/doc/searchindex.js +0 -1
- PythonExtensionsCollection-0.2.0.dist-info/RECORD +0 -48
- {PythonExtensionsCollection-0.2.0.dist-info → PythonExtensionsCollection-0.13.0.dist-info}/LICENSE +0 -0
- {PythonExtensionsCollection-0.2.0.dist-info → PythonExtensionsCollection-0.13.0.dist-info}/top_level.txt +0 -0
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
#
|
|
21
21
|
# XC-CT/ECA3-Queckenstedt
|
|
22
22
|
#
|
|
23
|
-
#
|
|
23
|
+
# 14.11.2022
|
|
24
24
|
#
|
|
25
25
|
# **************************************************************************************************************
|
|
26
26
|
|
|
@@ -30,57 +30,66 @@ import os, ntpath, re
|
|
|
30
30
|
# **************************************************************************************************************
|
|
31
31
|
|
|
32
32
|
class CString(object):
|
|
33
|
-
"""
|
|
33
|
+
"""
|
|
34
|
+
The class ``CString`` contains some string computation methods like e.g. normalizing a path.
|
|
35
|
+
"""
|
|
34
36
|
|
|
35
37
|
# --------------------------------------------------------------------------------------------------------------
|
|
36
38
|
#TM***
|
|
37
39
|
|
|
38
40
|
def NormalizePath(sPath=None, bWin=False, sReferencePathAbs=None, bConsiderBlanks=False, bExpandEnvVars=True, bMask=True):
|
|
39
41
|
"""
|
|
40
|
-
|
|
42
|
+
Normalizes local paths, paths to local network resources and internet addresses
|
|
41
43
|
|
|
42
|
-
**
|
|
44
|
+
**Arguments:**
|
|
43
45
|
|
|
44
|
-
|
|
46
|
+
* ``sPath``
|
|
45
47
|
|
|
46
|
-
|
|
48
|
+
/ *Condition*: required / *Type*: str /
|
|
47
49
|
|
|
48
|
-
|
|
50
|
+
The path to be normalized
|
|
49
51
|
|
|
50
|
-
|
|
52
|
+
* ``bWin``
|
|
51
53
|
|
|
52
|
-
|
|
54
|
+
/ *Condition*: optional / *Type*: bool / *Default*: False /
|
|
53
55
|
|
|
54
|
-
|
|
56
|
+
If ``True`` then returned path contains masked backslashes as separator, otherwise slashes
|
|
55
57
|
|
|
56
|
-
|
|
58
|
+
* ``sReferencePathAbs``
|
|
57
59
|
|
|
58
|
-
|
|
60
|
+
/ *Condition*: optional / *Type*: str / *Default*: None /
|
|
59
61
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
+
In case of ``sPath`` is relative and ``sReferencePathAbs`` (expected to be absolute) is given, then
|
|
63
|
+
the returned absolute path is a join of both input paths
|
|
62
64
|
|
|
63
|
-
|
|
65
|
+
* ``bConsiderBlanks``
|
|
64
66
|
|
|
65
|
-
|
|
67
|
+
/ *Condition*: optional / *Type*: bool / *Default*: False /
|
|
66
68
|
|
|
67
|
-
|
|
69
|
+
If ``True`` then the returned path is encapsulated in quotes - in case of the path contains blanks
|
|
70
|
+
|
|
71
|
+
* ``bExpandEnvVars``
|
|
72
|
+
|
|
73
|
+
/ *Condition*: optional / *Type*: bool / *Default*: True /
|
|
68
74
|
|
|
69
75
|
If ``True`` then in the returned path environment variables are resolved, otherwise not.
|
|
70
76
|
|
|
71
|
-
|
|
77
|
+
* ``bMask``
|
|
78
|
+
|
|
79
|
+
/ *Condition*: optional / *Type*: bool / *Default*: True (requires ``bWin=True``)/
|
|
72
80
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
81
|
+
* If ``bWin`` is ``True`` and ``bMask`` is ``True`` then the returned path contains masked backslashes as separator.
|
|
82
|
+
* If ``bWin`` is ``True`` and ``bMask`` is ``False`` then the returned path contains single backslashes only - this might be
|
|
83
|
+
required for applications, that are not able to handle masked backslashes.
|
|
84
|
+
* In case of ``bWin`` is ``False`` ``bMask`` has no effect.
|
|
76
85
|
|
|
77
86
|
**Returns:**
|
|
78
87
|
|
|
79
|
-
|
|
88
|
+
* ``sPath``
|
|
80
89
|
|
|
81
|
-
|
|
90
|
+
/ *Type*: str /
|
|
82
91
|
|
|
83
|
-
|
|
92
|
+
The normalized path (is ``None`` in case of ``sPath`` is ``None``)
|
|
84
93
|
"""
|
|
85
94
|
|
|
86
95
|
if sPath is not None:
|
|
@@ -212,60 +221,69 @@ class CString(object):
|
|
|
212
221
|
|
|
213
222
|
def DetectParentPath(sStartPath=None, sFolderName=None, sFileName=None):
|
|
214
223
|
"""
|
|
215
|
-
|
|
224
|
+
Computes the path to any parent folder inside a given path. Optionally DetectParentPath is able
|
|
225
|
+
to search for files inside the identified parent folder.
|
|
216
226
|
|
|
217
|
-
**
|
|
227
|
+
**Arguments:**
|
|
218
228
|
|
|
219
|
-
|
|
229
|
+
* ``sStartPath``
|
|
220
230
|
|
|
221
|
-
|
|
222
|
-
to search for files inside the parent folder.
|
|
231
|
+
/ *Condition*: required / *Type*: str /
|
|
223
232
|
|
|
224
|
-
|
|
233
|
+
The path in which to search for a parent folder
|
|
225
234
|
|
|
226
|
-
|
|
235
|
+
* ``sFolderName``
|
|
227
236
|
|
|
228
|
-
|
|
237
|
+
/ *Condition*: required / *Type*: str /
|
|
229
238
|
|
|
230
|
-
|
|
239
|
+
The name of the folder to search for within ``sStartPath``. It is possible to provide more than one folder name separated by semicolon
|
|
231
240
|
|
|
232
|
-
|
|
241
|
+
* ``sFileName``
|
|
233
242
|
|
|
234
|
-
|
|
243
|
+
/ *Condition*: optional / *Type*: str / *Default*: None /
|
|
235
244
|
|
|
236
|
-
|
|
245
|
+
The name of a file to search within the detected parent folder
|
|
237
246
|
|
|
238
247
|
**Returns:**
|
|
239
248
|
|
|
240
|
-
|
|
249
|
+
* ``sDestPath``
|
|
250
|
+
|
|
251
|
+
/ *Type*: str /
|
|
252
|
+
|
|
253
|
+
Path and name of parent folder found inside ``sStartPath``, ``None`` in case of ``sFolderName`` is not found inside ``sStartPath``.
|
|
254
|
+
In case of more than one parent folder is found ``sDestPath`` contains the first result and ``listDestPaths`` contains all results.
|
|
255
|
+
|
|
256
|
+
* ``listDestPaths``
|
|
241
257
|
|
|
242
|
-
|
|
243
|
-
In case of more than one parent folder is found ``sDestPath`` contains the first result and ``listDestPaths`` contains all results.
|
|
258
|
+
/ *Type*: list /
|
|
244
259
|
|
|
245
|
-
|
|
260
|
+
If ``sFolderName`` contains a single folder name this list contains only one element that is ``sDestPath``.
|
|
261
|
+
In case of ``FolderName`` contains a semicolon separated list of several folder names this list contains all found paths of the given folder names.
|
|
262
|
+
``listDestPaths`` is ``None`` (and not an empty list!) in case of ``sFolderName`` is not found inside ``sStartPath``.
|
|
246
263
|
|
|
247
|
-
|
|
248
|
-
In case of ``FolderName`` contains a semicolon separated list of several folder names this list contains all found paths of the given folder names.
|
|
249
|
-
``listDestPaths`` is ``None`` (and not an empty list!) in case of ``sFolderName`` is not found inside ``sStartPath``.
|
|
264
|
+
* ``sDestFile``
|
|
250
265
|
|
|
251
|
-
|
|
266
|
+
/ *Type*: str /
|
|
252
267
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
268
|
+
Path and name of ``sFileName``, in case of ``sFileName`` is given and found inside ``listDestPaths``.
|
|
269
|
+
In case of more than one file is found ``sDestFile`` contains the first result and ``listDestFiles`` contains all results.
|
|
270
|
+
``sDestFile`` is ``None`` in case of ``sFileName`` is ``None`` and also in case of ``sFileName`` is not found inside ``listDestPaths``
|
|
271
|
+
(and therefore also in case of ``sFolderName`` is not found inside ``sStartPath``).
|
|
257
272
|
|
|
258
|
-
|
|
273
|
+
* ``listDestFiles``
|
|
259
274
|
|
|
260
|
-
|
|
261
|
-
``listDestFiles`` is ``None`` (and not an empty list!) in case of ``sFileName`` is ``None`` and also in case of ``sFileName``
|
|
262
|
-
is not found inside ``listDestPaths`` (and therefore also in case of ``sFolderName`` is not found inside ``sStartPath``).
|
|
275
|
+
/ *Type*: list /
|
|
263
276
|
|
|
264
|
-
|
|
277
|
+
Contains all positions of ``sFileName`` found inside ``listDestPaths``.
|
|
265
278
|
|
|
266
|
-
|
|
279
|
+
``listDestFiles`` is ``None`` (and not an empty list!) in case of ``sFileName`` is ``None`` and also in case of ``sFileName``
|
|
280
|
+
is not found inside ``listDestPaths`` (and therefore also in case of ``sFolderName`` is not found inside ``sStartPath``).
|
|
267
281
|
|
|
268
|
-
|
|
282
|
+
* ``sDestPathParent``
|
|
283
|
+
|
|
284
|
+
/ *Type*: str /
|
|
285
|
+
|
|
286
|
+
The parent folder of ``sDestPath``, ``None`` in case of ``sFolderName`` is not found inside ``sStartPath`` (``sDestPath`` is ``None``).
|
|
269
287
|
"""
|
|
270
288
|
|
|
271
289
|
sDestPath = None
|
|
@@ -324,7 +342,7 @@ class CString(object):
|
|
|
324
342
|
if len(listDestPaths) > 0:
|
|
325
343
|
# -- returning sDestPath and sDestPathParent related to first entry in list; just to return anything else than None
|
|
326
344
|
sDestPath = listDestPaths[0]
|
|
327
|
-
sDestPathParent =
|
|
345
|
+
sDestPathParent = os.path.dirname(sDestPath)
|
|
328
346
|
|
|
329
347
|
# -- optionally searching also for a single file
|
|
330
348
|
# Input: file name
|
|
@@ -338,7 +356,8 @@ class CString(object):
|
|
|
338
356
|
for sFileNameTmp in listFileNames:
|
|
339
357
|
if sFileNameTmp == sFileName:
|
|
340
358
|
sFile = CString.NormalizePath(os.path.join(sLocalRootPath, sFileName))
|
|
341
|
-
listDestFiles
|
|
359
|
+
if sFile not in listDestFiles:
|
|
360
|
+
listDestFiles.append(sFile)
|
|
342
361
|
# eof for sLocalRootPath, listFolderNames, listFileNames in os.walk(sDestPathToWalk):
|
|
343
362
|
# eof for sDestPathToWalk in listDestPaths:
|
|
344
363
|
# eof if ( (sFileName is not None) and (len(listDestPaths) > 0) ):
|
|
@@ -376,65 +395,16 @@ class CString(object):
|
|
|
376
395
|
sExclRegEx = None,
|
|
377
396
|
bDebug = False):
|
|
378
397
|
"""
|
|
379
|
-
|
|
|
380
|
-
|
|
381
|
-
During the computation of strings there might occur the need to get to know if this string fulfils certain criteria or not.
|
|
382
|
-
Such a criterion can e.g. be that the string contains a certain substring. Also an inverse logic might be required:
|
|
383
|
-
In this case the criterion is that the string does **not** contain this substring.
|
|
384
|
-
|
|
385
|
-
It might also be required to combine several criteria to a final conclusion if in total the criterion for a string is fulfilled or not.
|
|
386
|
-
For example: The string must start with the string *prefix* and must also contain either the string *substring1* or the string *substring2*
|
|
387
|
-
but must also **not** end with the string *suffix*.
|
|
388
|
-
|
|
389
398
|
This method provides a bunch of predefined filters that can be used singly or combined to come to a final conclusion if the string fulfils all criteria or not.
|
|
390
399
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
1. Filters that are interpreted as raw strings (called 'standard filters'; no wild cards supported)
|
|
394
|
-
2. Filters that are interpreted as regular expressions (called 'regular expression based filters'; the syntax of regular expressions has to be considered)
|
|
395
|
-
3. Boolean switches (e.g. indicating if also an empty string is accepted or not)
|
|
396
|
-
|
|
397
|
-
The input string might contain leading and trailing blanks and tabs. This kind of horizontal space is removed from the input string
|
|
398
|
-
before the standard filters start their work (except the regular expression based filters).
|
|
399
|
-
|
|
400
|
-
The regular expression based filters consider the original input string (including the leading and trailing space).
|
|
401
|
-
|
|
402
|
-
The outcome is that in case of the leading and trailing space shall be part of the criterion, the regular expression based filters can be used only.
|
|
403
|
-
|
|
404
|
-
It is possible to decide if the standard filters shall work case sensitive or not. This decision has no effect on the regular expression based filters.
|
|
405
|
-
|
|
406
|
-
The regular expression based filters always work with the original input string that is not modified in any way.
|
|
407
|
-
|
|
408
|
-
Except the regular expression based filters it is possible to provide more than one string for every standard filter (must be a semikolon separated list in this case).
|
|
409
|
-
A semicolon that shall be part of the search string, has to be masked in this way: ``\;``.
|
|
410
|
-
|
|
411
|
-
This method returns a boolean value that is ``True`` in case of all criteria are fulfilled, and ``False`` in case of some or all of them are not fulfilled.
|
|
412
|
-
|
|
413
|
-
The default value for all filters is ``None`` (except ``bSkipBlankStrings``). In case of a filter value is ``None`` this filter has no influence on the result.
|
|
414
|
-
|
|
415
|
-
In case of all filters are ``None`` (default) the return value is ``True`` (except the string itself is ``None``
|
|
416
|
-
or the string is empty and ``bSkipBlankStrings`` is ``True``).
|
|
417
|
-
|
|
418
|
-
In case of the string is ``None``, the return value is ``False``, because nothing concrete can be done with ``None`` strings.
|
|
419
|
-
|
|
420
|
-
Internally every filter has his own individual acknowledge that indicates if the criterion of this filter is fulfilled or not.
|
|
400
|
+
These filters can be e.g. used to select or exclude lines while reading from a text file. Or they can be used to select or exclude files or folders
|
|
401
|
+
while walking through the file system.
|
|
421
402
|
|
|
422
|
-
The
|
|
423
|
-
|
|
424
|
-
The final return value ``bAck`` of this method is a logical join (``AND``) of all individual acknowledges (except ``bSkipBlankStrings`` and ``sComment``;
|
|
425
|
-
in case of their criteria are **not** fulfilled, immediately ``False`` is returned).
|
|
426
|
-
|
|
427
|
-
Summarized:
|
|
428
|
-
|
|
429
|
-
* Filters are used to define *criteria*
|
|
430
|
-
* The return value of this method provides the *conclusion* - indicating if all criteria are fulfilled or not
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
*The following filters are available:*
|
|
403
|
+
**The following filters are available:**
|
|
434
404
|
|
|
435
405
|
**bSkipBlankStrings**
|
|
436
406
|
|
|
437
|
-
*
|
|
407
|
+
* Leading and trailing spaces are removed from the input string at the beginning
|
|
438
408
|
* In case of the result is an empty string and ``bSkipBlankStrings`` is ``True``, the method immediately returns ``False``
|
|
439
409
|
and all other filters are ignored
|
|
440
410
|
|
|
@@ -504,238 +474,35 @@ Summarized:
|
|
|
504
474
|
* ``bCaseSensitive`` has no effect
|
|
505
475
|
* A semicolon separated list of several regular expressions is **not** supported
|
|
506
476
|
|
|
507
|
-
|
|
477
|
+
**Further arguments:**
|
|
478
|
+
|
|
479
|
+
* ``sString``
|
|
508
480
|
|
|
509
|
-
|
|
481
|
+
/ *Condition*: required / *Type*: str /
|
|
510
482
|
|
|
511
483
|
The input string that has to be investigated.
|
|
512
484
|
|
|
513
|
-
|
|
485
|
+
* ``bCaseSensitive``
|
|
486
|
+
|
|
487
|
+
/ *Condition*: optional / *Type*: bool / *Default*: True /
|
|
514
488
|
|
|
515
489
|
If ``True``, the standard filters work case sensitive, otherwise not.
|
|
516
490
|
|
|
517
|
-
|
|
491
|
+
* ``bDebug``
|
|
492
|
+
|
|
493
|
+
/ *Condition*: optional / *Type*: bool / *Default*: False /
|
|
518
494
|
|
|
519
495
|
If ``True``, additional output is printed to console (e.g. the decision of every single filter), otherwise not.
|
|
520
496
|
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
sComment = None,
|
|
531
|
-
sStartsWith = "Sp",
|
|
532
|
-
sEndsWith = None,
|
|
533
|
-
sStartsNotWith = None,
|
|
534
|
-
sEndsNotWith = None,
|
|
535
|
-
sContains = "beats",
|
|
536
|
-
sContainsNot = None,
|
|
537
|
-
sInclRegEx = None,
|
|
538
|
-
sExclRegEx = None)
|
|
539
|
-
|
|
540
|
-
Returns ``False``:
|
|
541
|
-
|
|
542
|
-
.. code::
|
|
543
|
-
|
|
544
|
-
bAck = CString.StringFilter(sString = "Speed is 25 beats per minute",
|
|
545
|
-
bCaseSensitive = True,
|
|
546
|
-
bSkipBlankStrings = True,
|
|
547
|
-
sComment = None,
|
|
548
|
-
sStartsWith = "Sp",
|
|
549
|
-
sEndsWith = None,
|
|
550
|
-
sStartsNotWith = None,
|
|
551
|
-
sEndsNotWith = "minute",
|
|
552
|
-
sContains = "beats",
|
|
553
|
-
sContainsNot = None,
|
|
554
|
-
sInclRegEx = None,
|
|
555
|
-
sExclRegEx = None)
|
|
556
|
-
|
|
557
|
-
Returns ``True``:
|
|
558
|
-
|
|
559
|
-
.. code::
|
|
560
|
-
|
|
561
|
-
bAck = CString.StringFilter(sString = "Speed is 25 beats per minute",
|
|
562
|
-
bCaseSensitive = True,
|
|
563
|
-
bSkipBlankStrings = True,
|
|
564
|
-
sComment = None,
|
|
565
|
-
sStartsWith = None,
|
|
566
|
-
sEndsWith = None,
|
|
567
|
-
sStartsNotWith = None,
|
|
568
|
-
sEndsNotWith = None,
|
|
569
|
-
sContains = None,
|
|
570
|
-
sContainsNot = "Beats",
|
|
571
|
-
sInclRegEx = None,
|
|
572
|
-
sExclRegEx = None)
|
|
573
|
-
|
|
574
|
-
Returns ``True``:
|
|
575
|
-
|
|
576
|
-
.. code::
|
|
577
|
-
|
|
578
|
-
bAck = CString.StringFilter(sString = "Speed is 25 beats per minute",
|
|
579
|
-
bCaseSensitive = True,
|
|
580
|
-
bSkipBlankStrings = True,
|
|
581
|
-
sComment = None,
|
|
582
|
-
sStartsWith = None,
|
|
583
|
-
sEndsWith = None,
|
|
584
|
-
sStartsNotWith = None,
|
|
585
|
-
sEndsNotWith = None,
|
|
586
|
-
sContains = None,
|
|
587
|
-
sContainsNot = None,
|
|
588
|
-
sInclRegEx = r"\d{2}",
|
|
589
|
-
sExclRegEx = None)
|
|
590
|
-
|
|
591
|
-
Returns ``False``:
|
|
592
|
-
|
|
593
|
-
.. code::
|
|
594
|
-
|
|
595
|
-
bAck = CString.StringFilter(sString = "Speed is 25 beats per minute",
|
|
596
|
-
bCaseSensitive = True,
|
|
597
|
-
bSkipBlankStrings = True,
|
|
598
|
-
sComment = None,
|
|
599
|
-
sStartsWith = "Speed",
|
|
600
|
-
sEndsWith = None,
|
|
601
|
-
sStartsNotWith = None,
|
|
602
|
-
sEndsNotWith = None,
|
|
603
|
-
sContains = None,
|
|
604
|
-
sContainsNot = None,
|
|
605
|
-
sInclRegEx = r"\d{3}",
|
|
606
|
-
sExclRegEx = None)
|
|
607
|
-
|
|
608
|
-
Returns ``False``:
|
|
609
|
-
|
|
610
|
-
.. code::
|
|
611
|
-
|
|
612
|
-
bAck = CString.StringFilter(sString = "Speed is 25 beats per minute",
|
|
613
|
-
bCaseSensitive = True,
|
|
614
|
-
bSkipBlankStrings = True,
|
|
615
|
-
sComment = None,
|
|
616
|
-
sStartsWith = "Speed",
|
|
617
|
-
sEndsWith = "minute",
|
|
618
|
-
sStartsNotWith = "speed",
|
|
619
|
-
sEndsNotWith = None,
|
|
620
|
-
sContains = "beats",
|
|
621
|
-
sContainsNot = None,
|
|
622
|
-
sInclRegEx = r"\d{2}",
|
|
623
|
-
sExclRegEx = r"\d{2}")
|
|
624
|
-
|
|
625
|
-
Returns ``False``:
|
|
626
|
-
|
|
627
|
-
.. code::
|
|
628
|
-
|
|
629
|
-
bAck = CString.StringFilter(sString = " ",
|
|
630
|
-
bCaseSensitive = True,
|
|
631
|
-
bSkipBlankStrings = True,
|
|
632
|
-
sComment = None,
|
|
633
|
-
sStartsWith = None,
|
|
634
|
-
sEndsWith = None,
|
|
635
|
-
sStartsNotWith = None,
|
|
636
|
-
sEndsNotWith = None,
|
|
637
|
-
sContains = None,
|
|
638
|
-
sContainsNot = None,
|
|
639
|
-
sInclRegEx = None,
|
|
640
|
-
sExclRegEx = None)
|
|
641
|
-
|
|
642
|
-
Returns ``False``:
|
|
643
|
-
|
|
644
|
-
.. code::
|
|
645
|
-
|
|
646
|
-
bAck = CString.StringFilter(sString = "# Speed is 25 beats per minute",
|
|
647
|
-
bCaseSensitive = True,
|
|
648
|
-
bSkipBlankStrings = True,
|
|
649
|
-
sComment = "#",
|
|
650
|
-
sStartsWith = None,
|
|
651
|
-
sEndsWith = None,
|
|
652
|
-
sStartsNotWith = None,
|
|
653
|
-
sEndsNotWith = None,
|
|
654
|
-
sContains = "beats",
|
|
655
|
-
sContainsNot = None,
|
|
656
|
-
sInclRegEx = None,
|
|
657
|
-
sExclRegEx = None)
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
Returns ``False``:
|
|
661
|
-
|
|
662
|
-
.. code::
|
|
663
|
-
|
|
664
|
-
bAck = CString.StringFilter(sString = " Alpha is not beta; and beta is not gamma ",
|
|
665
|
-
bCaseSensitive = True,
|
|
666
|
-
bSkipBlankStrings = True,
|
|
667
|
-
sComment = None,
|
|
668
|
-
sStartsWith = None,
|
|
669
|
-
sEndsWith = None,
|
|
670
|
-
sStartsNotWith = None,
|
|
671
|
-
sEndsNotWith = None,
|
|
672
|
-
sContains = " Alpha ",
|
|
673
|
-
sContainsNot = None,
|
|
674
|
-
sInclRegEx = None,
|
|
675
|
-
sExclRegEx = None)
|
|
676
|
-
|
|
677
|
-
Because blanks around search strings (here ``" Alpha "``) are considered, whereas the blanks around the input string are removed before computation.
|
|
678
|
-
Therefore ``" Alpha "`` cannot be found within the (shortened) input string.
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
This alternative solution returns ``True``:
|
|
682
|
-
|
|
683
|
-
.. code::
|
|
684
|
-
|
|
685
|
-
bAck = CString.StringFilter(sString = " Alpha is not beta; and beta is not gamma ",
|
|
686
|
-
bCaseSensitive = True,
|
|
687
|
-
bSkipBlankStrings = True,
|
|
688
|
-
sComment = None,
|
|
689
|
-
sStartsWith = None,
|
|
690
|
-
sEndsWith = None,
|
|
691
|
-
sStartsNotWith = None,
|
|
692
|
-
sEndsNotWith = None,
|
|
693
|
-
sContains = None,
|
|
694
|
-
sContainsNot = None,
|
|
695
|
-
sInclRegEx = r"\s{3}Alpha",
|
|
696
|
-
sExclRegEx = None)
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
Returns ``True``:
|
|
700
|
-
|
|
701
|
-
.. code::
|
|
702
|
-
|
|
703
|
-
bAck = CString.StringFilter(sString = "Alpha is not beta; and beta is not gamma",
|
|
704
|
-
bCaseSensitive = True,
|
|
705
|
-
bSkipBlankStrings = True,
|
|
706
|
-
sComment = None,
|
|
707
|
-
sStartsWith = None,
|
|
708
|
-
sEndsWith = None,
|
|
709
|
-
sStartsNotWith = None,
|
|
710
|
-
sEndsNotWith = None,
|
|
711
|
-
sContains = "beta; and",
|
|
712
|
-
sContainsNot = None,
|
|
713
|
-
sInclRegEx = None,
|
|
714
|
-
sExclRegEx = None)
|
|
715
|
-
|
|
716
|
-
The meaning of ``"beta; and"`` is: The criterion is fulfilled in case of either ``"beta"`` or ``" and"`` can be found. That's ``True`` in this example - but this
|
|
717
|
-
has nothing to do with the fact, that also this string ``"beta; and"`` can be found. A semicolon that shall be part of the search, has to be masked!
|
|
718
|
-
|
|
719
|
-
The meaning of ``"beta\; not"`` in the following example is: The criterion is fulfilled in case of ``"beta; not"`` can be found.
|
|
720
|
-
|
|
721
|
-
That's **not** ``True``. Therefore the method returns ``False``:
|
|
722
|
-
|
|
723
|
-
.. code::
|
|
724
|
-
|
|
725
|
-
bAck = CString.StringFilter(sString = "Alpha is not beta; and beta is not gamma",
|
|
726
|
-
bCaseSensitive = True,
|
|
727
|
-
bSkipBlankStrings = True,
|
|
728
|
-
sComment = None,
|
|
729
|
-
sStartsWith = None,
|
|
730
|
-
sEndsWith = None,
|
|
731
|
-
sStartsNotWith = None,
|
|
732
|
-
sEndsNotWith = None,
|
|
733
|
-
sContains = r"beta\; not",
|
|
734
|
-
sContainsNot = None,
|
|
735
|
-
sInclRegEx = None,
|
|
736
|
-
sExclRegEx = None)
|
|
737
|
-
|
|
738
|
-
|
|
|
497
|
+
**Returns:**
|
|
498
|
+
|
|
499
|
+
* ``bAck``
|
|
500
|
+
|
|
501
|
+
/ *Type*: bool /
|
|
502
|
+
|
|
503
|
+
Final statement about the input string ``sString`` after filter computation
|
|
504
|
+
|
|
505
|
+
Further details together with codde examples can be found within chapter **Description**, subsubsection **StringFilter**.
|
|
739
506
|
"""
|
|
740
507
|
|
|
741
508
|
if sString is None:
|
|
@@ -909,7 +676,6 @@ That's **not** ``True``. Therefore the method returns ``False``:
|
|
|
909
676
|
listParts = sContainsModified.split(";")
|
|
910
677
|
for sPart in listParts:
|
|
911
678
|
sPart = sPart.replace(sSeparatorSubstitute , ";") # recover the original version
|
|
912
|
-
print(f"- Part: '{sPart}'")
|
|
913
679
|
listContains.append(sPart)
|
|
914
680
|
else:
|
|
915
681
|
sContainsModified = sContains.replace(r"\;", ";") # convert to unmasked version
|
|
@@ -1055,24 +821,42 @@ That's **not** ``True``. Therefore the method returns ``False``:
|
|
|
1055
821
|
|
|
1056
822
|
def FormatResult(sMethod="", bSuccess=True, sResult=""):
|
|
1057
823
|
"""
|
|
1058
|
-
|
|
824
|
+
Formats the result string ``sResult`` depending on ``bSuccess``:
|
|
825
|
+
|
|
826
|
+
* ``bSuccess`` is ``True`` indicates *success*
|
|
827
|
+
* ``bSuccess`` is ``False`` indicates an *error*
|
|
828
|
+
* ``bSuccess`` is ``None`` indicates an *exception*
|
|
829
|
+
|
|
830
|
+
Additionally the name of the method that causes the result, can be provided (*optional*).
|
|
831
|
+
This is useful for debugging.
|
|
832
|
+
|
|
833
|
+
**Arguments:**
|
|
834
|
+
|
|
835
|
+
* ``sMethod``
|
|
836
|
+
|
|
837
|
+
/ *Condition*: optional / *Type*: str / *Default*: (empty string) /
|
|
1059
838
|
|
|
1060
|
-
|
|
839
|
+
Name of the method that causes the result.
|
|
1061
840
|
|
|
1062
|
-
|
|
841
|
+
* ``bSuccess``
|
|
1063
842
|
|
|
1064
|
-
|
|
843
|
+
/ *Condition*: optional / *Type*: bool / *Default*: True /
|
|
1065
844
|
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
845
|
+
Indicates if the computation of the method ``sMethod`` was successful or not.
|
|
846
|
+
|
|
847
|
+
* ``sResult``
|
|
848
|
+
|
|
849
|
+
/ *Condition*: optional / *Type*: str / *Default*: (empty string) /
|
|
850
|
+
|
|
851
|
+
The result of the computation of the method ``sMethod``.
|
|
852
|
+
|
|
853
|
+
**Returns:**
|
|
1069
854
|
|
|
1070
|
-
|
|
1071
|
-
This is useful for debugging.
|
|
855
|
+
* ``sResult``
|
|
1072
856
|
|
|
1073
|
-
|
|
857
|
+
/ *Type*: str /
|
|
1074
858
|
|
|
1075
|
-
|
|
859
|
+
The formatted result string.
|
|
1076
860
|
"""
|
|
1077
861
|
|
|
1078
862
|
if sMethod is None:
|