Python urllib.FancyURLopener() Examples

The following are code examples for showing how to use urllib.FancyURLopener(). 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: ebookpoint-promocja   Author: maciejszewczyk   File: ebp.py    BSD 2-Clause "Simplified" License 6 votes vote down vote up
def downloadXML():
	import urllib

	XML_URL = 'http://ebookpoint.pl/plugins/new/xml/lista.cgi'
	dlFile = 'ebookpoint_ebooks.xml'

	opener = urllib.FancyURLopener()
	try:
		f = opener.open(XML_URL)
	except IOError:
		print 'Failed to open "%s"' % XML_URL
	else:
		print 'Downloading XML from %s' % XML_URL
		outputFile = open(dlFile, "wb")
		while True:
			data = f.read(8192)
			if not data:
				print 'Done'
				break
			print('.'),
			outputFile.write(data)
		f.close( )
		outputFile.close( ) 
Example 2
Project: service.subtitles.tusubtitulocom   Author: k3lebra   File: TuSubtituloCom_Parse.py    GNU General Public License v2.0 6 votes vote down vote up
def getUrl(self,url):
		class AppURLopener(urllib.FancyURLopener):
			version = "App/1.7"
			def __init__(self, *args):
				urllib.FancyURLopener.__init__(self, *args)
			def add_referrer(self, url=None):
				if url:
					urllib._urlopener.addheader('Referer', url)

		urllib._urlopener = AppURLopener()
		urllib._urlopener.add_referrer("http://www.tusubtitulo.com/")
		try:
			response = urllib._urlopener.open(url)
			content    = response.read()
		except:
			content    = None
		return content 
Example 3
Project: service.subtitles.tusubtitulocom   Author: k3lebra   File: TuSubtituloCom.py    GNU General Public License v2.0 6 votes vote down vote up
def getUrl(self,url):
		class AppURLopener(urllib.FancyURLopener):
			version = "App/1.7"
			def __init__(self, *args):
				urllib.FancyURLopener.__init__(self, *args)
			def add_referrer(self, url=None):
				if url:
					urllib._urlopener.addheader('Referer', url)

		urllib._urlopener = AppURLopener()
		urllib._urlopener.add_referrer("http://www.tusubtitulo.com/")
		try:
			response = urllib._urlopener.open(url)
			content    = response.read()
		except:
			content    = None
		return content 
Example 4
Project: d4rkc0de   Author: knightmare2600   File: ProxyHarvest.py    GNU General Public License v2.0 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 
Example 5
Project: darkc0de-old-stuff   Author: tuwid   File: ProxyHarvest.py    GNU General Public License v3.0 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 
Example 6
Project: pyblish-win   Author: pyblish   File: webchecker.py    GNU Lesser General Public License v3.0 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 7
Project: pyblish-win   Author: pyblish   File: robotparser.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def __init__(self, *args):
        urllib.FancyURLopener.__init__(self, *args)
        self.errcode = 200 
Example 8
Project: pyblish-win   Author: pyblish   File: robotparser.py    GNU Lesser General Public License v3.0 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 9
Project: pyblish-win   Author: pyblish   File: test_urllibnet.py    GNU Lesser General Public License v3.0 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 10
Project: identify_playstation2_games   Author: workhorsy   File: iso9660.py    MIT License 5 votes vote down vote up
def _get_sector_url(self, sector, length):
        start = sector * SECTOR_SIZE
        if self._buff:
            self._buff.close()
        opener = urllib.FancyURLopener()
        opener.http_error_206 = lambda *a, **k: None
        opener.addheader(b"Range", b"bytes={0}-{1}".format(start, start+length-1))
        self._buff = opener.open(self._url) 
Example 11
Project: mathlibs-tester   Author: miroi   File: update.py    MIT License 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 12
Project: dockerizeme   Author: dockerizeme   File: snippet.py    Apache License 2.0 5 votes vote down vote up
def download_from(url):
	print("get content from " + url)
	opener = urllib.FancyURLopener({})
	f = opener.open(url)
	return f.read() 
