Example #1
0
 def check_proxy_settings(proxy_settings, dialog):
     if proxy_settings.config == 'None':
         return True
     try:
         proxies, _ = get_proxies_for_handler(proxy_settings)
         proxy_handler = get_proxy_handler(proxies)
         if proxy_handler.proxies:
             # System or manual proxy set, try a GET on test URL
             opener = urllib2.build_opener(proxy_handler)
             protocol = proxy_handler.proxies.iterkeys().next()
             test_url = protocol + '://' + PROXY_TEST_HOST
             opener.open(urllib2.Request(test_url))
         return True
     except socket.timeout:
         return handle_error(timeout_msg, dialog, tab_index=1, debug=True)
     except urllib2.HTTPError as e:
         msg = "HTTP error %d" % e.code
         if hasattr(e, 'msg'):
             msg = msg + ": " + e.msg
         return handle_error(msg, dialog, tab_index=1, debug=True)
     except Exception as e:
         if hasattr(e, 'msg'):
             msg = e.msg
         else:
             msg = "Unable to connect to proxy server."
         return handle_error(msg, dialog, tab_index=1, debug=True)
Example #2
0
 def check_proxy_settings(proxy_settings, dialog):
     if proxy_settings.config == 'None':
         return True
     try:
         proxies, _ = get_proxies_for_handler(proxy_settings)
         proxy_handler = get_proxy_handler(proxies)
         if proxy_handler.proxies:
             # System or manual proxy set, try a GET on test URL
             opener = urllib2.build_opener(proxy_handler)
             protocol = proxy_handler.proxies.iterkeys().next()
             test_url = protocol + '://' + PROXY_TEST_HOST
             opener.open(urllib2.Request(test_url))
         return True
     except socket.timeout:
         return handle_error(timeout_msg, dialog, tab_index=2)
     except urllib2.HTTPError as e:
         msg = "HTTP error %d" % e.code
         if hasattr(e, 'msg'):
             msg = msg + ": " + e.msg
         return handle_error(msg, dialog, tab_index=2)
     except Exception as e:
         if hasattr(e, 'msg'):
             msg = e.msg
         else:
             msg = "Unable to connect to proxy server."
         return handle_error(msg, dialog, tab_index=2)
Example #3
0
 def _connect_startup_page(self, server_url):
     url = server_url + DRIVE_STARTUP_PAGE
     try:
         proxy_handler = get_proxy_handler(self._manager.get_proxies())
         opener = urllib2.build_opener(proxy_handler)
         log.debug(
             'Proxy configuration for startup page connection: %s, effective proxy list: %r',
             self._manager.get_proxy_settings().config,
             get_opener_proxies(opener))
         headers = {
             'X-Application-Name':
             self._manager.get_appname(),
             'X-Device-Id':
             self._manager.get_device_id(),
             'X-Client-Version':
             self._manager.get_version(),
             'User-Agent':
             self._manager.get_appname() + "/" +
             self._manager.get_version(),
         }
         req = urllib2.Request(url, headers=headers)
         response = opener.open(req,
                                timeout=STARTUP_PAGE_CONNECTION_TIMEOUT)
         status = response.getcode()
     except urllib2.HTTPError as e:
         status = e.code
     except:
         log.exception(
             'Error while trying to connect to Nuxeo Drive startup page with URL %s',
             url)
         raise StartupPageConnectionError()
     log.debug('Status code for %s = %d', url, status)
     return status
Example #4
0
    def _connect_startup_page(self, server_url):
        # Take into account URL parameters
        parts = urlparse.urlsplit(guess_server_url(server_url))
        url = urlparse.urlunsplit((parts.scheme, parts.netloc,
                                   parts.path + '/' + Options.startup_page,
                                   parts.query, parts.fragment))

        # Remove any parameters from the original URL
        server_url = urlparse.urlunsplit(
            (parts.scheme, parts.netloc, parts.path, '', parts.fragment))

        try:
            proxy_handler = get_proxy_handler(
                self._manager.get_proxies(server_url))
            opener = urllib2.build_opener(proxy_handler)
            log.debug(
                'Proxy configuration for startup page connection: %s,'
                ' effective proxy list: %r',
                self._manager.get_proxy_settings().config,
                get_opener_proxies(opener))
            headers = {
                'X-Application-Name':
                self._manager.app_name,
                'X-Device-Id':
                self._manager.device_id,
                'X-Client-Version':
                self._manager.get_version(),
                'User-Agent':
                (self._manager.app_name + '/' + self._manager.get_version()),
            }
            req = urllib2.Request(url, headers=headers)
            response = opener.open(req,
                                   timeout=STARTUP_PAGE_CONNECTION_TIMEOUT)
            status = response.getcode()
        except urllib2.HTTPError as e:
            status = e.code
        except:
            log.exception(
                'Error while trying to connect to Nuxeo Drive'
                ' startup page with URL %s', url)
            raise StartupPageConnectionError()
        log.debug('Status code for %s = %d', url, status)
        return status
 def check_proxy_settings(proxy_settings, dialog):
     if proxy_settings.config == 'None':
         return True
     try:
         proxies, _ = get_proxies_for_handler(proxy_settings)
         proxy_handler = get_proxy_handler(proxies)
         opener = urllib2.build_opener(proxy_handler)
         opener.open(urllib2.Request(PROXY_TEST_URL))
         return True
     except socket.timeout:
         return handle_error(timeout_msg, dialog, tab_index=1, debug=True)
     except urllib2.HTTPError as e:
         msg = "HTTP error %d" % e.code
         if hasattr(e, 'msg'):
             msg = msg + ": " + e.msg
         return handle_error(msg, dialog, tab_index=1, debug=True)
     except Exception as e:
         if hasattr(e, 'msg'):
             msg = e.msg
         else:
             msg = "Unable to connect to proxy server."
         return handle_error(msg, dialog, tab_index=1, debug=True)
