|
a/rdpl2stream/lib/DummyMMSHandler.py |
|
b/rdpl2stream/lib/DummyMMSHandler.py |
|
... |
|
... |
15 |
#
|
15 |
#
|
16 |
# You should have received a copy of the GNU General Public License
|
16 |
# You should have received a copy of the GNU General Public License
|
17 |
# along with Radio Tray. If not, see <http://www.gnu.org/licenses/>.
|
17 |
# along with Radio Tray. If not, see <http://www.gnu.org/licenses/>.
|
18 |
#
|
18 |
#
|
19 |
##########################################################################
|
19 |
##########################################################################
|
20 |
import urllib2
|
20 |
import sys
|
|
|
21 |
PY3 = sys.version > '3'
|
|
|
22 |
if PY3:
|
|
|
23 |
from urllib.error import URLError as URLError
|
|
|
24 |
from urllib.request import HTTPRedirectHandler
|
|
|
25 |
else:
|
|
|
26 |
from urllib2 import URLError as URLError
|
|
|
27 |
from urllib2 import HTTPRedirectHandler
|
21 |
|
28 |
|
|
|
29 |
from lib.common import Logger
|
|
|
30 |
|
22 |
class DummyMMSHandler(urllib2.HTTPRedirectHandler):
|
31 |
class DummyMMSHandler(HTTPRedirectHandler):
|
|
|
32 |
def __init__(self):
|
|
|
33 |
self.log = Logger()
|
23 |
|
34 |
|
24 |
# Handle mms redirection, or let the standard code deal with it.
|
35 |
# Handle mms redirection, or let the standard code deal with it.
|
25 |
def http_error_302(self, req, fp, code, msg, headers):
|
36 |
def http_error_302(self, req, fp, code, msg, headers):
|
|
|
37 |
#self.log.info("http_error_302: code %s headers %s" % (code, headers))
|
26 |
if 'location' in headers:
|
38 |
if 'location' in headers:
|
27 |
newurl = headers.getheaders('location')[0]
|
39 |
newurl = headers['location']
|
28 |
if newurl.startswith('mms:'):
|
40 |
if newurl.startswith('mms:'):
|
29 |
raise urllib2.URLError("MMS REDIRECT:"+headers["Location"])
|
41 |
raise URLError("MMS REDIRECT:" + headers["Location"])
|
30 |
return urllib2.HTTPRedirectHandler.http_error_302(self, req, fp, code,
|
42 |
return HTTPRedirectHandler.http_error_302(self, req, fp, code,
|
31 |
msg, headers)
|
43 |
msg, headers)
|