Skip to content

Commit c500500

Browse files
authored
Merge pull request #145 from KiranBaktha/my_tropical_branch
My tropical branch
2 parents 448cc5e + b65f6e3 commit c500500

File tree

7 files changed

+34
-3
lines changed

7 files changed

+34
-3
lines changed

http_prompt/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def update_cookies(base_value, cookies):
4848
cookie = SimpleCookie(base_value)
4949
for k, v in cookies.items():
5050
cookie[k] = v
51-
return cookie.output(header='', sep=';').lstrip()
51+
return str(cookie.output(header='', sep=';').lstrip())
5252

5353

5454
class ExecutionListener(object):

http_prompt/completion.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
ROOT_COMMANDS = OrderedDict([
1212
('cd', 'Change URL/path'),
13+
('clear', 'Clear console screen'),
1314
('curl', 'Preview curl command'),
1415
('env', 'Print environment'),
1516
('exec', 'Clear and load environment from a file'),

http_prompt/context/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ def __init__(self, url=None, spec=None):
2929
for path in paths:
3030
path_tokens = (base_path_tokens +
3131
list(filter(lambda s: s, path.split('/'))))
32+
if path == '/': # Path is a trailing slash
33+
path_tokens.insert(len(base_path_tokens), '/')
34+
elif path[-1] == '/': # Path ends with a trailing slash
35+
path_tokens[-1] = path_tokens[-1] + '/'
3236
self.root.add_path(*path_tokens)
3337
endpoint = paths[path]
3438
for method, info in endpoint.items():

http_prompt/execution.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
command = mutation / immutation
3434
3535
mutation = concat_mut+ / nonconcat_mut
36-
immutation = preview / action / ls / env / help / exit / exec / source / _
36+
immutation = preview / action / ls / env / help / exit / exec / source / clear / _
3737
3838
concat_mut = option_mut / full_quoted_mut / value_quoted_mut / unquoted_mut
3939
nonconcat_mut = cd / rm
@@ -43,6 +43,7 @@
4343
urlpath = (~r"https?://" unquoted_string) /
4444
(!concat_mut !redir_out string)
4545
46+
clear = _ "clear" _
4647
help = _ "help" _
4748
exit = _ "exit" _
4849
ls = _ "ls" _ (urlpath _)? (redir_out)?
@@ -358,6 +359,10 @@ def visit_exit(self, node, children):
358359
self.context.should_exit = True
359360
return node
360361

362+
def visit_clear(self, node, children):
363+
self.output.clear()
364+
return node
365+
361366
def visit_mutkey(self, node, children):
362367
if isinstance(children[0], list):
363368
return children[0][1]

http_prompt/lexer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ class HttpPromptLexer(RegexLexer):
4646

4747
(words(HTTP_METHODS, prefix='(?i)', suffix='(?!\S)(\s*)'),
4848
bygroups(Keyword, Text), combined('redir_out', 'urlpath')),
49-
49+
50+
(r'(clear)(\s*)', bygroups(Keyword, Text), 'end'),
5051
(r'(exit)(\s*)', bygroups(Keyword, Text), 'end'),
5152
(r'(help)(\s)*', bygroups(Keyword, Text), 'end'),
5253
(r'(env)(\s*)', bygroups(Keyword, Text),

http_prompt/output.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ def isatty(self):
2727
def fileno(self):
2828
return sys.stdout.fileno()
2929

30+
def clear(self):
31+
click.clear()
32+
3033

3134
class TextWriter(object):
3235
"""Wrap a file-like object, opened with 'wb' or 'ab', so it accepts text

tests/test_cli.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,23 @@ def test_spec_from_http_only(self):
209209
self.assertEqual(lv1_names, set(['v1']))
210210
self.assertEqual(lv2_names, set(['me', 'publications', 'users']))
211211

212+
def test_spec_with_trailing_slash(self):
213+
spec_filepath = self.make_tempfile(json.dumps({
214+
'basePath': '/api',
215+
'paths': {
216+
'/': {},
217+
'/users/': {}
218+
}
219+
}))
220+
result, context = run_and_exit(['example.com', "--spec",
221+
spec_filepath])
222+
self.assertEqual(result.exit_code, 0)
223+
self.assertEqual(context.url, 'http://example.com')
224+
lv1_names = set([node.name for node in context.root.ls()])
225+
lv2_names = set([node.name for node in context.root.ls('api')])
226+
self.assertEqual(lv1_names, set(['api']))
227+
self.assertEqual(lv2_names, set(['/', 'users/']))
228+
212229
def test_env_only(self):
213230
env_filepath = self.make_tempfile(
214231
"cd http://example.com\nname=bob\nid==10")

0 commit comments

Comments
 (0)