Esempio n. 1
0
    def CreateLayout(self, name, frame):
        """create a bunch of widgets that look like a prefs panel."""

        #
        # Set up some frames
        proxy_frame = Frame(frame)
        manual_frame = Frame(proxy_frame)
        manual_right_frame = Frame(manual_frame)
        manual_left_frame = Frame(manual_frame)
        no_proxy_frame = Frame(proxy_frame)

        #
        # Establish some booleans to represent the button states
        self.no_proxy_enabled = IntVar(frame)
        self.manual_proxy_enabled = IntVar(frame)

        #
        # Create top level widgets
        l = Label(proxy_frame, pady=15,
               text="A proxy allows your browser to access the Internet through a Firewall.")

        self.no = Checkbutton(proxy_frame,
               text="Proxy Exceptions List            ",
               variable=self.no_proxy_enabled,
               padx=200, pady=15,
               font='-*-helvetica-bold-o-normal-*-*-120-*-*-*-*-*-*' ,
               command=self.no_switch)
        manual = Checkbutton(proxy_frame,
               text="Manual Proxy Configuration ",
               variable=self.manual_proxy_enabled,
               padx=200, pady=15,
               font='-*-helvetica-bold-o-normal-*-*-120-*-*-*-*-*-*',
               command=self.manual_switch)
        
        self.he = Entry(manual_right_frame, relief=SUNKEN, width=38)
        self.hl = Label(manual_left_frame, relief=FLAT,
               text="HTTP Proxy (http://server:port):")
        self.fe = Entry(manual_right_frame, relief=SUNKEN, width=38)
        self.fl = Label(manual_left_frame, relief=FLAT,
               text=" FTP Proxy (http://server:port):",)

        self.nl = Label(no_proxy_frame, relief=FLAT,
               text="Servers that need no proxy to be reached (www.python.org, .dlib.org):",)
        self.ne = Entry(no_proxy_frame, relief=SUNKEN, width=75)

        #
        # Pack the widgets
        frame.pack(expand=1, fill=X)
        proxy_frame.pack(expand=1, fill=X)
        l.pack(side=TOP)
        manual.pack(side=TOP, expand=1, anchor=CENTER, fill=X)
        manual_frame.pack(side=TOP, expand=1, fill=X)
        self.no.pack(side=TOP, expand=1, anchor=CENTER, fill=X)
        no_proxy_frame.pack(side=TOP, expand=1, fill=X)
        manual_right_frame.pack(side=RIGHT, expand=1, fill=X)
        manual_left_frame.pack(side=LEFT, expand=1, fill=X)
        self.nl.pack(side=TOP, expand=1, fill=X)
        self.ne.pack(side=BOTTOM, expand=1, fill=X)
        self.he.pack(side=TOP, expand=1, fill=X)
        self.hl.pack(side=TOP, expand=1, fill=X)
        self.fe.pack(side=TOP, expand=1, fill=X)
        self.fl.pack(side=TOP, expand=1, fill=X)

        #
        # Set the initial GUI state based on prefs
        self.register_prefs_UI()
        manual_proxy_enabled = grailutil.pref_or_getenv('manual_proxy_enabled',
                                                        type_name='int')
        if manual_proxy_enabled == 1:
            self.manual_proxy_enabled.set(1)
        else:
            self.manual_proxy_enabled.set(0)
        no_proxy_enabled = grailutil.pref_or_getenv('no_proxy_enabled', type_name='int')
        if no_proxy_enabled == 1:
            self.no_proxy_enabled.set(1)
        else:
            self.no_proxy_enabled.set(0)
        self.UpdateLayout()
