Python urllib.addinfourl() Examples

The following are code examples for showing how to use urllib.addinfourl(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: mysite-master   Author: hanbox   File: test_ping.py    MIT License 6 votes vote down vote up
def fake_urlopen(self, url):
        """Fake urlopen using test client"""
        if 'example' in url:
            response = StringIO('')
            return addinfourl(response, {'X-Pingback': '/xmlrpc.php',
                                         'Content-Type':
                                         'text/html; charset=utf-8'}, url)
        elif 'localhost' in url:
            response = StringIO(
                '<link rel="pingback" href="/xmlrpc/">')
            return addinfourl(response, {'Content-Type':
                                         'application/xhtml+xml'}, url)
        elif 'google' in url:
            response = StringIO('PNG CONTENT')
            return addinfourl(response, {'content-type': 'image/png'}, url)
        elif 'error' in url:
            raise URLError('Invalid ressource') 
Example 2
Project: openhatch   Author: campbe13   File: test_task_http.py    GNU Affero General Public License v3.0 5 votes vote down vote up
def mock_urlopen(response_method):

    import urllib2
    urlopen = urllib2.urlopen

    @wraps(urlopen)
    def _mocked(url, *args, **kwargs):
        response_data, headers = response_method(url)
        return addinfourl(StringIO(response_data), headers, url)

    urllib2.urlopen = _mocked

    yield True

    urllib2.urlopen = urlopen 
Example 3
Project: openhatch   Author: campbe13   File: feedparser.py    GNU Affero General Public License v3.0 5 votes vote down vote up
def http_error_default(self, req, fp, code, msg, headers):
        if ((code / 100) == 3) and (code != 304):
            return self.http_error_302(req, fp, code, msg, headers)
        infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        infourl.status = code
        return infourl 
Example 4
Project: openhatch   Author: campbe13   File: feedparser.py    GNU Affero General Public License v3.0 5 votes vote down vote up
def http_error_302(self, req, fp, code, msg, headers):
        if headers.dict.has_key('location'):
            infourl = urllib2.HTTPRedirectHandler.http_error_302(self, req, fp, code, msg, headers)
        else:
            infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        if not hasattr(infourl, 'status'):
            infourl.status = code
        return infourl 
Example 5
Project: openhatch   Author: campbe13   File: feedparser.py    GNU Affero General Public License v3.0 5 votes vote down vote up
def http_error_301(self, req, fp, code, msg, headers):
        if headers.dict.has_key('location'):
            infourl = urllib2.HTTPRedirectHandler.http_error_301(self, req, fp, code, msg, headers)
        else:
            infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        if not hasattr(infourl, 'status'):
            infourl.status = code
        return infourl 
Example 6
Project: Pancas   Author: Sup3Roque   File: plugintools.py    GNU General Public License v2.0 5 votes vote down vote up
def http_error_302(self,req,fp,code,msg,headers): infourl=urllib.addinfourl(fp,headers,req.get_full_url()); infourl.status=code; infourl.code=code; return infourl 
Example 7
Project: TESTGIT   Author: B-ROY   File: feedparser.py    Apache License 2.0 5 votes vote down vote up
def http_error_default(self, req, fp, code, msg, headers):
        if ((code / 100) == 3) and (code != 304):
            return self.http_error_302(req, fp, code, msg, headers)
        infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        infourl.status = code
        return infourl 
Example 8
Project: TESTGIT   Author: B-ROY   File: feedparser.py    Apache License 2.0 5 votes vote down vote up
def http_error_302(self, req, fp, code, msg, headers):
        if headers.dict.has_key('location'):
            infourl = urllib2.HTTPRedirectHandler.http_error_302(self, req, fp, code, msg, headers)
        else:
            infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        if not hasattr(infourl, 'status'):
            infourl.status = code
        return infourl 
Example 9
Project: TESTGIT   Author: B-ROY   File: feedparser.py    Apache License 2.0 5 votes vote down vote up
def http_error_301(self, req, fp, code, msg, headers):
        if headers.dict.has_key('location'):
            infourl = urllib2.HTTPRedirectHandler.http_error_301(self, req, fp, code, msg, headers)
        else:
            infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        if not hasattr(infourl, 'status'):
            infourl.status = code
        return infourl 
Example 10
Project: bugatsinho.github.io   Author: bugatsinho   File: openload.py    GNU General Public License v3.0 5 votes vote down vote up
def http_error_302(self, req, fp, code, msg, headers):
        infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        infourl.status = code
        infourl.code = code
        return infourl 
Example 11
Project: bugatsinho.github.io   Author: bugatsinho   File: openload.py    GNU General Public License v3.0 5 votes vote down vote up
def http_error_302(self, req, fp, code, msg, headers):
        infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        infourl.status = code
        infourl.code = code
        return infourl 
Example 12
Project: bugatsinho.github.io   Author: bugatsinho   File: openload.py    GNU General Public License v3.0 5 votes vote down vote up
def http_error_302(self, req, fp, code, msg, headers):
        infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        infourl.status = code
        infourl.code = code
        return infourl 
Example 13
Project: ithz   Author: ergoithz   File: feedparser.py    MIT License 5 votes vote down vote up
def http_error_default(self, req, fp, code, msg, headers):
        if ((code / 100) == 3) and (code != 304):
            return self.http_error_302(req, fp, code, msg, headers)
        infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        infourl.status = code
        return infourl 
Example 14
Project: ithz   Author: ergoithz   File: feedparser.py    MIT License 5 votes vote down vote up
def http_error_302(self, req, fp, code, msg, headers):
        if headers.dict.has_key('location'):
            infourl = urllib2.HTTPRedirectHandler.http_error_302(self, req, fp, code, msg, headers)
        else:
            infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        if not hasattr(infourl, 'status'):
            infourl.status = code
        return infourl 
Example 15
Project: ithz   Author: ergoithz   File: feedparser.py    MIT License 5 votes vote down vote up
def http_error_301(self, req, fp, code, msg, headers):
        if headers.dict.has_key('location'):
            infourl = urllib2.HTTPRedirectHandler.http_error_301(self, req, fp, code, msg, headers)
        else:
            infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        if not hasattr(infourl, 'status'):
            infourl.status = code
        return infourl 
Example 16
Project: banruo   Author: yingshang   File: test_http.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def mock_urlopen(response_method):

    urlopen = http.urlopen

    @wraps(urlopen)
    def _mocked(url, *args, **kwargs):
        response_data, headers = response_method(url)
        return addinfourl(WhateverIO(response_data), headers, url)

    http.urlopen = _mocked

    try:
        yield True
    finally:
        http.urlopen = urlopen 
Example 17
Project: ngDownloaderAPI   Author: manishbisht   File: compat.py    MIT License 5 votes vote down vote up
def data_open(self, req):
            # data URLs as specified in RFC 2397.
            #
            # ignores POSTed data
            #
            # syntax:
            # dataurl   := "data:" [ mediatype ] [ ";base64" ] "," data
            # mediatype := [ type "/" subtype ] *( ";" parameter )
            # data      := *urlchar
            # parameter := attribute "=" value
            url = req.get_full_url()

            scheme, data = url.split(':', 1)
            mediatype, data = data.split(',', 1)

            # even base64 encoded data URLs might be quoted so unquote in any case:
            data = compat_urllib_parse_unquote_to_bytes(data)
            if mediatype.endswith(';base64'):
                data = binascii.a2b_base64(data)
                mediatype = mediatype[:-7]

            if not mediatype:
                mediatype = 'text/plain;charset=US-ASCII'

            headers = email.message_from_string(
                'Content-type: %s\nContent-length: %d\n' % (mediatype, len(data)))

            return compat_urllib_response.addinfourl(io.BytesIO(data), headers, url) 
Example 18
Project: WebExploitationTool   Author: AutoSecTools   File: st.py    GNU General Public License v3.0 5 votes vote down vote up
def http_error_302(self, req, fp, code, msg, headers):
        x = addinfourl(fp, headers, (req.get_full_url)())
        (x.status) = code
        (x.code) = code
        return x 
Example 19
Project: dkodi   Author: dknlght   File: scrapertools.py    GNU General Public License v2.0 5 votes vote down vote up
def http_error_302(self, req, fp, code, msg, headers):
        infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        infourl.status = code
        infourl.code = code
        return infourl 
Example 20
Project: dkodi   Author: dknlght   File: scrapertools.py    GNU General Public License v2.0 5 votes vote down vote up
def http_error_302(self, req, fp, code, msg, headers):
        infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        infourl.status = code
        infourl.code = code
        return infourl 
Example 21
Project: dkodi   Author: dknlght   File: scrapertools.py    GNU General Public License v2.0 5 votes vote down vote up
def http_error_302(self, req, fp, code, msg, headers):
        infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        infourl.status = code
        infourl.code = code
        return infourl 
Example 22
Project: dkodi   Author: dknlght   File: scrapertools.py    GNU General Public License v2.0 5 votes vote down vote up
def http_error_302(self, req, fp, code, msg, headers):
        infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        infourl.status = code
        infourl.code = code
        return infourl 
Example 23
Project: dkodi   Author: dknlght   File: scrapertools.py    GNU General Public License v2.0 5 votes vote down vote up
def http_error_302(self, req, fp, code, msg, headers):
        infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        infourl.status = code
        infourl.code = code
        return infourl 
Example 24
Project: Hatkey   Author: Naayouu   File: browser.py    GNU General Public License v3.0 5 votes vote down vote up
def get_response(self):
        """Returns a copy of the current response."""
        return addinfourl(BytesIO(self.data), self._response.info(), self._response.geturl()) 
Example 25
Project: Hatkey   Author: Naayouu   File: browser.py    GNU General Public License v3.0 5 votes vote down vote up
def _make_response(self, result, url):

        data = "\r\n".join(["%s: %s" % (k, v) for k, v in result.header_items])

        if PY2:
            headers = HTTPMessage(BytesIO(data))
        else:
            import email
            headers = email.message_from_string(data)

        response = addinfourl(BytesIO(result.data), headers, url)
        code, msg = result.status.split(None, 1)
        response.code, response.msg = int(code), msg
        return response 
Example 26
Project: WrapSQLMAP   Author: THSamurai   File: rangehandler.py    GNU General Public License v3.0 5 votes vote down vote up
def http_error_206(self, req, fp, code, msg, hdrs):
        # 206 Partial Content Response
        r = urllib.addinfourl(fp, hdrs, req.get_full_url())
        r.code = code
        r.msg = msg
        return r 
Example 27
Project: tvalacarta   Author: tvalacarta   File: plugintools.py    GNU General Public License v3.0 5 votes vote down vote up
def http_error_302(self, req, fp, code, msg, headers):
        infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        infourl.status = code
        infourl.code = code
        return infourl 
Example 28
Project: tvalacarta   Author: tvalacarta   File: plugintools.py    GNU General Public License v3.0 5 votes vote down vote up
def http_error_302(self, req, fp, code, msg, headers):
        infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        infourl.status = code
        infourl.code = code
        return infourl 
Example 29
Project: tvalacarta   Author: tvalacarta   File: compat.py    GNU General Public License v3.0 5 votes vote down vote up
def data_open(self, req):
            # data URLs as specified in RFC 2397.
            #
            # ignores POSTed data
            #
            # syntax:
            # dataurl   := "data:" [ mediatype ] [ ";base64" ] "," data
            # mediatype := [ type "/" subtype ] *( ";" parameter )
            # data      := *urlchar
            # parameter := attribute "=" value
            url = req.get_full_url()

            scheme, data = url.split(':', 1)
            mediatype, data = data.split(',', 1)

            # even base64 encoded data URLs might be quoted so unquote in any case:
            data = compat_urllib_parse_unquote_to_bytes(data)
            if mediatype.endswith(';base64'):
                data = binascii.a2b_base64(data)
                mediatype = mediatype[:-7]

            if not mediatype:
                mediatype = 'text/plain;charset=US-ASCII'

            headers = email.message_from_string(
                'Content-type: %s\nContent-length: %d\n' % (mediatype, len(data)))

            return compat_urllib_response.addinfourl(io.BytesIO(data), headers, url) 
Example 30
Project: tvalacarta   Author: tvalacarta   File: scrapertools.py    GNU General Public License v3.0 5 votes vote down vote up
def http_error_302(self, req, fp, code, msg, headers):
        infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        infourl.status = code
        infourl.code = code
        return infourl 
Example 31
Project: tvalacarta   Author: tvalacarta   File: plugintools.py    GNU General Public License v3.0 5 votes vote down vote up
def http_error_302(self, req, fp, code, msg, headers):
        infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        infourl.status = code
        infourl.code = code
        return infourl 
Example 32
Project: dmind   Author: siouka   File: plugintools.py    GNU General Public License v2.0 5 votes vote down vote up
def http_error_302(self,req,fp,code,msg,headers): infourl=urllib.addinfourl(fp,headers,req.get_full_url()); infourl.status=code; infourl.code=code; return infourl 
Example 33
Project: NoobSec-Toolkit   Author: krintoxi   File: rangehandler.py    GNU General Public License v2.0 5 votes vote down vote up
def http_error_206(self, req, fp, code, msg, hdrs):
        # 206 Partial Content Response
        r = urllib.addinfourl(fp, hdrs, req.get_full_url())
        r.code = code
        r.msg = msg
        return r 
Example 34
Project: NoobSec-Toolkit   Author: krintoxi   File: rangehandler.py    GNU General Public License v2.0 5 votes vote down vote up
def http_error_206(self, req, fp, code, msg, hdrs):
        # 206 Partial Content Response
        r = urllib.addinfourl(fp, hdrs, req.get_full_url())
        r.code = code
        r.msg = msg
        return r 
Example 35
Project: gb160-kodi-addons   Author: gb160   File: plugintools.py    GNU General Public License v2.0 5 votes vote down vote up
def http_error_302(self,req,fp,code,msg,headers): infourl=urllib.addinfourl(fp,headers,req.get_full_url()); infourl.status=code; infourl.code=code; return infourl 
Example 36
Project: Python-ornekler   Author: ilteriskeskin   File: compat.py    GNU General Public License v3.0 5 votes vote down vote up
def data_open(self, req):
            # data URLs as specified in RFC 2397.
            #
            # ignores POSTed data
            #
            # syntax:
            # dataurl   := "data:" [ mediatype ] [ ";base64" ] "," data
            # mediatype := [ type "/" subtype ] *( ";" parameter )
            # data      := *urlchar
            # parameter := attribute "=" value
            url = req.get_full_url()

            scheme, data = url.split(':', 1)
            mediatype, data = data.split(',', 1)

            # even base64 encoded data URLs might be quoted so unquote in any case:
            data = compat_urllib_parse_unquote_to_bytes(data)
            if mediatype.endswith(';base64'):
                data = binascii.a2b_base64(data)
                mediatype = mediatype[:-7]

            if not mediatype:
                mediatype = 'text/plain;charset=US-ASCII'

            headers = email.message_from_string(
                'Content-type: %s\nContent-length: %d\n' % (mediatype, len(data)))

            return compat_urllib_response.addinfourl(io.BytesIO(data), headers, url) 
Example 37
Project: Plex-CS   Author: zobe123   File: feedparser.py    GNU General Public License v3.0 5 votes vote down vote up
def http_error_default(self, req, fp, code, msg, headers):
        if ((code / 100) == 3) and (code != 304):
            return self.http_error_302(req, fp, code, msg, headers)
        infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        infourl.status = code
        return infourl 
Example 38
Project: Plex-CS   Author: zobe123   File: feedparser.py    GNU General Public License v3.0 5 votes vote down vote up
def http_error_302(self, req, fp, code, msg, headers):
        if headers.dict.has_key('location'):
            infourl = urllib2.HTTPRedirectHandler.http_error_302(self, req, fp, code, msg, headers)
        else:
            infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        if not hasattr(infourl, 'status'):
            infourl.status = code
        return infourl 
Example 39
Project: Plex-CS   Author: zobe123   File: feedparser.py    GNU General Public License v3.0 5 votes vote down vote up
def http_error_301(self, req, fp, code, msg, headers):
        if headers.dict.has_key('location'):
            infourl = urllib2.HTTPRedirectHandler.http_error_301(self, req, fp, code, msg, headers)
        else:
            infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        if not hasattr(infourl, 'status'):
            infourl.status = code
        return infourl 
Example 40
Project: repository.kodiman.public-1.0.2   Author: Milhano   File: plugintools.py    GNU General Public License v3.0 5 votes vote down vote up
def http_error_302(self,req,fp,code,msg,headers): infourl=urllib.addinfourl(fp,headers,req.get_full_url()); infourl.status=code; infourl.code=code; return infourl 
Example 41
Project: repository.kodiman.public-1.0.2   Author: Milhano   File: api.py    GNU General Public License v3.0 5 votes vote down vote up
def http_error_default(self, req, fp, code, msg, hdrs):
        infourl = urllib.addinfourl(fp, hdrs, req.get_full_url())
        infourl.status = code
        infourl.code = code
        return infourl 
Example 42
Project: repository.kodiman.public-1.0.2   Author: Milhano   File: api.py    GNU General Public License v3.0 5 votes vote down vote up
def http_error_302(self, req, fp, code, msg, headers):
        infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        infourl.status = code
        infourl.code = code
        return infourl 
Example 43
Project: repository.kodiman.public-1.0.2   Author: Milhano   File: api.py    GNU General Public License v3.0 5 votes vote down vote up
def http_error_default(self, req, fp, code, msg, hdrs):
        infourl = urllib.addinfourl(fp, hdrs, req.get_full_url())
        infourl.status = code
        infourl.code = code
        return infourl 
Example 44
Project: repository.kodiman.public-1.0.2   Author: Milhano   File: api.py    GNU General Public License v3.0 5 votes vote down vote up
def http_error_302(self, req, fp, code, msg, headers):
        infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        infourl.status = code
        infourl.code = code
        return infourl 
Example 45
Project: urlgrabber   Author: rpm-software-management   File: byterange.py    GNU Lesser General Public License v2.1 5 votes vote down vote up
def http_error_206(self, req, fp, code, msg, hdrs):
        # 206 Partial Content Response
        r = urllib.addinfourl(fp, hdrs, req.get_full_url())
        r.code = code
        r.msg = msg
        return r 
Example 46
Project: urlgrabber   Author: rpm-software-management   File: byterange.py    GNU Lesser General Public License v2.1 5 votes vote down vote up
def open_local_file(self, req):
        host = req.get_host()
        file = req.get_selector()
        localfile = urllib.url2pathname(file)
        stats = os.stat(localfile)
        size = stats[stat.ST_SIZE]
        modified = email.utils.formatdate(stats[stat.ST_MTIME])
        mtype = mimetypes.guess_type(file)[0]
        if host:
            host, port = urllib.splitport(host)
            if port or socket.gethostbyname(host) not in self.get_names():
                raise URLError('file not on local host')
        fo = open(localfile,'rb')
        brange = req.headers.get('Range',None)
        brange = range_header_to_tuple(brange)
        assert brange != ()
        if brange:
            (fb,lb) = brange
            if lb == '': lb = size
            if fb < 0 or fb > size or lb > size:
                raise RangeError(9, 'Requested Range Not Satisfiable')
            size = (lb - fb)
            fo = RangeableFileObject(fo, (fb,lb))
        headers = email.message_from_string(
            'Content-Type: %s\nContent-Length: %d\nLast-modified: %s\n' %
            (mtype or 'text/plain', size, modified))
        return urllib.addinfourl(fo, headers, 'file:'+file)


# FTP Range Support
# Unfortunately, a large amount of base FTP code had to be copied
# from urllib and urllib2 in order to insert the FTP REST command.
# Code modifications for range support have been commented as
# follows:
# -- range support modifications start/end here 
Example 47
Project: urlgrabber   Author: rpm-software-management   File: grabber.py    GNU Lesser General Public License v2.1 5 votes vote down vote up
def geturl(self):
        """ Provide the geturl() method, used to be got from
            urllib.addinfourl, via. urllib.URLopener.* """
        return self.url 
Example 48
Project: plugin.video.torrserve   Author: Nemiroff   File: client.py    GNU General Public License v3.0 5 votes vote down vote up
def http_error_302(self, req, fp, code, msg, headers):
        import urllib
        infourl = urllib.addinfourl(fp, headers, headers["Location"])
        infourl.status = code
        infourl.code = code
        return infourl 
Example 49
Project: plugin.video.myclouds   Author: ytan-git   File: CloudXunlei.py    Apache License 2.0 5 votes vote down vote up
def http_error_302(self, req, fp, code, msg, headers):
            infourl = urllib.addinfourl(fp, headers, req.get_full_url())
            infourl.status = code
            infourl.code = code
            return infourl 
Example 50
Project: saveScreenshot   Author: Adamyuanyuan   File: browser.py    Do What The F*ck You Want To Public License 5 votes vote down vote up
def get_response(self):
        """Returns a copy of the current response."""
        return urllib.addinfourl(StringIO(self.data), self._response.info(), self._response.geturl()) 
Example 51
Project: saveScreenshot   Author: Adamyuanyuan   File: browser.py    Do What The F*ck You Want To Public License 5 votes vote down vote up
def _make_response(self, result, url):
        data = "\r\n".join(["%s: %s" % (k, v) for k, v in result.header_items])
        headers = httplib.HTTPMessage(StringIO(data))
        response = urllib.addinfourl(StringIO(result.data), headers, url)
        code, msg = result.status.split(None, 1)
        response.code, response.msg = int(code), msg
        return response 
Example 52
Project: addon   Author: alfa-addon   File: navigation.py    GNU General Public License v3.0 5 votes vote down vote up
def http_error_302(self, req, fp, code, msg, headers):
        import urllib
        infourl = urllib.addinfourl(fp, headers, headers["Location"])
        infourl.status = code
        infourl.code = code
        return infourl 
Example 53
Project: download-manager   Author: thispc   File: feedparser.py    GNU General Public License v3.0 5 votes vote down vote up
def http_error_default(self, req, fp, code, msg, headers):
        if ((code / 100) == 3) and (code != 304):
            return self.http_error_302(req, fp, code, msg, headers)
        infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        infourl.status = code
        return infourl 
Example 54
Project: download-manager   Author: thispc   File: feedparser.py    GNU General Public License v3.0 5 votes vote down vote up
def http_error_302(self, req, fp, code, msg, headers):
        if headers.dict.has_key('location'):
            infourl = urllib2.HTTPRedirectHandler.http_error_302(self, req, fp, code, msg, headers)
        else:
            infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        if not hasattr(infourl, 'status'):
            infourl.status = code
        return infourl 
Example 55
Project: download-manager   Author: thispc   File: feedparser.py    GNU General Public License v3.0 5 votes vote down vote up
def http_error_301(self, req, fp, code, msg, headers):
        if headers.dict.has_key('location'):
            infourl = urllib2.HTTPRedirectHandler.http_error_301(self, req, fp, code, msg, headers)
        else:
            infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        if not hasattr(infourl, 'status'):
            infourl.status = code
        return infourl 
Example 56
Project: BL-Bot   Author: IOIIIO   File: compat.py    GNU General Public License v3.0 5 votes vote down vote up
def data_open(self, req):
            # data URLs as specified in RFC 2397.
            #
            # ignores POSTed data
            #
            # syntax:
            # dataurl   := "data:" [ mediatype ] [ ";base64" ] "," data
            # mediatype := [ type "/" subtype ] *( ";" parameter )
            # data      := *urlchar
            # parameter := attribute "=" value
            url = req.get_full_url()

            scheme, data = url.split(':', 1)
            mediatype, data = data.split(',', 1)

            # even base64 encoded data URLs might be quoted so unquote in any case:
            data = compat_urllib_parse_unquote_to_bytes(data)
            if mediatype.endswith(';base64'):
                data = binascii.a2b_base64(data)
                mediatype = mediatype[:-7]

            if not mediatype:
                mediatype = 'text/plain;charset=US-ASCII'

            headers = email.message_from_string(
                'Content-type: %s\nContent-length: %d\n' % (mediatype, len(data)))

            return compat_urllib_response.addinfourl(io.BytesIO(data), headers, url) 
Example 57
Project: finkin   Author: gabelerner   File: browser.py    MIT License 5 votes vote down vote up
def get_response(self):
        """Returns a copy of the current response."""
        return urllib.addinfourl(StringIO(self.data), self._response.info(), self._response.geturl()) 
Example 58
Project: finkin   Author: gabelerner   File: browser.py    MIT License 5 votes vote down vote up
def _make_response(self, result, url):
        data = "\r\n".join(["%s: %s" % (k, v) for k, v in result.header_items])
        headers = httplib.HTTPMessage(StringIO(data))
        response = urllib.addinfourl(StringIO(result.data), headers, url)
        code, msg = result.status.split(None, 1)
        response.code, response.msg = int(code), msg
        return response 
Example 59
Project: StreamingFR.bundle   Author: jurnet   File: __init__.py    GNU General Public License v2.0 5 votes vote down vote up
def http_error_302(self, req, fp, code, msg, headers):
        infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        infourl.status = code
        infourl.code = code
        return infourl 
Example 60
Project: StreamingFR.bundle   Author: jurnet   File: scrapertools.py    GNU General Public License v2.0 5 votes vote down vote up
def http_error_302(self, req, fp, code, msg, headers):
        infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        infourl.status = code
        infourl.code = code
        return infourl 
Example 61
Project: iblis-cast   Author: vdelacou   File: compat.py    Apache License 2.0 5 votes vote down vote up
def data_open(self, req):
            # data URLs as specified in RFC 2397.
            #
            # ignores POSTed data
            #
            # syntax:
            # dataurl   := "data:" [ mediatype ] [ ";base64" ] "," data
            # mediatype := [ type "/" subtype ] *( ";" parameter )
            # data      := *urlchar
            # parameter := attribute "=" value
            url = req.get_full_url()

            scheme, data = url.split(':', 1)
            mediatype, data = data.split(',', 1)

            # even base64 encoded data URLs might be quoted so unquote in any case:
            data = compat_urllib_parse_unquote_to_bytes(data)
            if mediatype.endswith(';base64'):
                data = binascii.a2b_base64(data)
                mediatype = mediatype[:-7]

            if not mediatype:
                mediatype = 'text/plain;charset=US-ASCII'

            headers = email.message_from_string(
                'Content-type: %s\nContent-length: %d\n' % (mediatype, len(data)))

            return compat_urllib_response.addinfourl(io.BytesIO(data), headers, url) 
Example 62
Project: Plugin.Video.Mercy   Author: montanapr   File: plugintools.py    GNU General Public License v2.0 5 votes vote down vote up
def http_error_302(self, req, fp, code, msg, headers):
        infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        infourl.status = code
        infourl.code = code
        return infourl 
Example 63
Project: Plugin.Video.Mercy   Author: montanapr   File: plugintools_ptv.py    GNU General Public License v2.0 5 votes vote down vote up
def http_error_302(self, req, fp, code, msg, headers):
        infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        infourl.status = code
        infourl.code = code
        return infourl 
Example 64
Project: plugin.video.avezy   Author: egrueda   File: plugintools.py    GNU General Public License v3.0 5 votes vote down vote up
def http_error_302(self, req, fp, code, msg, headers):
        infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        infourl.status = code
        infourl.code = code
        return infourl 
Example 65
Project: Burp-Addons   Author: SofianeHamlaoui   File: rangehandler.py    GNU General Public License v3.0 5 votes vote down vote up
def http_error_206(self, req, fp, code, msg, hdrs):
        # 206 Partial Content Response
        r = urllib.addinfourl(fp, hdrs, req.get_full_url())
        r.code = code
        r.msg = msg
        return r 
Example 66
Project: anime-dl   Author: Xonshiz   File: compat.py    MIT License 5 votes vote down vote up
def data_open(self, req):
            # data URLs as specified in RFC 2397.
            #
            # ignores POSTed data
            #
            # syntax:
            # dataurl   := "data:" [ mediatype ] [ ";base64" ] "," data
            # mediatype := [ type "/" subtype ] *( ";" parameter )
            # data      := *urlchar
            # parameter := attribute "=" value
            url = req.get_full_url()

            scheme, data = url.split(':', 1)
            mediatype, data = data.split(',', 1)

            # even base64 encoded data URLs might be quoted so unquote in any case:
            data = compat_urllib_parse_unquote_to_bytes(data)
            if mediatype.endswith(';base64'):
                data = binascii.a2b_base64(data)
                mediatype = mediatype[:-7]

            if not mediatype:
                mediatype = 'text/plain;charset=US-ASCII'

            headers = email.message_from_string(
                'Content-type: %s\nContent-length: %d\n' % (mediatype, len(data)))

            return compat_urllib_response.addinfourl(io.BytesIO(data), headers, url) 
Example 67
Project: root-2015-tasks   Author: yandex   File: byterange.py    GNU General Public License v3.0 5 votes vote down vote up
def http_error_206(self, req, fp, code, msg, hdrs):
        # 206 Partial Content Response
        r = urllib.addinfourl(fp, hdrs, req.get_full_url())
        r.code = code
        r.msg = msg
        return r 
Example 68
Project: root-2015-tasks   Author: yandex   File: byterange.py    GNU General Public License v3.0 5 votes vote down vote up
def open_local_file(self, req):
        import mimetypes
        import mimetools
        host = req.get_host()
        file = req.get_selector()
        localfile = urllib.url2pathname(file)
        stats = os.stat(localfile)
        size = stats[stat.ST_SIZE]
        modified = rfc822.formatdate(stats[stat.ST_MTIME])
        mtype = mimetypes.guess_type(file)[0]
        if host:
            host, port = urllib.splitport(host)
            if port or socket.gethostbyname(host) not in self.get_names():
                raise urllib2.URLError('file not on local host')
        fo = open(localfile,'rb')
        brange = req.headers.get('Range',None)
        brange = range_header_to_tuple(brange)
        assert brange != ()
        if brange:
            (fb,lb) = brange
            if lb == '': lb = size
            if fb < 0 or fb > size or lb > size:
                raise RangeError(9, 'Requested Range Not Satisfiable')
            size = (lb - fb)
            fo = RangeableFileObject(fo, (fb,lb))
        headers = mimetools.Message(StringIO(
            'Content-Type: %s\nContent-Length: %d\nLast-modified: %s\n' %
            (mtype or 'text/plain', size, modified)))
        return urllib.addinfourl(fo, headers, 'file:'+file)


# FTP Range Support 
# Unfortunately, a large amount of base FTP code had to be copied
# from urllib and urllib2 in order to insert the FTP REST command.
# Code modifications for range support have been commented as 
# follows:
# -- range support modifications start/end here 
Example 69
Project: root-2015-tasks   Author: yandex   File: grabber.py    GNU General Public License v3.0 5 votes vote down vote up
def geturl(self):
        """ Provide the geturl() method, used to be got from
            urllib.addinfourl, via. urllib.URLopener.* """
        return self.url 
Example 70
Project: Antidote-DM   Author: AntidoteLabs   File: compat.py    GNU General Public License v2.0 5 votes vote down vote up
def data_open(self, req):
            # data URLs as specified in RFC 2397.
            #
            # ignores POSTed data
            #
            # syntax:
            # dataurl   := "data:" [ mediatype ] [ ";base64" ] "," data
            # mediatype := [ type "/" subtype ] *( ";" parameter )
            # data      := *urlchar
            # parameter := attribute "=" value
            url = req.get_full_url()

            scheme, data = url.split(":", 1)
            mediatype, data = data.split(",", 1)

            # even base64 encoded data URLs might be quoted so unquote in any case:
            data = compat_urllib_parse_unquote_to_bytes(data)
            if mediatype.endswith(";base64"):
                data = binascii.a2b_base64(data)
                mediatype = mediatype[:-7]

            if not mediatype:
                mediatype = "text/plain;charset=US-ASCII"

            headers = email.message_from_string(
                "Content-type: %s\nContent-length: %d\n" % (mediatype, len(data)))

            return compat_urllib_response.addinfourl(io.BytesIO(data), headers, url) 
Example 71
Project: Kodi_addons   Author: dvatterott   File: plugintools.py    GNU General Public License v3.0 5 votes vote down vote up
def http_error_302(self, req, fp, code, msg, headers):
        infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        infourl.status = code
        infourl.code = code
        return infourl 
Example 72
Project: pelisalacarta-ce   Author: pelisalacarta-ce   File: httptools.py    GNU General Public License v3.0 5 votes vote down vote up
def http_error_302(self, req, fp, code, msg, headers):
        infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        infourl.status = code
        infourl.code = code
        return infourl 
Example 73
Project: pelisalacarta-ce   Author: pelisalacarta-ce   File: plugintools.py    GNU General Public License v3.0 5 votes vote down vote up
def http_error_302(self, req, fp, code, msg, headers):
        infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        infourl.status = code
        infourl.code = code
        return infourl 
Example 74
Project: filmkodi   Author: mrknow   File: tvnplayer.py    Apache License 2.0 5 votes vote down vote up
def http_error_302(self, req, fp, code, msg, headers):
        infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        infourl.status = code
        infourl.code = code
        return infourl