Python urllib.FancyURLopener() Examples

The following are code examples for showing how to use urllib.FancyURLopener(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the ones you don't like. You can also save this page to your account.

Example 1
Project: HeaTDV4A   Author: HeaTTheatR   File: setcookie.py    (license) View Source Project 6 votes vote down vote up
def get_cookie(site, params, agent):
        """
        type params: list;
        param params: post-??????;

        """

        post = urllib.urlencode(params)
        cookie = None

        try:
            urlopener = urllib.FancyURLopener()
            urlopener.addheaders = [("User-agent", agent)]
            cookie = urlopener.open(site, post).info()["Set-Cookie"].split()
        except Exception:
            return False

        return cookie 
Example 2
Project: HeaTDV4A   Author: HeaTTheatR   File: getcookie.py    (license) View Source Project 6 votes vote down vote up
def get_cookie(site, params, agent):
    """
    type site: str
    param site: ?????? ?? ???????? ????? ?? ????

    type params: list
    param params: post-??????

    type agent: str
    param agent: ?????????? ?? ??????

    """

    post = urllib.urlencode(params)

    try:
        urlopener = urllib.FancyURLopener()
        urlopener.addheaders = [("User-agent", agent)]
        cookie = urlopener.open(site, post).info()["Set-Cookie"].split()
    except Exception:
        return False

    return cookie 
Example 3
Project: darkc0de-old-stuff   Author: tuwid   File: ProxyHarvest.py    (GNU General Public License v3.0) View Source Project 6 votes vote down vote up
def proxyvalidator(proxylist):
        finalcount = 0
	for proxy in proxylist:
		proxy.replace('\n', '')
		try:
			proxies = {'http': "http://"+proxy[:-1]}
			opener = urllib.FancyURLopener(proxies)
			try:
				loopchk = opener.open("http://www.google.com").read()
			except:
				pass
		except(IOError,socket.timeout), detail: 
			pass
		ipcheck(proxy)		
		alivelist.append(proxy)
		finalcount += 1
	return alivelist 
Example 4
Project: kinect-2-libras   Author: inessadl   File: robotparser.py    (Apache License 2.0) View Source Project 5 votes vote down vote up
def __init__(self, *args):
        urllib.FancyURLopener.__init__(self, *args)
        self.errcode = 200 
Example 5
Project: kinect-2-libras   Author: inessadl   File: robotparser.py    (Apache License 2.0) View Source Project 5 votes vote down vote up
def http_error_default(self, url, fp, errcode, errmsg, headers):
        self.errcode = errcode
        return urllib.FancyURLopener.http_error_default(self, url, fp, errcode,
                                                        errmsg, headers) 
Example 6
Project: anita   Author: gson1703   File: anita.py    (ISC License) View Source Project 5 votes vote down vote up
def expect(self, pattern, *args, **kwargs):
        print >>self.structured_log_f, "expect(" + repr(pattern) + ")"
        r = pexpect.spawn.expect(self, pattern, *args, **kwargs)
        print >>self.structured_log_f, "match(" + repr(self.match.group(0)) + ")"
        return r

# Subclass urllib.FancyURLopener so that we can catch
# HTTP 404 errors 
Example 7
Project: code   Author: ActiveState   File: recipe-224043.py    (MIT License) View Source Project 5 votes vote down vote up
def open_file(self, url):
        path = urllib.url2pathname(urllib.unquote(url))
        if os.path.isdir(path):
            if path[-1] != os.sep:
                url = url + '/'
            indexpath = os.path.join(path, "index.html")
            if os.path.exists(indexpath):
                return self.open_file(url + "index.html")
            try:
                names = os.listdir(path)
            except os.error, msg:
                raise IOError, msg, sys.exc_traceback
            names.sort()
            s = MyStringIO("file:"+url, {'content-type': 'text/html'})
            s.write('<BASE HREF="file:%s">\n' %
                    urllib.quote(os.path.join(path, "")))
            for name in names:
                q = urllib.quote(name)
                s.write('<A HREF="%s">%s</A>\n' % (q, q))
            s.seek(0)
            return s
        return urllib.FancyURLopener.open_file(self, url) 
Example 8
Project: hostapd-mana   Author: adde88   File: robotparser.py    (license) View Source Project 5 votes vote down vote up
def __init__(self, *args):
        urllib.FancyURLopener.__init__(self, *args)
        self.errcode = 200 
Example 9
Project: hostapd-mana   Author: adde88   File: robotparser.py    (license) View Source Project 5 votes vote down vote up
def http_error_default(self, url, fp, errcode, errmsg, headers):
        self.errcode = errcode
        return urllib.FancyURLopener.http_error_default(self, url, fp, errcode,
                                                        errmsg, headers) 
Example 10
Project: service.subtitles.tusubtitulo   Author: josecurioso2   File: service.py    (license) View Source Project 5 votes vote down vote up
def Download(link, filename):
    subtitle_list = []
    exts = [".srt", ".sub", ".txt", ".smi", ".ssa", ".ass"]

    if link:
        downloadlink = link
        log(__name__, "Downloadlink %s" % link)

        class MyOpener(urllib.FancyURLopener):
            version = "User-Agent=Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 ( .NET CLR 3.5.30729)"

        my_urlopener = MyOpener()
        my_urlopener.addheader('Referer', link)
        postparams = None
        
        
        log(__name__, "Fetching subtitles using url '%s' with referer header '%s' and post parameters '%s'" % (link, link, postparams))
        response = my_urlopener.open(link, postparams)
        local_tmp_file = os.path.join(__temp__, "sub.srt")
        
        if xbmcvfs.exists(__temp__):
            shutil.rmtree(__temp__)
        xbmcvfs.mkdirs(__temp__)
        try:
            log(__name__, "Saving subtitles to '%s'" % local_tmp_file)
            local_file_handle = open(local_tmp_file, "wb")
            local_file_handle.write(response.read())
            local_file_handle.close()
            
            subtitle_list.append(local_tmp_file)
            log(__name__, "=== returning subtitle file %s" % file)

        except:
            log(__name__, "Failed to save subtitle to %s" % local_tmp_file)

    return subtitle_list 
Example 11
Project: seq2seq   Author: eske   File: wsclient.py    (license) View Source Project 5 votes vote down vote up
def wsopen(self, url, post, **params):
                noparam = params.pop('noparam',False)
                if noparam:
                        params = {}
                else:
                        if self.user is not None:
                                params['user'] = self.user
                        if self.password is not None:
                                params.pop('hmac', None)
                                HMAC=hmac.new(self.password)
                                for k,v in sorted(params.items()):
                                        HMAC.update("%s=%s" % (k,v))
                                params.update({'hmac':HMAC.hexdigest()})
                query = urllib.urlencode(params)
                if post:
                        body = query
                elif query:
                        url = "{}?{}".format(url, query)

                if self.debug:
                        if post:
                                print("POST:\n{}\n{!r}\n".format(url, body), file=sys.stderr)
                        else:
                                print("GET:\n{}\n".format(url), file=sys.stderr)

                class URLopener(urllib.FancyURLopener):
                        def http_error_default(self, url, fp, errcode, errmsg, headers):
                                return urllib.addinfourl(fp, headers, "http:" + url, errcode)
                try:
                        urllib._urlopener = URLopener()
                        if post:
                                resp = urllib.urlopen(url, body)
                        else:
                                resp = urllib.urlopen(url)
                except IOError as e:
                        raise WSError(url, msg=e)
                if self.debug:
                        print("RESPONSE:\n{}\n{}".format(resp.getcode(), resp.info()), file=sys.stderr)
                if resp.getcode() != 200:
                        raise WSError(url, resp.getcode(), resp.read())
                return resp 
Example 12
Project: touch-pay-client   Author: HackPucBemobi   File: AuthorizeNet.py    (license) View Source Project 5 votes vote down vote up
def process(self):
        encoded_args = urllib.urlencode(self.parameters)
        if self.testmode == True:
            url = 'https://test.authorize.net/gateway/transact.dll'
        else:
            url = 'https://secure.authorize.net/gateway/transact.dll'

        if self.proxy is None:
            self.results += str(urllib.urlopen(
                url, encoded_args).read()).split(self.delimiter)
        else:
            opener = urllib.FancyURLopener(self.proxy)
            opened = opener.open(url, encoded_args)
            try:
                self.results += str(opened.read()).split(self.delimiter)
            finally:
                opened.close()
        Results = namedtuple('Results', 'ResultResponse ResponseSubcode ResponseCode ResponseText AuthCode \
                                          AVSResponse TransactionID InvoiceNumber Description Amount PaymentMethod \
                                          TransactionType CustomerID CHFirstName CHLastName Company BillingAddress \
                                          BillingCity BillingState BillingZip BillingCountry Phone Fax Email ShippingFirstName \
                                          ShippingLastName ShippingCompany ShippingAddress ShippingCity ShippingState \
                                          ShippingZip ShippingCountry TaxAmount DutyAmount FreightAmount TaxExemptFlag \
                                          PONumber MD5Hash CVVResponse CAVVResponse')
        self.response = Results(*tuple(r for r in self.results)[0:40])

        if self.getResultResponseFull() == 'Approved':
            self.error = False
            self.success = True
            self.declined = False
        elif self.getResultResponseFull() == 'Declined':
            self.error = False
            self.success = False
            self.declined = True
        else:
            raise AIM.AIMError(self.response.ResponseText) 
Example 13
Project: touch-pay-client   Author: HackPucBemobi   File: DowCommerce.py    (license) View Source Project 5 votes vote down vote up
def process(self):
        encoded_args = urllib.urlencode(self.parameters)
        if self.proxy is None:
            results = str(urllib.urlopen(
                self.url, encoded_args).read()).split(self.delimiter)
        else:
            opener = urllib.FancyURLopener(self.proxy)
            opened = opener.open(self.url, encoded_args)
            try:
                results = str(opened.read()).split(self.delimiter)
            finally:
                opened.close()

        for result in results:
            (key, val) = result.split('=')
            self.results[key] = val

        if self.results['response'] == '1':
            self.error = False
            self.success = True
            self.declined = False
        elif self.results['response'] == '2':
            self.error = False
            self.success = False
            self.declined = True
        elif self.results['response'] == '3':
            self.error = True
            self.success = False
            self.declined = False
        else:
            self.error = True
            self.success = False
            self.declined = False
            raise DowCommerce.DowCommerceError(self.results) 
Example 14
Project: flanders   Author: bast   File: update.py    (license) View Source Project 5 votes vote down vote up
def fetch_url(src, dst):
    """
    Fetch file from URL src and save it to dst.
    """
    # we do not use the nicer sys.version_info.major
    # for compatibility with Python < 2.7
    if sys.version_info[0] > 2:
        import urllib.request

        class URLopener(urllib.request.FancyURLopener):
            def http_error_default(self, url, fp, errcode, errmsg, headers):
                sys.stderr.write("ERROR: could not fetch {0}\n".format(url))
                sys.exit(-1)
    else:
        import urllib

        class URLopener(urllib.FancyURLopener):
            def http_error_default(self, url, fp, errcode, errmsg, headers):
                sys.stderr.write("ERROR: could not fetch {0}\n".format(url))
                sys.exit(-1)

    dirname = os.path.dirname(dst)
    if dirname != '':
        if not os.path.isdir(dirname):
            os.makedirs(dirname)

    opener = URLopener()
    opener.retrieve(src, dst) 
Example 15
Project: true_review_web2py   Author: lucadealfaro   File: AuthorizeNet.py    (license) View Source Project 5 votes vote down vote up
def process(self):
        encoded_args = urllib.urlencode(self.parameters)
        if self.testmode == True:
            url = 'https://test.authorize.net/gateway/transact.dll'
        else:
            url = 'https://secure.authorize.net/gateway/transact.dll'

        if self.proxy is None:
            self.results += str(urllib.urlopen(
                url, encoded_args).read()).split(self.delimiter)
        else:
            opener = urllib.FancyURLopener(self.proxy)
            opened = opener.open(url, encoded_args)
            try:
                self.results += str(opened.read()).split(self.delimiter)
            finally:
                opened.close()
        Results = namedtuple('Results', 'ResultResponse ResponseSubcode ResponseCode ResponseText AuthCode \
                                          AVSResponse TransactionID InvoiceNumber Description Amount PaymentMethod \
                                          TransactionType CustomerID CHFirstName CHLastName Company BillingAddress \
                                          BillingCity BillingState BillingZip BillingCountry Phone Fax Email ShippingFirstName \
                                          ShippingLastName ShippingCompany ShippingAddress ShippingCity ShippingState \
                                          ShippingZip ShippingCountry TaxAmount DutyAmount FreightAmount TaxExemptFlag \
                                          PONumber MD5Hash CVVResponse CAVVResponse')
        self.response = Results(*tuple(r for r in self.results)[0:40])

        if self.getResultResponseFull() == 'Approved':
            self.error = False
            self.success = True
            self.declined = False
        elif self.getResultResponseFull() == 'Declined':
            self.error = False
            self.success = False
            self.declined = True
        else:
            raise AIM.AIMError(self.response.ResponseText) 
Example 16
Project: true_review_web2py   Author: lucadealfaro   File: DowCommerce.py    (license) View Source Project 5 votes vote down vote up
def process(self):
        encoded_args = urllib.urlencode(self.parameters)
        if self.proxy is None:
            results = str(urllib.urlopen(
                self.url, encoded_args).read()).split(self.delimiter)
        else:
            opener = urllib.FancyURLopener(self.proxy)
            opened = opener.open(self.url, encoded_args)
            try:
                results = str(opened.read()).split(self.delimiter)
            finally:
                opened.close()

        for result in results:
            (key, val) = result.split('=')
            self.results[key] = val

        if self.results['response'] == '1':
            self.error = False
            self.success = True
            self.declined = False
        elif self.results['response'] == '2':
            self.error = False
            self.success = False
            self.declined = True
        elif self.results['response'] == '3':
            self.error = True
            self.success = False
            self.declined = False
        else:
            self.error = True
            self.success = False
            self.declined = False
            raise DowCommerce.DowCommerceError(self.results) 
Example 17
Project: spc   Author: whbrewer   File: AuthorizeNet.py    (license) View Source Project 5 votes vote down vote up
def process(self):
        encoded_args = urllib.urlencode(self.parameters)
        if self.testmode == True:
            url = 'https://test.authorize.net/gateway/transact.dll'
        else:
            url = 'https://secure.authorize.net/gateway/transact.dll'

        if self.proxy is None:
            self.results += str(urllib.urlopen(
                url, encoded_args).read()).split(self.delimiter)
        else:
            opener = urllib.FancyURLopener(self.proxy)
            opened = opener.open(url, encoded_args)
            try:
                self.results += str(opened.read()).split(self.delimiter)
            finally:
                opened.close()
        Results = namedtuple('Results', 'ResultResponse ResponseSubcode ResponseCode ResponseText AuthCode \
                                          AVSResponse TransactionID InvoiceNumber Description Amount PaymentMethod \
                                          TransactionType CustomerID CHFirstName CHLastName Company BillingAddress \
                                          BillingCity BillingState BillingZip BillingCountry Phone Fax Email ShippingFirstName \
                                          ShippingLastName ShippingCompany ShippingAddress ShippingCity ShippingState \
                                          ShippingZip ShippingCountry TaxAmount DutyAmount FreightAmount TaxExemptFlag \
                                          PONumber MD5Hash CVVResponse CAVVResponse')
        self.response = Results(*tuple(r for r in self.results)[0:40])

        if self.getResultResponseFull() == 'Approved':
            self.error = False
            self.success = True
            self.declined = False
        elif self.getResultResponseFull() == 'Declined':
            self.error = False
            self.success = False
            self.declined = True
        else:
            raise AIM.AIMError(self.response.ResponseText) 
Example 18
Project: spc   Author: whbrewer   File: DowCommerce.py    (license) View Source Project 5 votes vote down vote up
def process(self):
        encoded_args = urllib.urlencode(self.parameters)
        if self.proxy is None:
            results = str(urllib.urlopen(
                self.url, encoded_args).read()).split(self.delimiter)
        else:
            opener = urllib.FancyURLopener(self.proxy)
            opened = opener.open(self.url, encoded_args)
            try:
                results = str(opened.read()).split(self.delimiter)
            finally:
                opened.close()

        for result in results:
            (key, val) = result.split('=')
            self.results[key] = val

        if self.results['response'] == '1':
            self.error = False
            self.success = True
            self.declined = False
        elif self.results['response'] == '2':
            self.error = False
            self.success = False
            self.declined = True
        elif self.results['response'] == '3':
            self.error = True
            self.success = False
            self.declined = False
        else:
            self.error = True
            self.success = False
            self.declined = False
            raise DowCommerce.DowCommerceError(self.results) 
Example 19
Project: Problematica-public   Author: TechMaz   File: AuthorizeNet.py    (license) View Source Project 5 votes vote down vote up
def process(self):
        encoded_args = urllib.urlencode(self.parameters)
        if self.testmode == True:
            url = 'https://test.authorize.net/gateway/transact.dll'
        else:
            url = 'https://secure.authorize.net/gateway/transact.dll'

        if self.proxy is None:
            self.results += str(urllib.urlopen(
                url, encoded_args).read()).split(self.delimiter)
        else:
            opener = urllib.FancyURLopener(self.proxy)
            opened = opener.open(url, encoded_args)
            try:
                self.results += str(opened.read()).split(self.delimiter)
            finally:
                opened.close()
        Results = namedtuple('Results', 'ResultResponse ResponseSubcode ResponseCode ResponseText AuthCode \
                                          AVSResponse TransactionID InvoiceNumber Description Amount PaymentMethod \
                                          TransactionType CustomerID CHFirstName CHLastName Company BillingAddress \
                                          BillingCity BillingState BillingZip BillingCountry Phone Fax Email ShippingFirstName \
                                          ShippingLastName ShippingCompany ShippingAddress ShippingCity ShippingState \
                                          ShippingZip ShippingCountry TaxAmount DutyAmount FreightAmount TaxExemptFlag \
                                          PONumber MD5Hash CVVResponse CAVVResponse')
        self.response = Results(*tuple(r for r in self.results)[0:40])

        if self.getResultResponseFull() == 'Approved':
            self.error = False
            self.success = True
            self.declined = False
        elif self.getResultResponseFull() == 'Declined':
            self.error = False
            self.success = False
            self.declined = True
        else:
            raise AIM.AIMError(self.response.ResponseText) 
Example 20
Project: Problematica-public   Author: TechMaz   File: DowCommerce.py    (license) View Source Project 5 votes vote down vote up
def process(self):
        encoded_args = urllib.urlencode(self.parameters)
        if self.proxy is None:
            results = str(urllib.urlopen(
                self.url, encoded_args).read()).split(self.delimiter)
        else:
            opener = urllib.FancyURLopener(self.proxy)
            opened = opener.open(self.url, encoded_args)
            try:
                results = str(opened.read()).split(self.delimiter)
            finally:
                opened.close()

        for result in results:
            (key, val) = result.split('=')
            self.results[key] = val

        if self.results['response'] == '1':
            self.error = False
            self.success = True
            self.declined = False
        elif self.results['response'] == '2':
            self.error = False
            self.success = False
            self.declined = True
        elif self.results['response'] == '3':
            self.error = True
            self.success = False
            self.declined = False
        else:
            self.error = True
            self.success = False
            self.declined = False
            raise DowCommerce.DowCommerceError(self.results) 
Example 21
Project: oil   Author: oilshell   File: robotparser.py    (license) View Source Project 5 votes vote down vote up
def __init__(self, *args):
        urllib.FancyURLopener.__init__(self, *args)
        self.errcode = 200 
Example 22
Project: oil   Author: oilshell   File: robotparser.py    (license) View Source Project 5 votes vote down vote up
def http_error_default(self, url, fp, errcode, errmsg, headers):
        self.errcode = errcode
        return urllib.FancyURLopener.http_error_default(self, url, fp, errcode,
                                                        errmsg, headers) 
Example 23
Project: oil   Author: oilshell   File: test_urllib.py    (license) View Source Project 5 votes vote down vote up
def test_redirect_limit_independent(self):
        # Ticket #12923: make sure independent requests each use their
        # own retry limit.
        for i in range(urllib.FancyURLopener().maxtries):
            self.fakehttp(b'''HTTP/1.1 302 Found
Location: file://guidocomputer.athome.com:/python/license
Connection: close
''')
            try:
                self.assertRaises(IOError, urllib.urlopen,
                    "http://something")
            finally:
                self.unfakehttp() 
Example 24
Project: oil   Author: oilshell   File: test_urllibnet.py    (license) View Source Project 5 votes vote down vote up
def test_getcode(self):
        # test getcode() with the fancy opener to get 404 error codes
        URL = "http://www.pythontest.net/XXXinvalidXXX"
        open_url = urllib.FancyURLopener().open(URL)
        try:
            code = open_url.getcode()
        finally:
            open_url.close()
        self.assertEqual(code, 404) 
Example 25
Project: oil   Author: oilshell   File: webchecker.py    (license) View Source Project 5 votes vote down vote up
def __init__(*args):
        self = args[0]
        apply(urllib.FancyURLopener.__init__, args)
        self.addheaders = [
            ('User-agent', 'Python-webchecker/%s' % __version__),
            ] 
Example 26
Project: python2-tracer   Author: extremecoders-re   File: robotparser.py    (license) View Source Project 5 votes vote down vote up
def __init__(self, *args):
        urllib.FancyURLopener.__init__(self, *args)
        self.errcode = 200 
Example 27
Project: python2-tracer   Author: extremecoders-re   File: robotparser.py    (license) View Source Project 5 votes vote down vote up
def http_error_default(self, url, fp, errcode, errmsg, headers):
        self.errcode = errcode
        return urllib.FancyURLopener.http_error_default(self, url, fp, errcode,
                                                        errmsg, headers) 
Example 28
Project: python2-tracer   Author: extremecoders-re   File: test_urllib.py    (license) View Source Project 5 votes vote down vote up
def test_redirect_limit_independent(self):
        # Ticket #12923: make sure independent requests each use their
        # own retry limit.
        for i in range(urllib.FancyURLopener().maxtries):
            self.fakehttp(b'''HTTP/1.1 302 Found
Location: file://guidocomputer.athome.com:/python/license
Connection: close
''')
            try:
                self.assertRaises(IOError, urllib.urlopen,
                    "http://something")
            finally:
                self.unfakehttp() 
Example 29
Project: python2-tracer   Author: extremecoders-re   File: test_urllibnet.py    (license) View Source Project 5 votes vote down vote up
def test_getcode(self):
        # test getcode() with the fancy opener to get 404 error codes
        URL = "http://www.pythontest.net/XXXinvalidXXX"
        open_url = urllib.FancyURLopener().open(URL)
        try:
            code = open_url.getcode()
        finally:
            open_url.close()
        self.assertEqual(code, 404) 
Example 30
Project: python2-tracer   Author: extremecoders-re   File: webchecker.py    (license) View Source Project 5 votes vote down vote up
def __init__(*args):
        self = args[0]
        apply(urllib.FancyURLopener.__init__, args)
        self.addheaders = [
            ('User-agent', 'Python-webchecker/%s' % __version__),
            ] 
Example 31
Project: sslstrip-hsts-openwrt   Author: adde88   File: robotparser.py    (license) View Source Project 5 votes vote down vote up
def __init__(self, *args):
        urllib.FancyURLopener.__init__(self, *args)
        self.errcode = 200 
Example 32
Project: sslstrip-hsts-openwrt   Author: adde88   File: robotparser.py    (license) View Source Project 5 votes vote down vote up
def http_error_default(self, url, fp, errcode, errmsg, headers):
        self.errcode = errcode
        return urllib.FancyURLopener.http_error_default(self, url, fp, errcode,
                                                        errmsg, headers) 
Example 33
Project: bandit-ss   Author: zeroSteiner   File: urlopen.py    (license) View Source Project 5 votes vote down vote up
def test_urlopen():
    # urllib
    url = urllib.quote('file:///bin/ls')
    urllib.urlopen(url, 'blah', 32)
    urllib.urlretrieve('file:///bin/ls', '/bin/ls2')
    opener = urllib.URLopener()
    opener.open('file:///bin/ls')
    opener.retrieve('file:///bin/ls')
    opener = urllib.FancyURLopener()
    opener.open('file:///bin/ls')
    opener.retrieve('file:///bin/ls')

    # urllib2
    handler = urllib2.HTTPBasicAuthHandler()
    handler.add_password(realm='test',
                         uri='http://mysite.com',
                         user='bob')
    opener = urllib2.build_opener(handler)
    urllib2.install_opener(opener)
    urllib2.urlopen('file:///bin/ls')
    urllib2.Request('file:///bin/ls')

    # Python 3
    urllib.request.urlopen('file:///bin/ls')
    urllib.request.urlretrieve('file:///bin/ls', '/bin/ls2')
    opener = urllib.request.URLopener()
    opener.open('file:///bin/ls')
    opener.retrieve('file:///bin/ls')
    opener = urllib.request.FancyURLopener()
    opener.open('file:///bin/ls')
    opener.retrieve('file:///bin/ls')

    # Six
    six.moves.urllib.request.urlopen('file:///bin/ls')
    six.moves.urllib.request.urlretrieve('file:///bin/ls', '/bin/ls2')
    opener = six.moves.urllib.request.URLopener()
    opener.open('file:///bin/ls')
    opener.retrieve('file:///bin/ls')
    opener = six.moves.urllib.request.FancyURLopener()
    opener.open('file:///bin/ls')
    opener.retrieve('file:///bin/ls') 
Example 34
Project: rekall-agent-server   Author: rekall-innovations   File: AuthorizeNet.py    (license) View Source Project 5 votes vote down vote up
def process(self):
        encoded_args = urllib.urlencode(self.parameters)
        if self.testmode == True:
            url = 'https://test.authorize.net/gateway/transact.dll'
        else:
            url = 'https://secure.authorize.net/gateway/transact.dll'

        if self.proxy is None:
            self.results += str(urllib.urlopen(
                url, encoded_args).read()).split(self.delimiter)
        else:
            opener = urllib.FancyURLopener(self.proxy)
            opened = opener.open(url, encoded_args)
            try:
                self.results += str(opened.read()).split(self.delimiter)
            finally:
                opened.close()
        Results = namedtuple('Results', 'ResultResponse ResponseSubcode ResponseCode ResponseText AuthCode \
                                          AVSResponse TransactionID InvoiceNumber Description Amount PaymentMethod \
                                          TransactionType CustomerID CHFirstName CHLastName Company BillingAddress \
                                          BillingCity BillingState BillingZip BillingCountry Phone Fax Email ShippingFirstName \
                                          ShippingLastName ShippingCompany ShippingAddress ShippingCity ShippingState \
                                          ShippingZip ShippingCountry TaxAmount DutyAmount FreightAmount TaxExemptFlag \
                                          PONumber MD5Hash CVVResponse CAVVResponse')
        self.response = Results(*tuple(r for r in self.results)[0:40])

        if self.getResultResponseFull() == 'Approved':
            self.error = False
            self.success = True
            self.declined = False
        elif self.getResultResponseFull() == 'Declined':
            self.error = False
            self.success = False
            self.declined = True
        else:
            raise AIM.AIMError(self.response.ResponseText) 
Example 35
Project: rekall-agent-server   Author: rekall-innovations   File: DowCommerce.py    (license) View Source Project 5 votes vote down vote up
def process(self):
        encoded_args = urllib.urlencode(self.parameters)
        if self.proxy is None:
            results = str(urllib.urlopen(
                self.url, encoded_args).read()).split(self.delimiter)
        else:
            opener = urllib.FancyURLopener(self.proxy)
            opened = opener.open(self.url, encoded_args)
            try:
                results = str(opened.read()).split(self.delimiter)
            finally:
                opened.close()

        for result in results:
            (key, val) = result.split('=')
            self.results[key] = val

        if self.results['response'] == '1':
            self.error = False
            self.success = True
            self.declined = False
        elif self.results['response'] == '2':
            self.error = False
            self.success = False
            self.declined = True
        elif self.results['response'] == '3':
            self.error = True
            self.success = False
            self.declined = False
        else:
            self.error = True
            self.success = False
            self.declined = False
            raise DowCommerce.DowCommerceError(self.results) 
Example 36
Project: website-clone   Author: paperen   File: core.py    (license) View Source Project 5 votes vote down vote up
def __init__(self,d,r):
		self._op = urllib.FancyURLopener({})
		self._domain = d
		self._siteurl = 'http://'+self._domain+'/'
		print self._siteurl
		if  r == None :
			self._root = sys.path[0] + os.path.sep + self._domain.replace('/', os.path.sep).strip(os.path.sep)+os.path.sep
		else :
			self._root = r+os.path.sep
		self.create_dir(self._root,True)

	# ???? & ???? 
Example 37
Project: web3py   Author: web2py   File: authorize_net.py    (license) View Source Project 5 votes vote down vote up
def process(self):
        encoded_args = urllib.urlencode(self.parameters)
        if self.testmode == True:
            url = 'https://test.authorize.net/gateway/transact.dll'
        else:
            url = 'https://secure.authorize.net/gateway/transact.dll'

        if self.proxy is None:
            self.results += str(urllib.urlopen(
                url, encoded_args).read()).split(self.delimiter)
        else:
            opener = urllib.FancyURLopener(self.proxy)
            opened = opener.open(url, encoded_args)
            try:
                self.results += str(opened.read()).split(self.delimiter)
            finally:
                opened.close()
        Results = namedtuple('Results', 'ResultResponse ResponseSubcode ResponseCode ResponseText AuthCode \
                                          AVSResponse TransactionID InvoiceNumber Description Amount PaymentMethod \
                                          TransactionType CustomerID CHFirstName CHLastName Company BillingAddress \
                                          BillingCity BillingState BillingZip BillingCountry Phone Fax Email ShippingFirstName \
                                          ShippingLastName ShippingCompany ShippingAddress ShippingCity ShippingState \
                                          ShippingZip ShippingCountry TaxAmount DutyAmount FreightAmount TaxExemptFlag \
                                          PONumber MD5Hash CVVResponse CAVVResponse')
        self.response = Results(*tuple(r for r in self.results)[0:40])

        if self.getResultResponseFull() == 'Approved':
            self.error = False
            self.success = True
            self.declined = False
        elif self.getResultResponseFull() == 'Declined':
            self.error = False
            self.success = False
            self.declined = True
        else:
            raise AIM.AIMError(self.response.ResponseText) 
Example 38
Project: pefile.pypy   Author: cloudtracer   File: robotparser.py    (license) View Source Project 5 votes vote down vote up
def __init__(self, *args):
        urllib.FancyURLopener.__init__(self, *args)
        self.errcode = 200 
Example 39
Project: pefile.pypy   Author: cloudtracer   File: robotparser.py    (license) View Source Project 5 votes vote down vote up
def http_error_default(self, url, fp, errcode, errmsg, headers):
        self.errcode = errcode
        return urllib.FancyURLopener.http_error_default(self, url, fp, errcode,
                                                        errmsg, headers) 
Example 40
Project: pefile.pypy   Author: cloudtracer   File: test_urllibnet.py    (license) View Source Project 5 votes vote down vote up
def test_getcode(self):
        # test getcode() with the fancy opener to get 404 error codes
        URL = "http://www.example.com/XXXinvalidXXX"
        open_url = urllib.FancyURLopener().open(URL)
        try:
            code = open_url.getcode()
        finally:
            open_url.close()
        self.assertEqual(code, 404) 
Example 41
Project: slugiot-client   Author: slugiot   File: AuthorizeNet.py    (license) View Source Project 5 votes vote down vote up
def process(self):
        encoded_args = urllib.urlencode(self.parameters)
        if self.testmode == True:
            url = 'https://test.authorize.net/gateway/transact.dll'
        else:
            url = 'https://secure.authorize.net/gateway/transact.dll'

        if self.proxy is None:
            self.results += str(urllib.urlopen(
                url, encoded_args).read()).split(self.delimiter)
        else:
            opener = urllib.FancyURLopener(self.proxy)
            opened = opener.open(url, encoded_args)
            try:
                self.results += str(opened.read()).split(self.delimiter)
            finally:
                opened.close()
        Results = namedtuple('Results', 'ResultResponse ResponseSubcode ResponseCode ResponseText AuthCode \
                                          AVSResponse TransactionID InvoiceNumber Description Amount PaymentMethod \
                                          TransactionType CustomerID CHFirstName CHLastName Company BillingAddress \
                                          BillingCity BillingState BillingZip BillingCountry Phone Fax Email ShippingFirstName \
                                          ShippingLastName ShippingCompany ShippingAddress ShippingCity ShippingState \
                                          ShippingZip ShippingCountry TaxAmount DutyAmount FreightAmount TaxExemptFlag \
                                          PONumber MD5Hash CVVResponse CAVVResponse')
        self.response = Results(*tuple(r for r in self.results)[0:40])

        if self.getResultResponseFull() == 'Approved':
            self.error = False
            self.success = True
            self.declined = False
        elif self.getResultResponseFull() == 'Declined':
            self.error = False
            self.success = False
            self.declined = True
        else:
            raise AIM.AIMError(self.response.ResponseText) 
Example 42
Project: slugiot-client   Author: slugiot   File: DowCommerce.py    (license) View Source Project 5 votes vote down vote up
def process(self):
        encoded_args = urllib.urlencode(self.parameters)
        if self.proxy is None:
            results = str(urllib.urlopen(
                self.url, encoded_args).read()).split(self.delimiter)
        else:
            opener = urllib.FancyURLopener(self.proxy)
            opened = opener.open(self.url, encoded_args)
            try:
                results = str(opened.read()).split(self.delimiter)
            finally:
                opened.close()

        for result in results:
            (key, val) = result.split('=')
            self.results[key] = val

        if self.results['response'] == '1':
            self.error = False
            self.success = True
            self.declined = False
        elif self.results['response'] == '2':
            self.error = False
            self.success = False
            self.declined = True
        elif self.results['response'] == '3':
            self.error = True
            self.success = False
            self.declined = False
        else:
            self.error = True
            self.success = False
            self.declined = False
            raise DowCommerce.DowCommerceError(self.results) 
Example 43
Project: ndk-python   Author: gittor   File: robotparser.py    (license) View Source Project 5 votes vote down vote up
def __init__(self, *args):
        urllib.FancyURLopener.__init__(self, *args)
        self.errcode = 200 
Example 44
Project: ndk-python   Author: gittor   File: robotparser.py    (license) View Source Project 5 votes vote down vote up
def http_error_default(self, url, fp, errcode, errmsg, headers):
        self.errcode = errcode
        return urllib.FancyURLopener.http_error_default(self, url, fp, errcode,
                                                        errmsg, headers) 
Example 45
Project: ndk-python   Author: gittor   File: test_urllibnet.py    (license) View Source Project 5 votes vote down vote up
def test_getcode(self):
        # test getcode() with the fancy opener to get 404 error codes
        URL = "http://www.python.org/XXXinvalidXXX"
        open_url = urllib.FancyURLopener().open(URL)
        try:
            code = open_url.getcode()
        finally:
            open_url.close()
        self.assertEqual(code, 404) 
Example 46
Project: SpoilerSeason   Author: dev-id   File: spoilers.py    (license) View Source Project 5 votes vote down vote up
def get_allsets():
    class MyOpener(urllib.FancyURLopener):
        version = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.11) Gecko / 20071127 Firefox / 2.0.0.11'

    opener = MyOpener()
    opener.retrieve('http://mtgjson.com/json/AllSets.json', 'AllSets.pre.json')
    with open('AllSets.pre.json') as data_file:
        AllSets = json.load(data_file)
    return AllSets 
