hbmartin commited on
Commit
4e0334b
·
1 Parent(s): 9d481ad

escaping for regexes

Browse files
Files changed (3) hide show
  1. .flake8 +1 -1
  2. pytube/cipher.py +4 -4
  3. pytube/helpers.py +20 -20
.flake8 CHANGED
@@ -1,3 +1,3 @@
1
  [flake8]
2
- ignore = E231,E203,W605,W503
3
  max-line-length = 88
 
1
  [flake8]
2
+ ignore = E231,E203,W503
3
  max-line-length = 88
pytube/cipher.py CHANGED
@@ -198,14 +198,14 @@ def map_functions(js_func):
198
  """
199
  mapper = (
200
  # function(a){a.reverse()}
201
- ("{\w\.reverse\(\)}", reverse),
202
  # function(a,b){a.splice(0,b)}
203
- ("{\w\.splice\(0,\w\)}", splice),
204
  # function(a,b){var c=a[0];a[0]=a[b%a.length];a[b]=c}
205
- ("{var\s\w=\w\[0\];\w\[0\]=\w\[\w\%\w.length\];\w\[\w\]=\w}", swap),
206
  # function(a,b){var c=a[0];a[0]=a[b%a.length];a[b%a.length]=c}
207
  (
208
- "{var\s\w=\w\[0\];\w\[0\]=\w\[\w\%\w.length\];" "\w\[\w\%\w.length\]=\w}",
209
  swap,
210
  ),
211
  )
 
198
  """
199
  mapper = (
200
  # function(a){a.reverse()}
201
+ (r"{\w\.reverse\(\)}", reverse),
202
  # function(a,b){a.splice(0,b)}
203
+ (r"{\w\.splice\(0,\w\)}", splice),
204
  # function(a,b){var c=a[0];a[0]=a[b%a.length];a[b]=c}
205
+ (r"{var\s\w=\w\[0\];\w\[0\]=\w\[\w\%\w.length\];\w\[\w\]=\w}", swap),
206
  # function(a,b){var c=a[0];a[0]=a[b%a.length];a[b%a.length]=c}
207
  (
208
+ r"{var\s\w=\w\[0\];\w\[0\]=\w\[\w\%\w.length\];\w\[\w\%\w.length\]=\w}",
209
  swap,
210
  ),
211
  )
pytube/helpers.py CHANGED
@@ -89,26 +89,26 @@ def safe_filename(s: str, max_length: int = 255) -> str:
89
  # Characters in range 0-31 (0x00-0x1F) are not allowed in ntfs filenames.
90
  ntfs_characters = [chr(i) for i in range(0, 31)]
91
  characters = [
92
- '"',
93
- "\#",
94
- "\$",
95
- "\%",
96
- "'",
97
- "\*",
98
- "\,",
99
- "\.",
100
- "\/",
101
- "\:",
102
- '"',
103
- "\;",
104
- "\<",
105
- "\>",
106
- "\?",
107
- "\\",
108
- "\^",
109
- "\|",
110
- "\~",
111
- "\\\\",
112
  ]
113
  pattern = "|".join(ntfs_characters + characters)
114
  regex = re.compile(pattern, re.UNICODE)
 
89
  # Characters in range 0-31 (0x00-0x1F) are not allowed in ntfs filenames.
90
  ntfs_characters = [chr(i) for i in range(0, 31)]
91
  characters = [
92
+ r'"',
93
+ r"\#",
94
+ r"\$",
95
+ r"\%",
96
+ r"'",
97
+ r"\*",
98
+ r"\,",
99
+ r"\.",
100
+ r"\/",
101
+ r"\:",
102
+ r'"',
103
+ r"\;",
104
+ r"\<",
105
+ r"\>",
106
+ r"\?",
107
+ r"\\",
108
+ r"\^",
109
+ r"\|",
110
+ r"\~",
111
+ r"\\\\",
112
  ]
113
  pattern = "|".join(ntfs_characters + characters)
114
  regex = re.compile(pattern, re.UNICODE)