screenlets.plugins.Proxy

Package screenlets :: Package plugins :: Module Proxy |
[hide private]
[frames] | no frames]

# Source Code for Module screenlets.plugins.Proxy

     1  #
     2  # proxy module by Helder Fraga aka whise <helder.fraga@hotmail.com>
     3  #
     4  # This program is free software: you can redistribute it and/or modify
     5  # it under the terms of the GNU General Public License as published by
     6  # the Free Software Foundation, either version 3 of the License, or
     7  # (at your option) any later version.
     8  #
     9  # This program is distributed in the hope that it will be useful,
    10  # but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  # GNU General Public License for more details.
    13  #
    14  # You should have received a copy of the GNU General Public License
    15  # along with this program.  If not, see <http://www.gnu.org/licenses/>.
    16
    17  import gconf
    18
    19 -class Proxy(object):
    20
    21 -        def __init__(self):
    22                  try:
    23                          self.gconf_client = gconf.client_get_default()
    24                          self.gconf_client.notify_add("/system/http_proxy/use_http_proxy", self.get_is_active)
    25                          self.gconf_client.notify_add("/system/http_proxy/port", self.get_port)
    26                          self.gconf_client.notify_add("/system/http_proxy/host", self.get_host)
    27                  except:pass
    28                  self.get_is_active()
    29                  self.get_port()
    30                  self.get_host()
    31
    32 -        def get_is_active (self):
    33                  """Returns if the proxy gnome settings are enabled, shoulnt be used separatly"""
    34                  try:
    35                          a = bool(self.gconf_client.get_bool("/system/http_proxy/use_http_proxy"))
    36                          return a
    37                  except:
    38                          return None
    39 -        def get_port (self):
    40                  """Returns the proxy gnome settings port, shoulnt be used separatly"""
    41                  try:
    42                          a = self.gconf_client.get_int("/system/http_proxy/port")
    43                          return a
    44                  except:
    45                          return None
    46 -        def get_host (self):
    47                  """Returns the proxy gnome settings host, shoulnt be used separatly"""
    48                  try:
    49                          a = self.gconf_client.get_string("/system/http_proxy/host")
    50                          return a
    51                  except:
    52                          return None
    53
    54 -        def get_proxy(self):
    55                  """Return {'http' : HOST:PORT } if available or {} if not"""
    56                  try:
    57                          proxy = {}
    58                          if self.get_is_active():
    59                                  a = self.get_host()
    60                                  b = self.get_port()
    61                                  if a != None and b != None:
    62                                          c = str(a) + ':' + str(b)
    63                                          if c.find ('http://') == -1: c = 'http://' + c
    64                                          proxy['http'] = c
    65                                          return proxy
    66
    67                          else: return proxy
    68                  except:
    69                          return {}
    70