Esempio n. 2
0
def protocol_access(url, mode, params, data=None):
    scheme, resturl = splittype(url)
    if not scheme:
        raise IOError, ("protocol error", "no scheme identifier in URL", url)
    scheme = string.lower(scheme)
    sanitized = regsub.gsub("[^a-zA-Z0-9]", "_", scheme)
    #
    # Check first to see if proxies are enabled
    manual_proxy_enabled = grailutil.pref_or_getenv('manual_proxy_enabled',
                                                    type_name='int')

    app = grailutil.get_grailapp()
    if manual_proxy_enabled:
        proxy_name = sanitized + "_proxy"
        if manual_proxy_enabled == -1:
            #
            # We should only get here when there are no user preferences
            # for proxies, which should only happen once... so check the
            # environment for the rest of the known scheme proxy env vars
            # and load them into prefs if they exist.
            app.prefs.Set('proxies', 'manual_proxy_enabled', 0)
            proxy = None
            for next_proxy_name in VALID_PROXIES:
                next_proxy = grailutil.pref_or_getenv(next_proxy_name,
                                                      check_ok=VALID_PROXIES)
                if next_proxy:
                    app.prefs.Set('proxies', 'manual_proxy_enabled', 1)

                if next_proxy_name == proxy_name:
                    proxy = next_proxy

            no_proxy_enabled = grailutil.pref_or_getenv('no_proxy_enabled',
                                                        type_name='int')
            if no_proxy_enabled == -1:
                no_proxy = grailutil.pref_or_getenv('no_proxy')
            if no_proxy:
                app.prefs.Set('proxies', 'no_proxy_enabled', 1)
            else:
                app.prefs.Set('proxies', 'no_proxy_enabled', 0)
        else:
            proxy = grailutil.pref_or_getenv(proxy_name,
                                             check_ok=VALID_PROXIES)
    else:
        proxy = None

    if proxy:
        if not valid_proxy(proxy):
            error = 'Invalid proxy: ' + proxy
            raise IOError, error
        no_proxy_enabled = grailutil.pref_or_getenv('no_proxy_enabled',
                                                    type_name='int')
        if no_proxy_enabled:
            no_proxy = grailutil.pref_or_getenv('no_proxy')
        else:
            no_proxy = None

        do_proxy = 1
        if no_proxy:
            list = map(string.strip, string.split(no_proxy, ","))
            url_host, url_remains = splithost(resturl)
            url_host = string.lower(url_host or '')
            if proxy_exception(url_host, list):
                do_proxy = 0
            else:
                url_host, url_port = splitport(url_host)
                if proxy_exception(url_host, list):
                    do_proxy = 0
        if do_proxy:
            proxy_scheme, proxy_resturl = splittype(proxy)
            proxy_host, proxy_remains = splithost(proxy_resturl)
            resturl = (proxy_host, url)
            scheme = string.lower(proxy_scheme)
            sanitized = regsub.gsub("[^a-zA-Z0-9]", "_", scheme)


##          print "Sending", url
##          print "     to", scheme, "proxy", proxy_host
    modname = sanitized + "API"
    app = grailutil.get_grailapp()
    access = app.find_extension('protocols', sanitized).access
    if not access:
        raise IOError, ("protocol error", "no class for %s" % scheme)
    try:
        if data:
            return access(resturl, mode, params, data)
        else:
            return access(resturl, mode, params)
    except socket.error, msg:
        raise IOError, ("socket error", msg)
Esempio n. 3
0
def protocol_access(url, mode, params, data=None):
    scheme, resturl = splittype(url)
    if not scheme:
        raise IOError, ("protocol error", "no scheme identifier in URL", url)
    scheme = string.lower(scheme)
    sanitized = re.sub("[^a-zA-Z0-9]", "_", scheme)
    #
    # Check first to see if proxies are enabled
    manual_proxy_enabled = grailutil.pref_or_getenv('manual_proxy_enabled',
                                                    type_name='int')

    app = grailutil.get_grailapp()
    if manual_proxy_enabled:
        proxy_name = sanitized + "_proxy"
        if manual_proxy_enabled == -1:
            #
            # We should only get here when there are no user preferences
            # for proxies, which should only happen once... so check the
            # environment for the rest of the known scheme proxy env vars
            # and load them into prefs if they exist.
            app.prefs.Set('proxies', 'manual_proxy_enabled', 0)
            proxy = None
            for next_proxy_name in VALID_PROXIES:
                next_proxy = grailutil.pref_or_getenv(next_proxy_name,
                                              check_ok=VALID_PROXIES)
                if next_proxy:
                    app.prefs.Set('proxies', 'manual_proxy_enabled', 1)
                    
                if next_proxy_name == proxy_name:
                    proxy = next_proxy
                    
            no_proxy_enabled = grailutil.pref_or_getenv('no_proxy_enabled',
                                                        type_name='int')
            if no_proxy_enabled == -1:
                no_proxy = grailutil.pref_or_getenv('no_proxy')
            if no_proxy:
                app.prefs.Set('proxies', 'no_proxy_enabled', 1)
            else:
                app.prefs.Set('proxies', 'no_proxy_enabled', 0)
        else:   
            proxy = grailutil.pref_or_getenv(proxy_name,
                                             check_ok=VALID_PROXIES)
    else:
        proxy = None
        
    if proxy:
        if not valid_proxy(proxy):
            error = 'Invalid proxy: ' + proxy
            raise IOError, error
        no_proxy_enabled = grailutil.pref_or_getenv('no_proxy_enabled',
                                                    type_name='int')
        if no_proxy_enabled:
            no_proxy = grailutil.pref_or_getenv('no_proxy')
        else:
            no_proxy = None
            
        do_proxy = 1
        if no_proxy:
            list = map(string.strip, string.split(no_proxy, ","))
            url_host, url_remains = splithost(resturl)
            url_host = string.lower(url_host or '')
            if proxy_exception(url_host, list):
                do_proxy = 0
            else:
                url_host, url_port = splitport(url_host)
                if proxy_exception(url_host, list):
                    do_proxy = 0
        if do_proxy:
            proxy_scheme, proxy_resturl = splittype(proxy)
            proxy_host, proxy_remains = splithost(proxy_resturl)
            resturl = (proxy_host, url)
            scheme = string.lower(proxy_scheme)
            sanitized = re.sub("[^a-zA-Z0-9]", "_", scheme)
##          print "Sending", url
##          print "     to", scheme, "proxy", proxy_host
    modname = sanitized + "API"
    app = grailutil.get_grailapp()
    ext = app.find_extension('protocols', sanitized)
    if ext:
        access = ext.access
    else:
        access = None
    if not access:
        raise IOError, ("protocol error", "no class for %s" % scheme)
    try:
        if data:
            return access(resturl, mode, params, data)
        else:
            return access(resturl, mode, params)
    except socket.error, msg:
        raise IOError, ("socket error", msg)
Esempio n. 4
0
    def CreateLayout(self, name, frame):
        """create a bunch of widgets that look like a prefs panel."""

        #
        # Set up some frames
        proxy_frame = Frame(frame)
        manual_frame = Frame(proxy_frame)
        manual_right_frame = Frame(manual_frame)
        manual_left_frame = Frame(manual_frame)
        no_proxy_frame = Frame(proxy_frame)

        #
        # Establish some booleans to represent the button states
        self.no_proxy_enabled = IntVar(frame)
        self.manual_proxy_enabled = IntVar(frame)

        #
        # Create top level widgets
        l = Label(proxy_frame, pady=15,
               text="A proxy allows your browser to access the Internet through a Firewall.")

        self.no = Checkbutton(proxy_frame,
               text="Proxy Exceptions List            ",
               variable=self.no_proxy_enabled,
               padx=200, pady=15,
               font='-*-helvetica-bold-o-normal-*-*-120-*-*-*-*-*-*' ,
               command=self.no_switch)
        manual = Checkbutton(proxy_frame,
               text="Manual Proxy Configuration ",
               variable=self.manual_proxy_enabled,
               padx=200, pady=15,
               font='-*-helvetica-bold-o-normal-*-*-120-*-*-*-*-*-*',
               command=self.manual_switch)
        
        self.he = Entry(manual_right_frame, relief=SUNKEN, width=38)
        self.hl = Label(manual_left_frame, relief=FLAT,
               text="HTTP Proxy (http://server:port):")
        self.fe = Entry(manual_right_frame, relief=SUNKEN, width=38)
        self.fl = Label(manual_left_frame, relief=FLAT,
               text=" FTP Proxy (http://server:port):",)

        self.nl = Label(no_proxy_frame, relief=FLAT,
               text="Servers that need no proxy to be reached (www.python.org, .dlib.org):",)
        self.ne = Entry(no_proxy_frame, relief=SUNKEN, width=75)

        #
        # Pack the widgets
        frame.pack(expand=1, fill=X)
        proxy_frame.pack(expand=1, fill=X)
        l.pack(side=TOP)
        manual.pack(side=TOP, expand=1, anchor=CENTER, fill=X)
        manual_frame.pack(side=TOP, expand=1, fill=X)
        self.no.pack(side=TOP, expand=1, anchor=CENTER, fill=X)
        no_proxy_frame.pack(side=TOP, expand=1, fill=X)
        manual_right_frame.pack(side=RIGHT, expand=1, fill=X)
        manual_left_frame.pack(side=LEFT, expand=1, fill=X)
        self.nl.pack(side=TOP, expand=1, fill=X)
        self.ne.pack(side=BOTTOM, expand=1, fill=X)
        self.he.pack(side=TOP, expand=1, fill=X)
        self.hl.pack(side=TOP, expand=1, fill=X)
        self.fe.pack(side=TOP, expand=1, fill=X)
        self.fl.pack(side=TOP, expand=1, fill=X)

        #
        # Set the initial GUI state based on prefs
        self.register_prefs_UI()
        manual_proxy_enabled = grailutil.pref_or_getenv('manual_proxy_enabled',
                                                        type_name='int')
        if manual_proxy_enabled == 1:
            self.manual_proxy_enabled.set(1)
        else:
            self.manual_proxy_enabled.set(0)
        no_proxy_enabled = grailutil.pref_or_getenv('no_proxy_enabled', type_name='int')
        if no_proxy_enabled == 1:
            self.no_proxy_enabled.set(1)
        else:
            self.no_proxy_enabled.set(0)
        self.UpdateLayout()