2014-10-24 01:01:34 +00:00
|
|
|
import sys
|
|
|
|
import os
|
2014-10-25 06:50:48 +00:00
|
|
|
import hashlib
|
2015-04-29 20:03:26 +00:00
|
|
|
import Queue
|
2014-10-25 03:43:01 +00:00
|
|
|
import random
|
2015-04-29 20:03:26 +00:00
|
|
|
import select
|
2015-03-14 00:54:47 +00:00
|
|
|
import time
|
2015-04-28 22:02:16 +00:00
|
|
|
import threading
|
2015-03-14 00:54:47 +00:00
|
|
|
|
|
|
|
import OpenSSL.crypto
|
|
|
|
|
2015-04-28 22:02:16 +00:00
|
|
|
from netlib import tcp, http, certutils, websockets
|
2012-09-25 22:38:47 +00:00
|
|
|
import netlib.utils
|
2014-10-25 02:30:54 +00:00
|
|
|
|
|
|
|
import language
|
|
|
|
import utils
|
2012-06-24 09:10:10 +00:00
|
|
|
|
2014-10-25 02:30:54 +00:00
|
|
|
|
|
|
|
class PathocError(Exception):
|
|
|
|
pass
|
2012-06-24 09:10:10 +00:00
|
|
|
|
|
|
|
|
2014-03-02 00:45:35 +00:00
|
|
|
class SSLInfo:
|
2014-03-02 08:54:30 +00:00
|
|
|
def __init__(self, certchain, cipher):
|
|
|
|
self.certchain, self.cipher = certchain, cipher
|
2014-03-02 00:45:35 +00:00
|
|
|
|
2015-04-19 06:04:27 +00:00
|
|
|
def __str__(self):
|
|
|
|
parts = [
|
|
|
|
"Cipher: %s, %s bit, %s"%self.cipher,
|
|
|
|
"SSL certificate chain:"
|
|
|
|
]
|
|
|
|
for i in self.certchain:
|
|
|
|
parts.append("\tSubject: ")
|
|
|
|
for cn in i.get_subject().get_components():
|
|
|
|
parts.append("\t\t%s=%s"%cn)
|
|
|
|
parts.append("\tIssuer: ")
|
|
|
|
for cn in i.get_issuer().get_components():
|
|
|
|
parts.append("\t\t%s=%s"%cn)
|
|
|
|
parts.extend(
|
|
|
|
[
|
|
|
|
"\tVersion: %s"%i.get_version(),
|
|
|
|
"\tValidity: %s - %s"%(
|
|
|
|
i.get_notBefore(), i.get_notAfter()
|
|
|
|
),
|
|
|
|
"\tSerial: %s"%i.get_serial_number(),
|
|
|
|
"\tAlgorithm: %s"%i.get_signature_algorithm()
|
|
|
|
]
|
|
|
|
)
|
|
|
|
pk = i.get_pubkey()
|
|
|
|
types = {
|
|
|
|
OpenSSL.crypto.TYPE_RSA: "RSA",
|
|
|
|
OpenSSL.crypto.TYPE_DSA: "DSA"
|
|
|
|
}
|
|
|
|
t = types.get(pk.type(), "Uknown")
|
|
|
|
parts.append("\tPubkey: %s bit %s"%(pk.bits(), t))
|
|
|
|
s = certutils.SSLCert(i)
|
|
|
|
if s.altnames:
|
|
|
|
parts.append("\tSANs: %s"%" ".join(s.altnames))
|
|
|
|
return "\n".join(parts)
|
|
|
|
|
2014-03-02 00:45:35 +00:00
|
|
|
|
2013-02-26 20:07:16 +00:00
|
|
|
class Response:
|
2014-10-25 03:20:23 +00:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
httpversion,
|
|
|
|
status_code,
|
|
|
|
msg,
|
|
|
|
headers,
|
|
|
|
content,
|
|
|
|
sslinfo
|
|
|
|
):
|
|
|
|
self.httpversion, self.status_code = httpversion, status_code
|
|
|
|
self.msg = msg
|
2013-02-26 20:07:16 +00:00
|
|
|
self.headers, self.content = headers, content
|
2014-03-02 00:45:35 +00:00
|
|
|
self.sslinfo = sslinfo
|
2013-02-26 20:07:16 +00:00
|
|
|
|
2013-03-02 03:57:00 +00:00
|
|
|
def __repr__(self):
|
|
|
|
return "Response(%s - %s)"%(self.status_code, self.msg)
|
|
|
|
|
2014-03-02 00:45:35 +00:00
|
|
|
|
2015-04-28 22:02:16 +00:00
|
|
|
class WebsocketFrameReader(threading.Thread):
|
2015-04-29 20:03:26 +00:00
|
|
|
def __init__(self, rfile, callback, ws_read_limit):
|
2015-04-28 22:02:16 +00:00
|
|
|
threading.Thread.__init__(self)
|
2015-04-29 20:03:26 +00:00
|
|
|
self.ws_read_limit = ws_read_limit
|
2015-04-28 22:02:16 +00:00
|
|
|
self.rfile, self.callback = rfile, callback
|
2015-04-29 20:03:26 +00:00
|
|
|
self.terminate = Queue.Queue()
|
|
|
|
self.is_done = Queue.Queue()
|
2015-04-28 22:02:16 +00:00
|
|
|
|
|
|
|
def run(self):
|
|
|
|
while 1:
|
2015-04-29 20:03:26 +00:00
|
|
|
if self.ws_read_limit == 0:
|
|
|
|
break
|
|
|
|
r, _, _ = select.select([self.rfile], [], [], 0.05)
|
|
|
|
try:
|
|
|
|
self.terminate.get_nowait()
|
|
|
|
break
|
|
|
|
except Queue.Empty:
|
|
|
|
pass
|
|
|
|
for rfile in r:
|
|
|
|
print websockets.Frame.from_file(self.rfile).human_readable()
|
|
|
|
if self.ws_read_limit is not None:
|
|
|
|
self.ws_read_limit -= 1
|
|
|
|
self.is_done.put(None)
|
2015-04-28 22:02:16 +00:00
|
|
|
|
|
|
|
|
2012-06-24 09:10:10 +00:00
|
|
|
class Pathoc(tcp.TCPClient):
|
2014-10-25 02:30:54 +00:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
address,
|
2015-04-19 06:04:27 +00:00
|
|
|
|
|
|
|
# SSL
|
2014-10-25 02:30:54 +00:00
|
|
|
ssl=None,
|
|
|
|
sni=None,
|
|
|
|
sslversion=4,
|
|
|
|
clientcert=None,
|
2015-04-19 06:04:27 +00:00
|
|
|
ciphers=None,
|
|
|
|
|
2015-04-29 20:03:26 +00:00
|
|
|
# Websockets
|
|
|
|
ws_read_limit = None,
|
|
|
|
|
2015-04-19 06:04:27 +00:00
|
|
|
# Output control
|
|
|
|
showreq = False,
|
|
|
|
showresp = False,
|
|
|
|
explain = False,
|
|
|
|
hexdump = False,
|
2015-04-20 03:42:33 +00:00
|
|
|
ignorecodes = (),
|
2015-04-19 06:04:27 +00:00
|
|
|
ignoretimeout = False,
|
|
|
|
showsummary = False,
|
|
|
|
fp = sys.stderr
|
2015-04-20 03:42:33 +00:00
|
|
|
):
|
2015-04-19 06:04:27 +00:00
|
|
|
"""
|
|
|
|
spec: A request specification
|
|
|
|
showreq: Print requests
|
|
|
|
showresp: Print responses
|
|
|
|
explain: Print request explanation
|
|
|
|
showssl: Print info on SSL connection
|
|
|
|
hexdump: When printing requests or responses, use hex dump output
|
|
|
|
showsummary: Show a summary of requests
|
|
|
|
ignorecodes: Sequence of return codes to ignore
|
|
|
|
"""
|
2014-01-28 18:28:20 +00:00
|
|
|
tcp.TCPClient.__init__(self, address)
|
2015-04-22 03:49:17 +00:00
|
|
|
self.settings = language.Settings(
|
2012-07-22 11:37:46 +00:00
|
|
|
staticdir = os.getcwd(),
|
2012-07-24 09:38:28 +00:00
|
|
|
unconstrained_file_access = True,
|
2015-04-22 03:49:17 +00:00
|
|
|
request_host = self.address.host
|
2012-07-22 11:37:46 +00:00
|
|
|
)
|
2013-01-03 21:37:26 +00:00
|
|
|
self.ssl, self.sni = ssl, sni
|
2013-01-20 09:37:43 +00:00
|
|
|
self.clientcert = clientcert
|
2014-02-27 05:33:48 +00:00
|
|
|
self.sslversion = utils.SSLVERSIONS[sslversion]
|
|
|
|
self.ciphers = ciphers
|
2015-04-19 20:56:47 +00:00
|
|
|
self.sslinfo = None
|
2013-01-03 21:37:26 +00:00
|
|
|
|
2015-04-29 20:03:26 +00:00
|
|
|
self.ws_read_limit = ws_read_limit
|
|
|
|
|
2015-04-19 06:04:27 +00:00
|
|
|
self.showreq = showreq
|
|
|
|
self.showresp = showresp
|
|
|
|
self.explain = explain
|
|
|
|
self.hexdump = hexdump
|
|
|
|
self.ignorecodes = ignorecodes
|
|
|
|
self.ignoretimeout = ignoretimeout
|
|
|
|
self.showsummary = showsummary
|
|
|
|
self.fp = fp
|
|
|
|
|
2015-04-29 20:03:26 +00:00
|
|
|
self.ws_framereader = None
|
|
|
|
|
2013-12-15 05:42:58 +00:00
|
|
|
def http_connect(self, connect_to):
|
|
|
|
self.wfile.write(
|
2014-10-25 02:30:54 +00:00
|
|
|
'CONNECT %s:%s HTTP/1.1\r\n'%tuple(connect_to) +
|
|
|
|
'\r\n'
|
|
|
|
)
|
2013-12-15 05:42:58 +00:00
|
|
|
self.wfile.flush()
|
|
|
|
l = self.rfile.readline()
|
2013-03-02 03:57:00 +00:00
|
|
|
if not l:
|
|
|
|
raise PathocError("Proxy CONNECT failed")
|
|
|
|
parsed = http.parse_response_line(l)
|
|
|
|
if not parsed[1] == 200:
|
2015-04-20 03:42:33 +00:00
|
|
|
raise PathocError(
|
|
|
|
"Proxy CONNECT failed: %s - %s"%(parsed[1], parsed[2])
|
|
|
|
)
|
2014-01-19 05:20:01 +00:00
|
|
|
http.read_headers(self.rfile)
|
2013-01-05 07:29:46 +00:00
|
|
|
|
2015-04-19 03:55:22 +00:00
|
|
|
def connect(self, connect_to=None, showssl=False, fp=sys.stdout):
|
2013-01-05 07:29:46 +00:00
|
|
|
"""
|
2015-04-20 03:42:33 +00:00
|
|
|
connect_to: A (host, port) tuple, which will be connected to with
|
|
|
|
an HTTP CONNECT request.
|
2013-01-05 07:29:46 +00:00
|
|
|
"""
|
2013-01-03 21:37:26 +00:00
|
|
|
tcp.TCPClient.connect(self)
|
2013-01-05 07:29:46 +00:00
|
|
|
if connect_to:
|
2013-12-15 05:42:58 +00:00
|
|
|
self.http_connect(connect_to)
|
2014-03-02 00:45:35 +00:00
|
|
|
self.sslinfo = None
|
2013-01-03 21:37:26 +00:00
|
|
|
if self.ssl:
|
|
|
|
try:
|
2014-02-27 05:33:48 +00:00
|
|
|
self.convert_to_ssl(
|
2014-10-25 02:30:54 +00:00
|
|
|
sni=self.sni,
|
|
|
|
cert=self.clientcert,
|
|
|
|
method=self.sslversion,
|
|
|
|
cipher_list = self.ciphers
|
|
|
|
)
|
2013-01-03 21:37:26 +00:00
|
|
|
except tcp.NetLibError, v:
|
|
|
|
raise PathocError(str(v))
|
2014-03-02 00:45:35 +00:00
|
|
|
self.sslinfo = SSLInfo(
|
2014-10-25 02:30:54 +00:00
|
|
|
self.connection.get_peer_cert_chain(),
|
|
|
|
self.get_current_cipher()
|
|
|
|
)
|
2015-04-19 03:55:22 +00:00
|
|
|
if showssl:
|
2015-04-19 06:04:27 +00:00
|
|
|
print >> fp, str(self.sslinfo)
|
2014-03-02 00:45:35 +00:00
|
|
|
|
2015-04-19 06:04:27 +00:00
|
|
|
def _show_summary(self, fp, resp):
|
2014-10-25 02:30:54 +00:00
|
|
|
print >> fp, "<< %s %s: %s bytes"%(
|
2015-04-19 06:04:27 +00:00
|
|
|
resp.status_code, utils.xrepr(resp.msg), len(resp.content)
|
2014-10-25 02:30:54 +00:00
|
|
|
)
|
2012-09-25 23:07:22 +00:00
|
|
|
|
|
|
|
def _show(self, fp, header, data, hexdump):
|
|
|
|
if hexdump:
|
|
|
|
print >> fp, "%s (hex dump):"%header
|
|
|
|
for line in netlib.utils.hexdump(data):
|
|
|
|
print >> fp, "\t%s %s %s"%line
|
|
|
|
else:
|
|
|
|
print >> fp, "%s (unprintables escaped):"%header
|
|
|
|
print >> fp, netlib.utils.cleanBin(data)
|
|
|
|
|
2015-04-29 20:03:26 +00:00
|
|
|
def stop(self):
|
|
|
|
self.ws_framereader.terminate.put(None)
|
|
|
|
|
|
|
|
def wait(self):
|
|
|
|
if self.ws_framereader:
|
|
|
|
while 1:
|
|
|
|
try:
|
|
|
|
self.ws_framereader.is_done.get(timeout=0.05)
|
|
|
|
self.ws_framereader.join()
|
|
|
|
return
|
|
|
|
except Queue.Empty:
|
|
|
|
pass
|
|
|
|
|
2015-04-28 22:02:16 +00:00
|
|
|
def websocket_get_frame(self, frame):
|
|
|
|
"""
|
|
|
|
Called when a frame is received from the server.
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
def websocket_send_frame(self, r):
|
|
|
|
"""
|
|
|
|
Sends a single websocket frame.
|
|
|
|
"""
|
|
|
|
req = None
|
|
|
|
if isinstance(r, basestring):
|
|
|
|
r = language.parse_requests(r)[0]
|
|
|
|
if self.showreq:
|
|
|
|
self.wfile.start_log()
|
|
|
|
try:
|
|
|
|
req = language.serve(r, self.wfile, self.settings)
|
|
|
|
self.wfile.flush()
|
|
|
|
except tcp.NetLibTimeout:
|
|
|
|
if self.ignoretimeout:
|
|
|
|
return None
|
|
|
|
if self.showsummary:
|
|
|
|
print >> self.fp, "<<", "Timeout"
|
|
|
|
raise
|
|
|
|
except tcp.NetLibDisconnect: # pragma: nocover
|
|
|
|
if self.showsummary:
|
|
|
|
print >> self.fp, "<<", "Disconnect"
|
|
|
|
raise
|
|
|
|
finally:
|
|
|
|
if req:
|
|
|
|
if self.explain:
|
|
|
|
print >> self.fp, ">> Spec:", r.spec()
|
|
|
|
if self.showreq:
|
|
|
|
self._show(
|
2015-04-29 20:03:26 +00:00
|
|
|
self.fp, ">> Websocket Frame",
|
2015-04-28 22:02:16 +00:00
|
|
|
self.wfile.get_log(),
|
|
|
|
self.hexdump
|
|
|
|
)
|
|
|
|
|
2015-04-29 20:03:26 +00:00
|
|
|
def websocket_start(self, r, callback=None, limit=None):
|
2015-04-28 22:02:16 +00:00
|
|
|
"""
|
|
|
|
Performs an HTTP request, and attempts to drop into websocket
|
|
|
|
connection.
|
2015-04-29 20:03:26 +00:00
|
|
|
|
|
|
|
callback: A callback called within the websocket thread for every
|
|
|
|
server frame.
|
|
|
|
limit: Disconnect after receiving N server frames.
|
2015-04-28 22:02:16 +00:00
|
|
|
"""
|
|
|
|
resp = self.http(r)
|
|
|
|
if resp.status_code == 101:
|
|
|
|
if self.showsummary:
|
2015-04-29 20:03:26 +00:00
|
|
|
print >> self.fp, "<< websocket connection established..."
|
|
|
|
self.ws_framereader = WebsocketFrameReader(
|
|
|
|
self.rfile,
|
|
|
|
self.websocket_get_frame,
|
|
|
|
self.ws_read_limit
|
|
|
|
)
|
|
|
|
self.ws_framereader.start()
|
2015-04-28 22:02:16 +00:00
|
|
|
return resp
|
|
|
|
|
|
|
|
def http(self, r):
|
2012-06-29 22:51:13 +00:00
|
|
|
"""
|
2015-04-19 06:04:27 +00:00
|
|
|
Performs a single request.
|
2012-09-25 22:12:30 +00:00
|
|
|
|
2015-04-19 06:04:27 +00:00
|
|
|
r: A language.Request object, or a string representing one request.
|
2012-09-26 22:56:06 +00:00
|
|
|
|
2015-04-28 22:02:16 +00:00
|
|
|
Returns Response if we have a non-ignored response.
|
2015-04-19 20:56:47 +00:00
|
|
|
|
|
|
|
May raise http.HTTPError, tcp.NetLibError
|
2012-06-29 22:51:13 +00:00
|
|
|
"""
|
2015-04-19 06:04:27 +00:00
|
|
|
if isinstance(r, basestring):
|
|
|
|
r = language.parse_requests(r)[0]
|
2012-09-26 21:44:25 +00:00
|
|
|
resp, req = None, None
|
2015-04-19 06:04:27 +00:00
|
|
|
if self.showreq:
|
2012-09-26 02:25:39 +00:00
|
|
|
self.wfile.start_log()
|
2015-04-19 06:04:27 +00:00
|
|
|
if self.showresp:
|
2012-10-04 21:30:32 +00:00
|
|
|
self.rfile.start_log()
|
2012-09-26 02:25:39 +00:00
|
|
|
try:
|
2015-04-22 03:49:17 +00:00
|
|
|
req = language.serve(r, self.wfile, self.settings)
|
2012-09-26 02:25:39 +00:00
|
|
|
self.wfile.flush()
|
2015-04-20 03:42:33 +00:00
|
|
|
resp = list(
|
2015-04-22 03:49:17 +00:00
|
|
|
http.read_response(
|
|
|
|
self.rfile,
|
|
|
|
req["method"],
|
|
|
|
None
|
|
|
|
)
|
2015-04-20 03:42:33 +00:00
|
|
|
)
|
2015-04-19 06:04:27 +00:00
|
|
|
resp.append(self.sslinfo)
|
|
|
|
resp = Response(*resp)
|
2012-09-26 02:25:39 +00:00
|
|
|
except http.HttpError, v:
|
2015-04-19 06:04:27 +00:00
|
|
|
if self.showsummary:
|
|
|
|
print >> self.fp, "<< HTTP Error:", v.message
|
|
|
|
raise
|
2012-09-26 02:25:39 +00:00
|
|
|
except tcp.NetLibTimeout:
|
2015-04-19 06:04:27 +00:00
|
|
|
if self.ignoretimeout:
|
|
|
|
return None
|
|
|
|
if self.showsummary:
|
|
|
|
print >> self.fp, "<<", "Timeout"
|
|
|
|
raise
|
2012-09-26 02:25:39 +00:00
|
|
|
except tcp.NetLibDisconnect: # pragma: nocover
|
2015-04-19 06:04:27 +00:00
|
|
|
if self.showsummary:
|
|
|
|
print >> self.fp, "<<", "Disconnect"
|
|
|
|
raise
|
|
|
|
finally:
|
|
|
|
if req:
|
2015-04-20 03:42:33 +00:00
|
|
|
if resp and resp.status_code in self.ignorecodes:
|
2015-04-19 20:56:47 +00:00
|
|
|
resp = None
|
|
|
|
else:
|
|
|
|
if self.explain:
|
|
|
|
print >> self.fp, ">> Spec:", r.spec()
|
2014-03-02 06:04:56 +00:00
|
|
|
|
2015-04-19 20:56:47 +00:00
|
|
|
if self.showreq:
|
|
|
|
self._show(
|
2015-04-20 03:42:33 +00:00
|
|
|
self.fp, ">> Request",
|
|
|
|
self.wfile.get_log(),
|
|
|
|
self.hexdump
|
2015-04-19 20:56:47 +00:00
|
|
|
)
|
2012-10-30 22:23:53 +00:00
|
|
|
|
2015-04-19 20:56:47 +00:00
|
|
|
if self.showsummary and resp:
|
|
|
|
self._show_summary(self.fp, resp)
|
|
|
|
if self.showresp:
|
|
|
|
self._show(
|
|
|
|
self.fp,
|
|
|
|
"<< Response",
|
|
|
|
self.rfile.get_log(),
|
|
|
|
self.hexdump
|
|
|
|
)
|
2015-04-19 06:04:27 +00:00
|
|
|
return resp
|
2014-03-02 06:04:56 +00:00
|
|
|
|
2015-04-28 22:02:16 +00:00
|
|
|
def request(self, r):
|
|
|
|
"""
|
|
|
|
Performs a single request.
|
|
|
|
|
|
|
|
r: A language.Request object, or a string representing one request.
|
|
|
|
|
|
|
|
Returns Response if we have a non-ignored response.
|
|
|
|
|
|
|
|
May raise http.HTTPError, tcp.NetLibError
|
|
|
|
"""
|
|
|
|
if isinstance(r, basestring):
|
|
|
|
r = language.parse_requests(r)[0]
|
|
|
|
if isinstance(r, language.Request):
|
|
|
|
if r.ws:
|
|
|
|
return self.websocket_start(r, self.websocket_get_frame)
|
|
|
|
else:
|
|
|
|
return self.http(r)
|
|
|
|
elif isinstance(r, language.WebsocketFrame):
|
|
|
|
self.websocket_send_frame(r)
|
|
|
|
|
2014-03-02 06:04:56 +00:00
|
|
|
|
2015-04-17 05:45:50 +00:00
|
|
|
def main(args): # pragma: nocover
|
2014-10-25 06:50:48 +00:00
|
|
|
memo = set([])
|
2014-10-26 05:16:47 +00:00
|
|
|
trycount = 0
|
2015-04-29 20:03:26 +00:00
|
|
|
p = None
|
2014-10-24 04:12:54 +00:00
|
|
|
try:
|
2014-10-25 04:58:59 +00:00
|
|
|
cnt = 0
|
|
|
|
while 1:
|
2015-03-14 00:54:47 +00:00
|
|
|
if cnt == args.repeat and args.repeat != 0:
|
|
|
|
break
|
2014-10-26 05:16:47 +00:00
|
|
|
if trycount > args.memolimit:
|
|
|
|
print >> sys.stderr, "Memo limit exceeded..."
|
|
|
|
return
|
2015-03-14 00:54:47 +00:00
|
|
|
if args.wait and cnt != 0:
|
|
|
|
time.sleep(args.wait)
|
2014-10-26 05:16:47 +00:00
|
|
|
|
2014-10-25 04:58:59 +00:00
|
|
|
cnt += 1
|
2014-10-25 06:50:48 +00:00
|
|
|
if args.random:
|
|
|
|
playlist = [random.choice(args.requests)]
|
|
|
|
else:
|
|
|
|
playlist = args.requests
|
2014-10-24 04:12:54 +00:00
|
|
|
p = Pathoc(
|
|
|
|
(args.host, args.port),
|
2015-04-19 06:04:27 +00:00
|
|
|
ssl = args.ssl,
|
|
|
|
sni = args.sni,
|
|
|
|
sslversion = args.sslversion,
|
|
|
|
clientcert = args.clientcert,
|
|
|
|
ciphers = args.ciphers,
|
|
|
|
showreq = args.showreq,
|
|
|
|
showresp = args.showresp,
|
|
|
|
explain = args.explain,
|
|
|
|
hexdump = args.hexdump,
|
|
|
|
ignorecodes = args.ignorecodes,
|
|
|
|
ignoretimeout = args.ignoretimeout,
|
|
|
|
showsummary = True
|
2014-10-24 04:12:54 +00:00
|
|
|
)
|
2014-10-25 06:50:48 +00:00
|
|
|
if args.explain or args.memo:
|
|
|
|
playlist = [
|
2015-04-22 03:49:17 +00:00
|
|
|
i.freeze(p.settings) for i in playlist
|
2014-10-25 06:50:48 +00:00
|
|
|
]
|
|
|
|
if args.memo:
|
|
|
|
newlist = []
|
|
|
|
for spec in playlist:
|
|
|
|
h = hashlib.sha256(spec.spec()).digest()
|
|
|
|
if h not in memo:
|
|
|
|
memo.add(h)
|
|
|
|
newlist.append(spec)
|
|
|
|
playlist = newlist
|
|
|
|
if not playlist:
|
2014-10-26 05:16:47 +00:00
|
|
|
trycount += 1
|
2014-10-25 06:50:48 +00:00
|
|
|
continue
|
|
|
|
|
2014-10-26 05:16:47 +00:00
|
|
|
trycount = 0
|
2014-10-24 04:12:54 +00:00
|
|
|
try:
|
2015-04-19 03:55:22 +00:00
|
|
|
p.connect(args.connect_to, args.showssl)
|
2015-03-14 00:54:47 +00:00
|
|
|
except tcp.NetLibError, v:
|
|
|
|
print >> sys.stderr, str(v)
|
|
|
|
continue
|
|
|
|
except PathocError, v:
|
2014-10-24 04:12:54 +00:00
|
|
|
print >> sys.stderr, str(v)
|
|
|
|
sys.exit(1)
|
|
|
|
if args.timeout:
|
|
|
|
p.settimeout(args.timeout)
|
2014-10-25 03:43:01 +00:00
|
|
|
for spec in playlist:
|
2015-04-19 06:04:27 +00:00
|
|
|
try:
|
|
|
|
ret = p.request(spec)
|
|
|
|
sys.stdout.flush()
|
|
|
|
if ret and args.oneshot:
|
|
|
|
return
|
2015-04-19 20:56:47 +00:00
|
|
|
except (http.HttpError, tcp.NetLibError), v:
|
2015-04-19 06:04:27 +00:00
|
|
|
pass
|
2015-04-29 20:03:26 +00:00
|
|
|
p.wait()
|
2014-10-24 04:12:54 +00:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
pass
|
2015-04-29 20:03:26 +00:00
|
|
|
if p:
|
|
|
|
p.stop()
|
|
|
|
p.wait()
|