class BaseRequest(object):
    
    def __init__(self, cookie_file=None):
        self.cookie_file = cookie_file
        self.net = Net()
        if cookie_file:
            self.net.set_cookies(cookie_file)
        self.url = ''
    
    def ErrorDecorator(self, fn):
        '''
            Decorator for web requests
        '''
        def wrap(*args):
            try:
                return fn(*args)
            except ValueError, e:
                print 'Failed to open "%s".' % self.url
                print 'url is invalid'
            
            except IOError, e:
                    #traceback.print_exc(file = sys.stdout)
                    print 'Failed to open "%s".' % self.url
                    if hasattr(e, 'code'):
                        print 'Failed with error code - %s.' % e.code
                    elif hasattr(e, 'reason'):
                        print "The error object has the following 'reason' attribute :", e.reason
                        print "This usually means the server doesn't exist, is down, or we don't have an internet connection."
            return None
Exemplo n.º 2
0
class BaseRequest(object):
    
    def __init__(self, cookie_file=None):
        self.cookie_file = cookie_file
        self.net = Net()
        if cookie_file:
            self.net.set_cookies(cookie_file)
        self.url = ''
    
    def ErrorDecorator(self, fn):
        '''
            Decorator for web requests
        '''
        def wrap(*args):
            try:
                return fn(*args)
            except ValueError, e:
                print 'Failed to open "%s".' % self.url
                print 'url is invalid'
            
            except IOError, e:
                    #traceback.print_exc(file = sys.stdout)
                    print 'Failed to open "%s".' % self.url
                    if hasattr(e, 'code'):
                        print 'Failed with error code - %s.' % e.code
                    elif hasattr(e, 'reason'):
                        print "The error object has the following 'reason' attribute :", e.reason
                        print "This usually means the server doesn't exist, is down, or we don't have an internet connection."
            return None
 def __init__(self, cookie_file=None):
     self.cookie_file = cookie_file
     self.net = Net()
     if cookie_file:
         self.net.set_cookies(cookie_file)
     self.url = ''
Exemplo n.º 4
0
 def __init__(self, cookie_file=None):
     self.cookie_file = cookie_file
     self.net = Net()
     if cookie_file:
         self.net.set_cookies(cookie_file)
     self.url = ''