Browse Source

Added proxy support. fixes #97

master
Julio Biason 15 years ago
parent
commit
bcfc045912
  1. 5
      CHEAT-CODES
  2. 7
      HACKING
  3. 38
      mitterlib/network/__init__.py
  4. 15
      mitterlib/ui/ui_pygtk.py

5
CHEAT-CODES

@ -44,6 +44,11 @@ network manager uses the ``NetworkManager`` section:
(since those storage devices have a lifetime based on the number
of writes.) Default is '5'.
*proxy*
The HTTP proxy to be used. Notice that on Windows and OS X systems,
the system wide proxy will be used, so you don't need to worry about
this.
Twitter
=======
Twitter is the most famous micro-blogging website and the original

7
HACKING

@ -112,6 +112,13 @@ worry about each network data. It is wise to create your own
:class:`NetworkData`, inheriting from it, with its own ``__init__``
and setting the properties.
Proxy support
-------------
Mitter supports proxies. Its value is in the configuration manager, in
the ``NetworkManager`` section, ``proxy`` value. The network manager
itself will install a urllib2 proxy handler, so you don't need to
worry about manually installing a handler yourself if you use urllib2.
Mixing It All
=============

38
mitterlib/network/__init__.py

@ -83,6 +83,7 @@ class Networks(object):
self._networks = {}
self._options = options
self._operations = 0
self._proxy_handler = None
self.options()
@property
@ -130,6 +131,26 @@ class Networks(object):
_log.debug('Config file saved')
return
def _proxy(self):
"""Check and install the proxy."""
if not self._options['NetworkManager']['proxy']:
return
if self._proxy_handler:
return
proxy = self._options['NetworkManager']['proxy']
if not '://' in proxy:
proxy = 'http://' + proxy
_log.debug('Installing proxy ' + proxy)
self._proxy_handler = urllib2.ProxyHandler({
'http': proxy,
'https': proxy})
opener = urllib2.build_opener(self._proxy_handler)
urllib2.install_opener(opener)
return
def settings(self):
"""Return a dictionary with the options that the interfaces need to
setup."""
@ -162,6 +183,15 @@ class Networks(object):
type='int',
metavar='SECONDS',
default=120)
self._options.add_option(
'--proxy',
group='NetworkManager',
option='proxy',
help='Proxy server (Note: This is not needed on Windows " \
"and OS X systems as Mitter will use the system " \
"value.)',
metavar='SERVER',
default='')
self._options.add_option(
group='NetworkManager',
option='save_count',
@ -187,6 +217,7 @@ class Networks(object):
def messages(self, network=None):
"""Return a list of NetworkData objects for the main "timeline" (the
default list presented to the user.)"""
self._proxy()
result = []
for shortcut in self._targets(network):
for message in self.networks[shortcut].messages():
@ -201,6 +232,7 @@ class Networks(object):
def update(self, status, reply_to=None, network=None):
"""Update the user status. Must return the id for the new status."""
self._proxy()
if reply_to and isinstance(reply_to, NetworkData):
# If you pass a NetworkData object, we get the proper network
network = reply_to.network
@ -215,12 +247,14 @@ class Networks(object):
def reply_prefix(self, message):
"""Return the prefix to be used in the reply for that message."""
assert(isinstance(message, NetworkData))
self._proxy()
return self.networks[message.network].reply_prefix(message)
def repost(self, message):
"""Repost a message in the user's timeline. The network used is
the same in the message."""
assert(isinstance(message, NetworkData))
self._proxy()
self.networks[message.network].repost(message)
self._operations += 1
self._save()
@ -229,6 +263,7 @@ class Networks(object):
def favourite(self, message):
"""Change the favourite status of the message."""
assert(isinstance(message, NetworkData))
self._proxy()
self.networks[message.network].favourite(message)
self._operations += 1
self._save()
@ -241,6 +276,7 @@ class Networks(object):
if isinstance(message, NetworkData):
network = message.network
self._proxy()
self.networks[network].delete_message(message)
self._operations += 1
self._save()
@ -253,6 +289,7 @@ class Networks(object):
if not network in self.networks:
raise NetworksNoSuchNetworkError(network)
self._proxy()
data = self.networks[network].message(message_id)
data.network = network
self._operations += 1
@ -268,6 +305,7 @@ class Networks(object):
"""Return a list of NetworkData objects for the replies for the user
messages."""
result = []
self._proxy()
for shortcut in self._targets(network):
for message in self.networks[shortcut].replies():
message.network = shortcut

15
mitterlib/ui/ui_pygtk.py

@ -1022,7 +1022,7 @@ class Interface(object):
self._options[self.NAMESPACE]['refresh_interval'])
self._refresh_interval_field.set_increments(1, 5)
interface_box = gtk.Table(rows=1, columns=2, homogeneous=False)
interface_box = gtk.Table(rows=2, columns=1, homogeneous=False)
interface_box.attach(gtk.Label(_('Refresh interval (minutes):')),
0, 1, 0, 1)
interface_box.attach(self._refresh_interval_field, 0, 1, 1, 2)
@ -1030,6 +1030,19 @@ class Interface(object):
tabs.insert_page(interface_box, gtk.Label(_('Interface')))
# second page is the network manager settings
self._proxy_field = gtk.Entry()
if self._options['NetworkManager']['proxy']:
self._proxy_field.set_text(
self._options['NetworkManager']['proxy'])
manager_box = gtk.Table(rows=1, columns=2, homogeneous=False)
manager_box.attach(gtk.Label(_('Proxy:')), 0, 1, 0, 1)
manager_box.attach(self._proxy_field, 0, 1, 1, 2)
manager_box.show_all()
tabs.insert_page(manager_box, gtk.Label(_('Networks')))
# We store the fields in a dictionary, inside dictionaries for each
# NAMESPACE. To set the values, we just run the dictionaries setting
# self._options.

Loading…
Cancel
Save