forked from shawwn/scrap
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcurlquote
More file actions
executable file
·84 lines (65 loc) · 1.95 KB
/
Copy pathcurlquote
File metadata and controls
executable file
·84 lines (65 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python
#==============================================================================
# Functionality
#==============================================================================
import pdb
import sys
import os
import re
import scrap
# utility funcs, classes, etc go here.
def asserting(cond):
if not cond:
pdb.set_trace()
assert(cond)
def has_stdin():
return not sys.stdin.isatty()
def reg(pat, flags=0):
return re.compile(pat, re.VERBOSE | flags)
#==============================================================================
# Cmdline
#==============================================================================
import argparse
parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter,
description="""
TODO
""")
parser.add_argument('-v', '--verbose',
action="store_true",
help="verbose output" )
parser.add_argument('-n', '--no-unescape-newlines',
action="store_true",
help="don't unescape newlines." )
parser.add_argument('-t', '--no-unescape-tabs',
action="store_true",
help="don't unescape tabs." )
parser.add_argument('url')
args = None
#==============================================================================
# Main
#==============================================================================
def cmd(name, args, stdin=None):
out, err = scrap._system(name, args, stdin=stdin)
if err:
sys.stderr.write(err)
sys.exit(1)
else:
return out
def run():
if args.verbose:
print args
out = cmd('curl', [args.url])
out = cmd('quote', [], out)
if not args.no_unescape_newlines:
out = out.replace(r'\n', '\n')
if not args.no_unescape_tabs:
out = out.replace(r'\t', '\t')
sys.stdout.write(out)
def main():
global args
if not args:
args, leftovers = parser.parse_known_args()
args.args = leftovers
return run()
if __name__ == "__main__":
main()