Example 47
Project: empyrion-python-api   Author: huhlig   File: robotparser.py    (license) View Source Project 5 votes vote down vote up
def __init__(self, *args):
        urllib.FancyURLopener.__init__(self, *args)
        self.errcode = 200 
Example 48
Project: empyrion-python-api   Author: huhlig   File: robotparser.py    (license) View Source Project 5 votes vote down vote up
def http_error_default(self, url, fp, errcode, errmsg, headers):
        self.errcode = errcode
        return urllib.FancyURLopener.http_error_default(self, url, fp, errcode,
                                                        errmsg, headers) 
Example 49
Project: StuffShare   Author: StuffShare   File: AuthorizeNet.py    (license) View Source Project 5 votes vote down vote up
def process(self):
        encoded_args = urllib.urlencode(self.parameters)
        if self.testmode == True:
            url = 'https://test.authorize.net/gateway/transact.dll'
        else:
            url = 'https://secure.authorize.net/gateway/transact.dll'

        if self.proxy is None:
            self.results += str(urllib.urlopen(
                url, encoded_args).read()).split(self.delimiter)
        else:
            opener = urllib.FancyURLopener(self.proxy)
            opened = opener.open(url, encoded_args)
            try:
                self.results += str(opened.read()).split(self.delimiter)
            finally:
                opened.close()
        Results = namedtuple('Results', 'ResultResponse ResponseSubcode ResponseCode ResponseText AuthCode \
                                          AVSResponse TransactionID InvoiceNumber Description Amount PaymentMethod \
                                          TransactionType CustomerID CHFirstName CHLastName Company BillingAddress \
                                          BillingCity BillingState BillingZip BillingCountry Phone Fax Email ShippingFirstName \
                                          ShippingLastName ShippingCompany ShippingAddress ShippingCity ShippingState \
                                          ShippingZip ShippingCountry TaxAmount DutyAmount FreightAmount TaxExemptFlag \
                                          PONumber MD5Hash CVVResponse CAVVResponse')
        self.response = Results(*tuple(r for r in self.results)[0:40])

        if self.getResultResponseFull() == 'Approved':
            self.error = False
            self.success = True
            self.declined = False
        elif self.getResultResponseFull() == 'Declined':
            self.error = False
            self.success = False
            self.declined = True
        else:
            raise AIM.AIMError(self.response.ResponseText) 
Example 50
Project: StuffShare   Author: StuffShare   File: DowCommerce.py    (license) View Source Project 5 votes vote down vote up
def process(self):
        encoded_args = urllib.urlencode(self.parameters)
        if self.proxy is None:
            results = str(urllib.urlopen(
                self.url, encoded_args).read()).split(self.delimiter)
        else:
            opener = urllib.FancyURLopener(self.proxy)
            opened = opener.open(self.url, encoded_args)
            try:
                results = str(opened.read()).split(self.delimiter)
            finally:
                opened.close()

        for result in results:
            (key, val) = result.split('=')
            self.results[key] = val

        if self.results['response'] == '1':
            self.error = False
            self.success = True
            self.declined = False
        elif self.results['response'] == '2':
            self.error = False
            self.success = False
            self.declined = True
        elif self.results['response'] == '3':
            self.error = True
            self.success = False
            self.declined = False
        else:
            self.error = True
            self.success = False
            self.declined = False
            raise DowCommerce.DowCommerceError(self.results)