extend 'path-restrict' option
Allow its value to be a JSON object / Python dict that specifies
a mapping from invalid/unwanted input characters to specific
output characters.
For example {"/": "-", "*": "+"} will transform
"foo / ***bar***" into "foo - +++bar+++"
(closes #662, #755)
This commit is contained in:
@@ -131,11 +131,13 @@ Description Use an extractor's current target directory as
|
|||||||
extractor.*.path-restrict
|
extractor.*.path-restrict
|
||||||
-------------------------
|
-------------------------
|
||||||
=========== =====
|
=========== =====
|
||||||
Type ``string``
|
Type ``string`` or ``object``
|
||||||
Default ``"auto"``
|
Default ``"auto"``
|
||||||
Example ``"/!? (){}"``
|
Example | ``"/!? (){}"``
|
||||||
Description Set of characters to replace with underscores (``_``)
|
| ``{" ": "_", "/": "-", "|": "-", ":": "-", "*": "+"}``
|
||||||
in generated path segment names.
|
Description | String of characters to be replaced with underscores (``_``)
|
||||||
|
| or an object mapping specific characters to others
|
||||||
|
| in generated path segment names.
|
||||||
|
|
||||||
Special values:
|
Special values:
|
||||||
|
|
||||||
@@ -144,7 +146,7 @@ Description Set of characters to replace with underscores (``_``)
|
|||||||
* ``"unix"``: ``"/"``
|
* ``"unix"``: ``"/"``
|
||||||
* ``"windows"``: ``"\\\\|/<>:\"?*"``
|
* ``"windows"``: ``"\\\\|/<>:\"?*"``
|
||||||
|
|
||||||
Note: In a set with 2 or more characters, ``[]^-\`` need to be
|
Note: In a string with 2 or more characters, ``[]^-\`` need to be
|
||||||
escaped with backslashes, e.g. ``"\\[\\]"``
|
escaped with backslashes, e.g. ``"\\[\\]"``
|
||||||
=========== =====
|
=========== =====
|
||||||
|
|
||||||
@@ -156,7 +158,7 @@ Type ``string``
|
|||||||
Default ``"\u0000-\u001f\u007f"`` (ASCII control characters)
|
Default ``"\u0000-\u001f\u007f"`` (ASCII control characters)
|
||||||
Description Set of characters to remove from generated path names.
|
Description Set of characters to remove from generated path names.
|
||||||
|
|
||||||
Note: In a set with 2 or more characters, ``[]^-\`` need to be
|
Note: In a string with 2 or more characters, ``[]^-\`` need to be
|
||||||
escaped with backslashes, e.g. ``"\\[\\]"``
|
escaped with backslashes, e.g. ``"\\[\\]"``
|
||||||
=========== =====
|
=========== =====
|
||||||
|
|
||||||
|
|||||||
@@ -690,6 +690,9 @@ class PathFormat():
|
|||||||
def _build_cleanfunc(chars, repl):
|
def _build_cleanfunc(chars, repl):
|
||||||
if not chars:
|
if not chars:
|
||||||
return lambda x: x
|
return lambda x: x
|
||||||
|
elif isinstance(chars, dict):
|
||||||
|
def func(x, table=str.maketrans(chars)):
|
||||||
|
return x.translate(table)
|
||||||
elif len(chars) == 1:
|
elif len(chars) == 1:
|
||||||
def func(x, c=chars, r=repl):
|
def func(x, c=chars, r=repl):
|
||||||
return x.replace(c, r)
|
return x.replace(c, r)
|
||||||
|
|||||||
Reference in New Issue
Block a user