Example 13
Project: Dreamcast   Author: abveost   File: iso9660.py    GNU General Public License v3.0 5 votes vote down vote up
def _get_sector_url(self, sector, length):
        start = sector * 2048
        if self._buff:
            self._buff.close()
        opener = urllib.FancyURLopener()
        opener.http_error_206 = lambda *a, **k: None
        opener.addheader("Range", "bytes=%d-%d" % (start, start+length-1))
        self._buff = opener.open(self._url) 
Example 14
Project: ironpython2   Author: IronLanguages   File: robotparser.py    Apache License 2.0 5 votes vote down vote up
def __init__(self, *args):
        urllib.FancyURLopener.__init__(self, *args)
        self.errcode = 200 
Example 15
Project: ironpython2   Author: IronLanguages   File: robotparser.py    Apache License 2.0 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 16
Project: ironpython2   Author: IronLanguages   File: test_urllibnet.py    Apache License 2.0 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 17
Project: ironpython2   Author: IronLanguages   File: test_urllib.py    Apache License 2.0 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 18
Project: flanders   Author: bast   File: update.py    Mozilla Public License 2.0 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 19
Project: IronHydra   Author: microdee   File: robotparser.py    MIT License 5 votes vote down vote up
def __init__(self, *args):
        urllib.FancyURLopener.__init__(self, *args)
        self.errcode = 200 
Example 20
Project: IronHydra   Author: microdee   File: robotparser.py    MIT License 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 21
Project: Computable   Author: ktraunmueller   File: robotparser.py    MIT License 5 votes vote down vote up
def __init__(self, *args):
        urllib.FancyURLopener.__init__(self, *args)
        self.errcode = 200 
Example 22
Project: Computable   Author: ktraunmueller   File: robotparser.py    MIT License 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: oss-ftp   Author: aliyun   File: webchecker.py    MIT License 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 24
Project: oss-ftp   Author: aliyun   File: robotparser.py    MIT License 5 votes vote down vote up
def __init__(self, *args):
        urllib.FancyURLopener.__init__(self, *args)
        self.errcode = 200 
Example 25
Project: oss-ftp   Author: aliyun   File: robotparser.py    MIT License 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 26
Project: oss-ftp   Author: aliyun   File: test_urllibnet.py    MIT License 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 27
Project: bandit-ss   Author: zeroSteiner   File: urlopen.py    Apache License 2.0 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 28
Project: identify_playstation1_games   Author: WorkhorsyTest   File: iso9660.py    MIT License 5 votes vote down vote up
def _get_sector_url(self, sector, length):
        start = sector * SECTOR_SIZE
        if self._buff:
            self._buff.close()
        opener = urllib.FancyURLopener()
        opener.http_error_206 = lambda *a, **k: None
        opener.addheader(b"Range", b"bytes={0}-{1}".format(start, start+length-1))
        self._buff = opener.open(self._url) 
Example 29
Project: godot-zeronet-plugin   Author: zam-org   File: robotparser.py    GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, *args):
        urllib.FancyURLopener.__init__(self, *args)
        self.errcode = 200 
Example 30
Project: godot-zeronet-plugin   Author: zam-org   File: robotparser.py    GNU General Public License v2.0 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 31
Project: godot-zeronet-plugin   Author: zam-org   File: robotparser.py    GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, *args):
        urllib.FancyURLopener.__init__(self, *args)
        self.errcode = 200 
Example 32
Project: godot-zeronet-plugin   Author: zam-org   File: robotparser.py    GNU General Public License v2.0 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: godot-zeronet-plugin   Author: zam-org   File: robotparser.py    GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, *args):
        urllib.FancyURLopener.__init__(self, *args)
        self.errcode = 200 
Example 34
Project: godot-zeronet-plugin   Author: zam-org   File: robotparser.py    GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, *args):
        urllib.FancyURLopener.__init__(self, *args)
        self.errcode = 200 
Example 35
Project: godot-zeronet-plugin   Author: zam-org   File: robotparser.py    GNU General Public License v2.0 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 36
Project: godot-zeronet-plugin   Author: zam-org   File: robotparser.py    GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, *args):
        urllib.FancyURLopener.__init__(self, *args)
        self.errcode = 200 
