-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f47ea09
commit 499b858
Showing
16 changed files
with
105 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,49 @@ | ||
import re | ||
import shlex | ||
|
||
|
||
def escape_argument(arg): | ||
"""Escape a command line argument. | ||
>>> print(escape_argument("hello")) | ||
hello | ||
>>> print(escape_argument("hello world")) | ||
'hello world' | ||
>>> print(escape_argument("hello'world'")) | ||
'hello'"'"'world'"'"'' | ||
""" | ||
return shlex.quote(arg) | ||
|
||
|
||
def create_command_line(args): | ||
"""Create a command line from a list of arguments. | ||
>>> print(create_command_line(["echo", "hello world"])) | ||
echo 'hello world' | ||
""" | ||
escaped_args = [escape_argument(str(arg)) for arg in args] | ||
return " ".join(escaped_args) | ||
|
||
|
||
class GreppableString(str): | ||
"""A string that can be parsed with regular expressions.""" | ||
|
||
def grep(self, pattern: str, *args) -> bool: | ||
"""Return True if the pattern is found in the string. | ||
>>> GreppableString("hello world").grep("w.{3}d") | ||
['world'] | ||
>>> GreppableString("hello world").grep(r"\b[a-z]{4}\b") | ||
[] | ||
""" | ||
return re.findall(pattern, self, *args) | ||
|
||
def contains(self, value: str) -> bool: | ||
"""Return True if the value is found in the string. | ||
>>> GreppableString("hello world").contains("world") | ||
True | ||
>>> GreppableString("hello world").contains("earth") | ||
False | ||
""" | ||
return value in self |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
failures: 2 | ||
points: | ||
earned: 4 | ||
total: 10 | ||
skipped: 0 | ||
successes: 2 | ||
time: 0.03 | ||
total: 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
version: 1 | ||
executable: ./main.exe.py | ||
filters: | ||
trim: true | ||
tests: | ||
- name: Foo | ||
args: [4, 0] | ||
stdout: [ equals: 4 ] | ||
points: 1 | ||
- name: Bar | ||
args: [8, 0] | ||
stdout: [ equals: 2 ] | ||
points: 2 | ||
- name: Baz | ||
args: [15, 0] | ||
stdout: [ equals: 15 ] | ||
points: 3 | ||
- name: Qux | ||
args: [16, 0] | ||
stdout: [ equals: 42 ] | ||
points: 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.