Example #1
0
 def __init__(self,user=None,passwd=None):
     AURLOpener.__init__(self,user,passwd)
     self.session = HTTPSession(debug_level=0)
     self.session.add_header('User-Agent',
                             'Mozilla/4.0 (compatible; Windows; Linux)')
     if self.user and self.passwd:
         self.session.set_basic_auth(self.user,self.passwd)
     self.log = get_logger()
Example #2
0
class CookieAURLOpener(AURLOpener):
    def __init__(self,user=None,passwd=None):
        AURLOpener.__init__(self,user,passwd)
        self.session = HTTPSession(debug_level=0)
        self.session.add_header('User-Agent',
                                'Mozilla/4.0 (compatible; Windows; Linux)')
        if self.user and self.passwd:
            self.session.set_basic_auth(self.user,self.passwd)
        self.log = get_logger()

    def urlopen(self,url,data=None,method='get',referer=None):
        self.log.debug('urlopen: %s\n' % url)
        scheme = urlparse(url)[0]
        if not scheme in ['http','https']:
            return urllib2.urlopen(url,data)
        if method == 'post':
            req = self.session.post(url)
        else:
            req = self.session.get(url)

        if not referer:
            referer = url
        if referer:
            req.add_header('Referer',referer)

        if data:
            params = urldecode(data)
            req.add_params(params)
        rc,msg,hdr = req.getreply()
        fd = req.getfile()
        return addinfourl(fd,hdr,req.url)