Example 37
Project: godot-zeronet-plugin   Author: zam-org   File: robotparser.py    GNU General Public License v2.0 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 38
Project: eve-metrics   Author: ccpgames   File: AuthorizeNet.py    MIT License 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 39
Project: eve-metrics   Author: ccpgames   File: DowCommerce.py    MIT License 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 40
Project: gimic   Author: qmcurrents   File: update.py    GNU General Public License v2.0 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 41
Project: bandit   Author: PyCQA   File: urlopen.py    Apache License 2.0 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 42
Project: flake8-bandit   Author: tylerwince   File: urlopen.py    MIT License 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 43
Project: spc   Author: whbrewer   File: AuthorizeNet.py    MIT License 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 44
Project: spc   Author: whbrewer   File: DowCommerce.py    MIT License 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 45
Project: KalutClient   Author: TwoUnderscorez   File: robotparser.py    Apache License 2.0 5 votes vote down vote up
def __init__(self, *args):
        urllib.FancyURLopener.__init__(self, *args)
        self.errcode = 200 
Example 46
Project: KalutClient   Author: TwoUnderscorez   File: robotparser.py    Apache License 2.0 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 47
Project: Plex-CS   Author: zobe123   File: classes.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, user, pw):
        self.username = user
        self.password = pw

        # remember if we've tried the username/password before
        self.numTries = 0

        # call the base class
        urllib.FancyURLopener.__init__(self) 
Example 48
Project: kinect-2-libras   Author: inessadl   File: robotparser.py    Apache License 2.0 5 votes vote down vote up
def __init__(self, *args):
        urllib.FancyURLopener.__init__(self, *args)
        self.errcode = 200 
Example 49
Project: kinect-2-libras   Author: inessadl   File: robotparser.py    Apache License 2.0 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 50
Project: Savethemblobs_app   Author: iApeiron   File: robotparser.py    MIT License 5 votes vote down vote up
def __init__(self, *args):
        urllib.FancyURLopener.__init__(self, *args)
        self.errcode = 200 
Example 51
Project: Savethemblobs_app   Author: iApeiron   File: robotparser.py    MIT License 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 52
Project: SoCDep2   Author: siavooshpayandehazad   File: Benchmark_Alg_Downloader.py    GNU General Public License v2.0 5 votes vote down vote up
def download_benchmark_algorithms(Benchmark):
    testfile = urllib.FancyURLopener()

    if Benchmark == 'idct':     # Inverse Discrete Cosine Transform
        url = "http://express.ece.ucsb.edu/benchmark/jpeg/jpeg_idct_ifast_dfg__6.dot"
        DestinationFile = 'Benchmarks/idct.dot'

    elif Benchmark == 'fdct':   # Forward Discrete Cosine Transform
        url = "http://express.ece.ucsb.edu/benchmark/jpeg/jpeg_fdct_islow_dfg__6.dot"
        DestinationFile = 'Benchmarks/fdct.dot'
    elif Benchmark == 'mi':     # Matrix Inverse
        url = "http://express.ece.ucsb.edu/benchmark/mesa/invert_matrix_general_dfg__3.dot"
        DestinationFile = 'Benchmarks/mi.dot'
    else:
        print("THIS BENCHMARK IS NOT SUPPORTED...")
        return False

    if not os.path.isfile(DestinationFile):
        code = urllib.urlopen(url).code
        if code/100 >= 4:
            print("BENCHMARK IS NOT AVAILABLE...")
            return False
        else:
            print("DOWNLOADING BENCHMARK...")
            testfile.retrieve(url, DestinationFile)
            print("FINISHED DOWNLOADING...")
            Config.tg.dot_file_path = DestinationFile
            Config.tg.type = 'FromDOTFile'
            return True
    else:
        print("FILE ALREADY EXISTS...")
        Config.tg.dot_file_path = DestinationFile
        Config.tg.type = 'FromDOTFile'
        return True 
