File: getj.py

package info (click to toggle)
zurl 1.12.0-3
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 748 kB
  • sloc: cpp: 8,055; python: 247; sh: 119; makefile: 15
file content (33 lines) | stat: -rw-r--r-- 683 bytes parent folder | download | duplicates (6)
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
import sys
import uuid
import json
import zmq

if len(sys.argv) < 2:
	print 'usage: %s [url]' % sys.argv[0]
	sys.exit(1)

ctx = zmq.Context()
sock = ctx.socket(zmq.REQ)
sock.connect('ipc:///tmp/zurl-req')

req = dict()
req['id'] = str(uuid.uuid4())
req['method'] = 'GET'
req['uri'] = sys.argv[1]
#req['ignore-tls-errors'] = True
sock.send('J' + json.dumps(req))

resp = json.loads(sock.recv()[1:])
if 'type' in resp and resp['type'] == 'error':
	print 'error: %s' % resp['condition']
	sys.exit(1)

print 'code=%d reason=[%s]' % (resp['code'], resp['reason'])
for h in resp['headers']:
	print '%s: %s' % (h[0], h[1])

if 'body' in resp:
	print '\n%s' % resp['body']
else:
	print '\n'