Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: abp/filters/sources.py

Issue 29824555: Issue #4116: Make infile and outfile parameters of flrender script from python-abp optional (Closed)
Patch Set: Updated tests and README.md Created July 10, 2018, 4:07 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: abp/filters/sources.py
diff --git a/abp/filters/sources.py b/abp/filters/sources.py
index 6aae32c5e5462c300825537c8c787756c4d91a15..a1c9d41a9c7082094abfa6bb161711b585efdd3e 100644
--- a/abp/filters/sources.py
+++ b/abp/filters/sources.py
@@ -17,6 +17,7 @@
import io
from os import path
+import sys
try:
from urllib2 import urlopen, HTTPError
@@ -106,6 +107,29 @@ class TopSource(FSSource):
def _resolve_path(self, path_in_source):
return path_in_source
+ def get(self, path_in_source):
+ """Read the data. Handles stdin, on top of file input.
+
+ Parameters
+ ----------
+ path_in_source : str
+ Path to the file inside of source or '-' for stdin.
+
+ Returns
+ -------
+ generator or str
+ Lines in the file/ from stdin.
+
+ """
+ if path_in_source == '-':
+ lines = sys.stdin.readlines()
+ for line in lines:
+ yield line.rstrip('\n')
+ else:
+ lines = super(TopSource, self).get(path_in_source)
+ for line in lines:
+ yield line
+
class WebSource(object):
"""Handler for http or https.

Powered by Google App Engine
This is Rietveld