Example 53
Project: Wallet   Author: superbitcoin   File: robotparser.py    MIT License 5 votes vote down vote up
def __init__(self, *args):
        urllib.FancyURLopener.__init__(self, *args)
        self.errcode = 200 
Example 54
Project: Wallet   Author: superbitcoin   File: robotparser.py    MIT License 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 55
Project: Hot   Author: dsolimando   File: robotparser.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, *args):
        urllib.FancyURLopener.__init__(self, *args)
        self.errcode = 200 
Example 56
Project: Hot   Author: dsolimando   File: robotparser.py    GNU General Public License v3.0 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 57
Project: linux-cross-gcc   Author: nmercier   File: robotparser.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self, *args):
        urllib.FancyURLopener.__init__(self, *args)
        self.errcode = 200 
Example 58
Project: linux-cross-gcc   Author: nmercier   File: robotparser.py    BSD 3-Clause "New" or "Revised" License 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 59
Project: linux-cross-gcc   Author: nmercier   File: robotparser.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self, *args):
        urllib.FancyURLopener.__init__(self, *args)
        self.errcode = 200 
Example 60
Project: linux-cross-gcc   Author: nmercier   File: robotparser.py    BSD 3-Clause "New" or "Revised" License 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 61
Project: service.subtitles.tusubtitulocom   Author: k3lebra   File: service.py    GNU General Public License v2.0 5 votes vote down vote up
def download(self,link,filename,referer):
		subtitle_list = []

		if link:
				downloadlink = link
				self.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', referer)
				postparams = None
				
				
				self.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:
						self.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)
						self.log(__name__, "=== returning subtitle file %s" % file)

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

		return subtitle_list 
Example 62
Project: d4rkc0de   Author: knightmare2600   File: proxytest.py    GNU General Public License v2.0 5 votes vote down vote up
def main(proxy):
	
	try:# make a http HEAD request
		proxies = {'http': "http://"+proxy[:-1]}
		opener = urllib.FancyURLopener(proxies)
		opener.open("http://www.python.org")
		print "\t[+] Alive"
	except(IOError), msg: 
		if verbose == 1:
			print "\t[-] Error:",msg
		pass 
Example 63
Project: d4rkc0de   Author: knightmare2600   File: proxybot.py    GNU General Public License v2.0 5 votes vote down vote up
def proxtest(proxy):
	socket.setdefaulttimeout(5) #Set proxy timeout here
	proxies = {'http': "http://"+proxy}
	opener = urllib.FancyURLopener(proxies)
	opener.open("http://www.google.com") 
Example 64
Project: scrimmage-scoreboard   Author: ShySec   File: AuthorizeNet.py    GNU General Public License v2.0 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 65
Project: scrimmage-scoreboard   Author: ShySec   File: DowCommerce.py    GNU General Public License v2.0 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 66
Project: charm-helpers   Author: juju   File: utils.py    Apache License 2.0 5 votes vote down vote up
def create_cirros_image(self, glance, image_name, hypervisor_type=None):
        """Download the latest cirros image and upload it to glance,
        validate and return a resource pointer.

        :param glance: pointer to authenticated glance connection
        :param image_name: display name for new image
        :param hypervisor_type: glance image hypervisor property
        :returns: glance image pointer
        """
        # /!\ DEPRECATION WARNING
        self.log.warn('/!\\ DEPRECATION WARNING:  use '
                      'glance_create_image instead of '
                      'create_cirros_image.')

        self.log.debug('Creating glance cirros image '
                       '({})...'.format(image_name))

        # Get cirros image URL
        http_proxy = os.getenv('OS_TEST_HTTP_PROXY')
        self.log.debug('OS_TEST_HTTP_PROXY: {}'.format(http_proxy))
        if http_proxy:
            proxies = {'http': http_proxy}
            opener = urllib.FancyURLopener(proxies)
        else:
            opener = urllib.FancyURLopener()

        f = opener.open('http://download.cirros-cloud.net/version/released')
        version = f.read().strip()
        cirros_img = 'cirros-{}-x86_64-disk.img'.format(version)
        cirros_url = 'http://{}/{}/{}'.format('download.cirros-cloud.net',
                                              version, cirros_img)
        f.close()

        return self.glance_create_image(
            glance,
            image_name,
            cirros_url,
            hypervisor_type=hypervisor_type) 
