Skip to content
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

solve SyntaxWarning: invalid escape sequence '\s' errors #193

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions filters/ftp_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def listing (dir, where, what):

pattern = "^d" if what == "directories" else "^-"
lines = [l for l in lines if re.search(pattern, l)] # makes only sense if there is a column with drwxr-xr-x
results = [re.split('\s+', l)[dir_filename_column[where]] for l in lines]
results = [re.split(r'\s+', l)[dir_filename_column[where]] for l in lines]
return results


Expand Down Expand Up @@ -97,16 +97,16 @@ def commands():

def complete_handler(line, prefix, completions):

nwords = len(re.split('\s+', line))
nwords = len(re.split(r'\s+', line))
if prefix == None:
nwords += 1 # TAB at start of a new (empty) argument

if nwords <= 1:
completions.extend([c for c in ftp_commands if re.search(r'^' + prefix, c)])
return completions

command = re.search('\s*(\S+)', line).group(1)
prefix_match = re.search('((.*)/)?([^/]*)', prefix)
command = re.search(r'\s*(\S+)', line).group(1)
prefix_match = re.search(r'((.*)/)?([^/]*)', prefix)
dir = prefix_match.group(2)
name_prefix = prefix_match.group(3)
#dir = '.' if dir == None else dir
Expand Down
14 changes: 7 additions & 7 deletions filters/rlwrapfilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
filter.output_handler = lambda x: re.sub('apple', 'orange', x) # re−write output
filter.prompt_handler = munge_prompt
filter.completion_handler = complete_handler
filter.history_handler = lambda x: re.sub(r'(identified\s+by\s+)(\S+)', r'\\1xXxXxXxX', x)
filter.history_handler = lambda x: re.sub(r'(identified\\s+by\\s+)(\\S+)', r'\\1xXxXxXxX', x)
filter.run()

This is an [RlwrapFilter](https://github.com/hanslub42/rlwrap/wiki/RlwrapFilter.pm-manpage)
Expand Down Expand Up @@ -208,7 +208,7 @@ def read_from_stdin():
tagname = None
while (tag is None):
try:
m = re.match("(\S+) (.*?)\r?\n", sys.stdin.readline())
m = re.match(r'(\S+) (.*?)\r?\n', sys.stdin.readline())
except KeyboardInterrupt:
sys.exit()
if not m:
Expand Down Expand Up @@ -493,8 +493,8 @@ def cloak_and_dagger(self, question, prompt, timeout,
response = read_until(CMD_OUT, prompt, timeout,
prompt_search_from=prompt_search_from,
prompt_search_to=prompt_search_to)
response = re.sub('^.*?\n', '', response) # chop off echoed question;
response = re.sub('{0}$'.format(prompt), '', response) # chop off prompt;
response = re.sub(r'^.*?\n', '', response) # chop off echoed question;
response = re.sub(r'{0}$'.format(prompt), '', response) # chop off prompt;
if (self.cloak_and_dagger_verbose):
self.send_output_oob("cloak_and_dagger response: {0}\n".format(response))
return response
Expand Down Expand Up @@ -625,14 +625,14 @@ def run(self):
write_message(tag,REJECT_PROMPT);
# don't update <previous_tag> and don't reset <cumulative_input>
next
if (os.environ.get('RLWRAP_IMPATIENT') and not re.search('\n$', self.cumulative_output)):
if (os.environ.get('RLWRAP_IMPATIENT') and not re.search(r'\n$', self.cumulative_output)):
# cumulative output contains prompt: chop it off!
# s/[^\n]*$// takes way too long on big strings,
# what is the optimal regex to do this?
self.cumulative_output = re.sub('(?<![^\n])[^\n]*$', '', self.cumulative_output)
self.cumulative_output = re.sub(r'(?<![^\n])[^\n]*$', '', self.cumulative_output)

response = when_defined(self.prompt_handler, message)
if (re.search('\n', response)):
if (re.search(r'\n', response)):
send_error('prompts may not contain newlines!')
elif (tag == TAG_SIGNAL):
response = when_defined(self.signal_handler, message)
Expand Down