| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,4 @@ | |||
| 1 | + # vim:ts=4 sw=4 expandtab softtabstop=4 | ||
| 1 | 2 | from __future__ import print_function | |
| 2 | 3 | import argparse | |
| 3 | 4 | import locale | |
@@ -10,28 +11,25 @@ | |||
| 10 | 11 | PY3 = sys.version_info[0] >= 3 | |
| 11 | 12 | ||
| 12 | 13 | def main(): | |
| 13 | - isatty = sys.stdin.isatty() | ||
| 14 | 14 | parser = argparse.ArgumentParser('unidecode') | |
| 15 | 15 | parser.add_argument('-e', | |
| 16 | 16 | '--encoding', | |
| 17 | 17 | nargs=1, | |
| 18 | 18 | metavar='ENCODING', | |
| 19 | 19 | help='Specify an encoding, overriding system default') | |
| 20 | - | ||
| 21 | - if isatty: | ||
| 22 | - parser.add_argument('file', | ||
| 23 | - nargs=1, | ||
| 24 | - metavar='FILE', | ||
| 25 | - help='File to transliterate') | ||
| 20 | + parser.add_argument('file', | ||
| 21 | + nargs='?', | ||
| 22 | + metavar='FILE', | ||
| 23 | + help='File to transliterate') | ||
| 26 | 24 | ||
| 27 | 25 | args = parser.parse_args() | |
| 28 | 26 | if args.encoding: | |
| 29 | 27 | encoding = args.encoding[0] | |
| 30 | 28 | else: | |
| 31 | 29 | encoding = locale.getpreferredencoding() | |
| 32 | 30 | ||
| 33 | - if isatty: | ||
| 34 | - with open(args.file[0], 'rb') as f: | ||
| 31 | + if args.file: | ||
| 32 | + with open(args.file, 'rb') as f: | ||
| 35 | 33 | stream = f.read() | |
| 36 | 34 | else: | |
| 37 | 35 | # In Python 3, stdin.read() is read in the system's locale and returns type str | |
| Back | FazBrowse Home | New Git URL |
0 commit comments