Example 67
Project: kkFileView   Author: kekingcn   File: robotparser.py    Apache License 2.0 5 votes vote down vote up
def __init__(self, *args):
        urllib.FancyURLopener.__init__(self, *args)
        self.errcode = 200 
Example 68
Project: kkFileView   Author: kekingcn   File: robotparser.py    Apache License 2.0 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 69
Project: Splunking-Crime   Author: nccgroup   File: robotparser.py    GNU Affero General Public License v3.0 5 votes vote down vote up
def __init__(self, *args):
        urllib.FancyURLopener.__init__(self, *args)
        self.errcode = 200 
Example 70
Project: Splunking-Crime   Author: nccgroup   File: robotparser.py    GNU Affero General Public License v3.0 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 71
Project: SpoilerSeason   Author: dev-id   File: spoilers.py    MIT License 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 72
Project: senior-design   Author: james-tate   File: robotparser.py    GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, *args):
        urllib.FancyURLopener.__init__(self, *args)
        self.errcode = 200 
Example 73
Project: senior-design   Author: james-tate   File: robotparser.py    GNU General Public License v2.0 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 74
Project: addrest   Author: JBrVJxsc   File: AuthorizeNet.py    MIT License 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 75
Project: addrest   Author: JBrVJxsc   File: DowCommerce.py    MIT License 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 76
Project: homework-arch-4   Author: 51reboot   File: downloadfilesThreadings.py    Apache License 2.0 5 votes vote down vote up
def __init__(self,threadname,url,filename,ranges):
        Thread.__init__(self,name=threadname)
        urllib.FancyURLopener.__init__(self)
        self.name = threadname
        self.url = url
        self.filename = filename
        self.ranges = ranges
        self.downloaded = 0 
Example 77
Project: homework-arch-4   Author: 51reboot   File: doubanSpider.py    Apache License 2.0 5 votes vote down vote up
def urlProxies(self,url):
        proxylist = (
            '211.167.112.14:80',
            '210.32.34.115:8080',
            '115.47.8.39:80',
            '211.151.181.41:80',
            '219.239.26.23:80',                         
        )
        for proxy in proxylist:
            proxies = {'': proxy}
            opener = urllib.FancyURLopener(proxies)
            f = opener.open(url)
            return f
    #定义打印信息 
Example 78
Project: opentracing-python-instrumentation   Author: uber-common   File: urllib.py    MIT License 4 votes vote down vote up
def install_patches():
    if six.PY3:
        # The old urllib does not exist in Py3, so delegate to urllib2 patcher
        from . import urllib2
        urllib2.install_patches()
        return

    import urllib
    import urlparse

    log.info('Instrumenting urllib methods for tracing')

    class TracedURLOpener(urllib.FancyURLopener):

        def open(self, fullurl, data=None):
            parsed_url = urlparse.urlparse(fullurl)
            host = parsed_url.hostname or None
            port = parsed_url.port or None

            span = utils.start_child_span(
                operation_name='urllib', parent=current_span_func())

            span.set_tag(ext_tags.SPAN_KIND, ext_tags.SPAN_KIND_RPC_CLIENT)

            # use span as context manager so that its finish() method is called
            with span:
                span.set_tag(ext_tags.HTTP_URL, fullurl)
                if host:
                    span.set_tag(ext_tags.PEER_HOST_IPV4, host)
                if port:
                    span.set_tag(ext_tags.PEER_PORT, port)
                # TODO add callee service name
                # TODO add headers to propagate trace
                # cannot use super here, this is an old style class
                fileobj = urllib.FancyURLopener.open(self, fullurl, data)
                if fileobj.getcode() is not None:
                    span.set_tag(ext_tags.HTTP_STATUS_CODE, fileobj.getcode())

            return fileobj

        def retrieve(self, url, filename=None, reporthook=None, data=None):
            raise NotImplementedError

    urllib._urlopener = TracedURLOpener()