-
Notifications
You must be signed in to change notification settings - Fork 198
Fix fromjson() to support reading from stdin #667
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| from __future__ import print_function, division, absolute_import | ||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Missing module docstring
Missing module docstring
Check warningCode scanning / Pylint (reported by Codacy) Missing module docstring
Missing module docstring
|
||
|
|
||
| import subprocess | ||
Check warningCode scanning / Bandit (reported by Codacy) Consider possible security implications associated with the subprocess module.
Consider possible security implications associated with the subprocess module.
|
||
|
|
||
| def test_executable(): | ||
Check warningCode scanning / Pylint (reported by Codacy) Missing function docstring
Missing function docstring
Check warningCode scanning / Pylintpython3 (reported by Codacy) Missing function or method docstring
Missing function or method docstring
|
||
| result = subprocess.check_output(""" | ||
Check warningCode scanning / Bandit (reported by Codacy) Starting a process with a partial executable path
Starting a process with a partial executable path
|
||
| (echo foo,bar ; echo a,b; echo c,d) | | ||
| petl 'fromcsv().cut("foo").head(1).tocsv()' | ||
| """, shell=True) | ||
Check failureCode scanning / Bandit (reported by Codacy) subprocess call with shell=True seems safe, but may be changed in the future, consider rewriting without shell
subprocess call with shell=True seems safe, but may be changed in the future, consider rewriting without shell
|
||
| assert result == b'foo\r\na\r\n' | ||
Check noticeCode scanning / Semgrep (reported by Codacy) The application was found using `assert` in non-test code.
The application was found using `assert` in non-test code.
Check warningCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
|
|
||
| def test_json_stdin(): | ||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Missing function or method docstring
Missing function or method docstring
Check warningCode scanning / Pylint (reported by Codacy) Missing function docstring
Missing function docstring
|
||
| result = subprocess.check_output(""" | ||
Check warningCode scanning / Bandit (reported by Codacy) Starting a process with a partial executable path
Starting a process with a partial executable path
|
||
| echo '[{"foo": "a", "bar": "b"}]' | | ||
| petl 'fromjson().tocsv()' | ||
| """, shell=True) | ||
Check failureCode scanning / Bandit (reported by Codacy) subprocess call with shell=True seems safe, but may be changed in the future, consider rewriting without shell
subprocess call with shell=True seems safe, but may be changed in the future, consider rewriting without shell
|
||
| assert result == b'foo,bar\r\na,b\r\n' | ||
Check noticeCode scanning / Semgrep (reported by Codacy) The application was found using `assert` in non-test code.
The application was found using `assert` in non-test code.
Check warningCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| result = subprocess.check_output(""" | ||
Check warningCode scanning / Bandit (reported by Codacy) Starting a process with a partial executable path
Starting a process with a partial executable path
|
||
| ( echo '{"foo": "a", "bar": "b"}' ; echo '{"foo": "c", "bar": "d"}' ) | | ||
| petl 'fromjson(lines=True).tocsv()' | ||
| """, shell=True) | ||
Check failureCode scanning / Bandit (reported by Codacy) subprocess call with shell=True seems safe, but may be changed in the future, consider rewriting without shell
subprocess call with shell=True seems safe, but may be changed in the future, consider rewriting without shell
|
||
| assert result == b'foo,bar\r\na,b\r\nc,d\r\n' | ||
Check noticeCode scanning / Semgrep (reported by Codacy) The application was found using `assert` in non-test code.
The application was found using `assert` in non-test code.
Check warningCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
Check warning
Code scanning / Prospector (reported by Codacy)
Keyword argument before variable positional arguments list in the definition of fromjson function (keyword-arg-before-vararg)
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yaniv-aknin
This wouldn't break existing code?
Maybe read_source_from_arg can be taught to read even when stdin is passed as argument as in:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might be wrong, but I don't think it should break existing code.
All these assertions pass -
re.
read_source_from_arg()- my interest is in thepetlexecutable, i.e., I would love for syntax like this to work in shell:echo '{"a":2, "b":4}' | petl 'fromjson(lines=True)'.What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that:
a. Adding more examples in the documentation.
b. Mention this usage pattern in the repository Readme/Frontage
a. tojson() and tojsonarrays()
b. fromcsv()
a. But I haven't had the time to check if this is the case yet.
b. If not it will be a good change for API consistency
c. I would love to hear more opinions about this change.