Example #6
0
    def _connect_startup_page(self, server_url):
        # Take into account URL parameters
        parts = urlparse.urlsplit(guess_server_url(server_url))
        url = urlparse.urlunsplit((parts.scheme,
                                   parts.netloc,
                                   parts.path + '/' + Options.startup_page,
                                   parts.query,
                                   parts.fragment))

        # Remove any parameters from the original URL
        server_url = urlparse.urlunsplit(
            (parts.scheme, parts.netloc, parts.path, '', parts.fragment))

        try:
            proxy_handler = get_proxy_handler(
                self._manager.get_proxies(server_url))
            opener = urllib2.build_opener(proxy_handler)
            log.debug('Proxy configuration for startup page connection: %s,'
                      ' effective proxy list: %r',
                      self._manager.get_proxy_settings().config,
                      get_opener_proxies(opener))
            headers = {
                'X-Application-Name': self._manager.app_name,
                'X-Device-Id': self._manager.device_id,
                'X-Client-Version': self._manager.get_version(),
                'User-Agent': (self._manager.app_name
                               + '/' + self._manager.get_version()),
            }
            req = urllib2.Request(url, headers=headers)
            response = opener.open(req, timeout=STARTUP_PAGE_CONNECTION_TIMEOUT)
            status = response.getcode()
        except urllib2.HTTPError as e:
            status = e.code
        except:
            log.exception('Error while trying to connect to Nuxeo Drive'
                          ' startup page with URL %s', url)
            raise StartupPageConnectionError()
        log.debug('Status code for %s = %d', url, status)
        return status
Example #7
0
 def _connect_startup_page(self, server_url):
     url = server_url + DRIVE_STARTUP_PAGE
     try:
         proxy_handler = get_proxy_handler(self._manager.get_proxies())
         opener = urllib2.build_opener(proxy_handler)
         log.debug('Proxy configuration for startup page connection: %s, effective proxy list: %r',
                   self._manager.get_proxy_settings().config, get_opener_proxies(opener))
         headers = {
             'X-Application-Name': self._manager.get_appname(),
             'X-Device-Id': self._manager.get_device_id(),
             'X-Client-Version': self._manager.get_version(),
             'User-Agent': self._manager.get_appname() + "/" + self._manager.get_version(),
         }
         req = urllib2.Request(url, headers=headers)
         response = opener.open(req, timeout=STARTUP_PAGE_CONNECTION_TIMEOUT)
         status = response.getcode()
     except urllib2.HTTPError as e:
         status = e.code
     except:
         log.exception('Error while trying to connect to Nuxeo Drive startup page with URL %s', url)
         raise StartupPageConnectionError()
     log.debug('Status code for %s = %d', url, status)
     return status
Example #8
0
    def __init__(self, server_url, user_id, device_id, client_version,
                 password=None, token=None, timeout=20, cookie_jar=None,
                 proxies=None, proxy_exceptions=None):

        if not server_url.endswith('/'):
            server_url += '/'
        self.rest_api_url = server_url + 'api/v1/'
        self.server_url = server_url
        self.user_id = user_id
        self.device_id = device_id
        self.client_version = client_version
        self.timeout = timeout
        self._update_auth(password=password, token=token)

        # Build URL opener
        self.cookie_jar = cookie_jar
        cookie_processor = urllib2.HTTPCookieProcessor(
            cookiejar=cookie_jar)
        # Get proxy handler
        proxy_handler = get_proxy_handler(proxies,
                                          proxy_exceptions=proxy_exceptions,
                                          url=self.server_url)
        self.opener = urllib2.build_opener(cookie_processor, proxy_handler)