-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PathFilter questions #313
Labels
Accepted
Accepted issue on our roadmap
Feature
New feature
Needed: documentation
Documentation is required
Needed: tests
Tests are required
Priority: medium
Medium priority
Status: in progress
Issue/pull request which is currently being worked on
Stretch
Optional goal for the current sprint (may not be delivered)
Milestone
Comments
This looks weird indeed. The unicode quoting code is also something we can get rid of, I think. |
On Tue, Oct 23, 2018 at 03:11:10AM -0700, Merlijn Wajer wrote:
This looks weird indeed. The unicode quoting code is also something we can get rid of, I think.
--
You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub:
#313 (comment)
What about something like this? This would leave only the configuration
question (autodetect during the first run and store in the config file?)
diff --git a/whipper/common/path.py b/whipper/common/path.py
index a5d0eb4..2b0fba9 100644
--- a/whipper/common/path.py
+++ b/whipper/common/path.py
@@ -21,47 +21,24 @@
import re
+POSIX = 0
+MACOS = 1
+WINDOWS = 2
+
class PathFilter(object):
"""
I filter path components for safe storage on file systems.
"""
- def __init__(self, slashes=True, quotes=True, fat=True, special=False):
+ def __init__(self, os=POSIX):
"""
- @param slashes: whether to convert slashes to dashes
- @param quotes: whether to normalize quotes
- @param fat: whether to strip characters illegal on FAT filesystems
- @param special: whether to strip special characters
+ @param os: the path character set restrictions to use
"""
- self._slashes = slashes
- self._quotes = quotes
- self._fat = fat
- self._special = special
+ self._os = os
def filter(self, path):
- if self._slashes:
- path = re.sub(r'[/\\]', '-', path, re.UNICODE)
-
- def separators(path):
- # replace separators with a space-hyphen or hyphen
- path = re.sub(r'[:]', ' -', path, re.UNICODE)
- path = re.sub(r'[\|]', '-', path, re.UNICODE)
- return path
-
- # change all fancy single/double quotes to normal quotes
- if self._quotes:
- path = re.sub(ur'[\xc2\xb4\u2018\u2019\u201b]', "'", path,
- re.UNICODE)
- path = re.sub(ur'[\u201c\u201d\u201f]', '"', path, re.UNICODE)
-
- if self._special:
- path = separators(path)
- path = re.sub(r'[\*\?&!\'\"\$\(\)`{}\[\]<>]',
- '_', path, re.UNICODE)
-
- if self._fat:
- path = separators(path)
- # : and | already gone, but leave them here for reference
- path = re.sub(r'[:\*\?"<>|"]', '_', path, re.UNICODE)
-
- return path
+ if self._os == POSIX or self._os == MACOS:
+ repl = r'/'
+ else:
+ repl = r'[/\\:*?"<>|]'
+ return re.sub(repl, '_', path, re.UNICODE)
|
I think you can use sys.platform for that |
@q3cpma Let me quote you to have the diff formatted in a code block: diff --git a/whipper/common/path.py b/whipper/common/path.py
index a5d0eb4..2b0fba9 100644
--- a/whipper/common/path.py
+++ b/whipper/common/path.py
@@ -21,47 +21,24 @@
import re
+POSIX = 0
+MACOS = 1
+WINDOWS = 2
+
class PathFilter(object):
"""
I filter path components for safe storage on file systems.
"""
- def __init__(self, slashes=True, quotes=True, fat=True, special=False):
+ def __init__(self, os=POSIX):
"""
- @param slashes: whether to convert slashes to dashes
- @param quotes: whether to normalize quotes
- @param fat: whether to strip characters illegal on FAT filesystems
- @param special: whether to strip special characters
+ @param os: the path character set restrictions to use
"""
- self._slashes = slashes
- self._quotes = quotes
- self._fat = fat
- self._special = special
+ self._os = os
def filter(self, path):
- if self._slashes:
- path = re.sub(r'[/\\]', '-', path, re.UNICODE)
-
- def separators(path):
- # replace separators with a space-hyphen or hyphen
- path = re.sub(r'[:]', ' -', path, re.UNICODE)
- path = re.sub(r'[\|]', '-', path, re.UNICODE)
- return path
-
- # change all fancy single/double quotes to normal quotes
- if self._quotes:
- path = re.sub(ur'[\xc2\xb4\u2018\u2019\u201b]', "'", path,
- re.UNICODE)
- path = re.sub(ur'[\u201c\u201d\u201f]', '"', path, re.UNICODE)
-
- if self._special:
- path = separators(path)
- path = re.sub(r'[\*\?&!\'\"\$\(\)`{}\[\]<>]',
- '_', path, re.UNICODE)
-
- if self._fat:
- path = separators(path)
- # : and | already gone, but leave them here for reference
- path = re.sub(r'[:\*\?"<>|"]', '_', path, re.UNICODE)
-
- return path
+ if self._os == POSIX or self._os == MACOS:
+ repl = r'/'
+ else:
+ repl = r'[/\\:*?"<>|]'
+ return re.sub(repl, '_', path, re.UNICODE)
|
Merged
JoeLametta
added
Status: in progress
Issue/pull request which is currently being worked on
Accepted
Accepted issue on our roadmap
Priority: medium
Medium priority
Feature
New feature
Needed: tests
Tests are required
Needed: documentation
Documentation is required
Stretch
Optional goal for the current sprint (may not be delivered)
labels
Nov 12, 2018
JoeLametta
added a commit
that referenced
this issue
Feb 22, 2020
Added new filter options. Fixes #313. Signed-off-by: JoeLametta <JoeLametta@users.noreply.github.com>
JoeLametta
added a commit
that referenced
this issue
Feb 22, 2020
Added new filter options. Fixes #313. Signed-off-by: JoeLametta <JoeLametta@users.noreply.github.com>
JoeLametta
added a commit
that referenced
this issue
Feb 22, 2020
Added new filter options. Fixes #313. Signed-off-by: JoeLametta <JoeLametta@users.noreply.github.com>
JoeLametta
added a commit
that referenced
this issue
Feb 22, 2020
Added filter options: - dot (replace leading dot with _) - posix (replace illegal chars in *nix OSes with _) - vfat (replace illegal chars in VFAT filesystems with _) - whitespace (replace all whitespace chars with _) - printable (replace all non printable ASCII chars with _) Removed filter options: - fat (replaced with vfat) - special Fixes #313. Signed-off-by: JoeLametta <JoeLametta@users.noreply.github.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Accepted
Accepted issue on our roadmap
Feature
New feature
Needed: documentation
Documentation is required
Needed: tests
Tests are required
Priority: medium
Medium priority
Status: in progress
Issue/pull request which is currently being worked on
Stretch
Optional goal for the current sprint (may not be delivered)
Hello,
as a POSIX OS user, I'm wondering about the forced character stripping in paths, and am confused at the PathFilter class in path.py:
I'm thinking about replacing everything but quotes by "POSIX" and "vfat", while having a configuration option for adding an additional string of characters to replace and maybe another for the fallback character.
The text was updated successfully, but these errors were encountered: