Package screenlets :: Package plugins :: Module Proxy

[hide private]
[frames] | no frames]

# Source Code for Module screenlets.plugins.Proxy

     1  # This application is released under the GNU General Public License
     2  # v3 (or, at your option, any later version). You can find the full
     3  # text of the license under http://www.gnu.org/licenses/gpl.txt.
     4  # By using, editing and/or distributing this software you agree to
     5  # the terms and conditions of this license.
     6  # Thank you for using free softwa
     7
     8  # proxy module by Helder Fraga aka whise <helder.fraga@hotmail.com>
     9
    10  import gconf
    11
    12
    13 -class Proxy:
    14
    15 -        def __init__(self):
    16                  try:
    17                          self.gconf_client = gconf.client_get_default()
    18                          self.gconf_client.notify_add("/system/http_proxy/use_http_proxy", self.get_is_active)
    19                          self.gconf_client.notify_add("/system/http_proxy/port", self.get_port)
    20                          self.gconf_client.notify_add("/system/http_proxy/host", self.get_host)
    21                  except:pass
    22                  self.get_is_active()
    23                  self.get_port()
    24                  self.get_host()
    25
    26 -        def get_is_active (self):
    27                  """Returns if the proxy gnome settings are enabled, shoulnt be used separatly"""
    28                  try:
    29                          a = bool(self.gconf_client.get_bool("/system/http_proxy/use_http_proxy"))
    30                          return a
    31                  except:
    32                          return None
    33 -        def get_port (self):
    34                  """Returns the proxy gnome settings port, shoulnt be used separatly"""
    35                  try:
    36                          a = self.gconf_client.get_int("/system/http_proxy/port")
    37                          return a
    38                  except:
    39                          return None
    40 -        def get_host (self):
    41                  """Returns the proxy gnome settings host, shoulnt be used separatly"""
    42                  try:
    43                          a = self.gconf_client.get_string("/system/http_proxy/host")
    44                          return a
    45                  except:
    46                          return None
    47
    48 -        def get_proxy(self):
    49                  """Return {'http' : HOST:PORT } if available or {} if not"""
    50                  try:
    51                          proxy = {}
    52                          if self.get_is_active():
    53                                  a = self.get_host()
    54                                  b = self.get_port()
    55                                  if a != None and b != None:
    56                                          c = str(a) + ':' + str(b)
    57                                          if c.find ('http://') == -1: c = 'http://' + c
    58                                          proxy['http'] = c
    59                                          return proxy
    60
    61                          else: return proxy
    62                  except:
    63                          return {}
    64