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 (since those storage devices have a lifetime based on the number
of writes.) Default is '5'. 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
======= =======
Twitter is the most famous micro-blogging website and the original 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__`` :class:`NetworkData`, inheriting from it, with its own ``__init__``
and setting the properties. 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 Mixing It All
============= =============

38
mitterlib/network/__init__.py

@ -83,6 +83,7 @@ class Networks(object):
self._networks = {} self._networks = {}
self._options = options self._options = options
self._operations = 0 self._operations = 0
self._proxy_handler = None
self.options() self.options()
@property @property
@ -130,6 +131,26 @@ class Networks(object):
_log.debug('Config file saved') _log.debug('Config file saved')
return 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): def settings(self):
"""Return a dictionary with the options that the interfaces need to """Return a dictionary with the options that the interfaces need to
setup.""" setup."""
@ -162,6 +183,15 @@ class Networks(object):
type='int', type='int',
metavar='SECONDS', metavar='SECONDS',
default=120) 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( self._options.add_option(
group='NetworkManager', group='NetworkManager',
option='save_count', option='save_count',
@ -187,6 +217,7 @@ class Networks(object):
def messages(self, network=None): def messages(self, network=None):
"""Return a list of NetworkData objects for the main "timeline" (the """Return a list of NetworkData objects for the main "timeline" (the
default list presented to the user.)""" default list presented to the user.)"""
self._proxy()
result = [] result = []
for shortcut in self._targets(network): for shortcut in self._targets(network):
for message in self.networks[shortcut].messages(): for message in self.networks[shortcut].messages():
@ -201,6 +232,7 @@ class Networks(object):
def update(self, status, reply_to=None, network=None): def update(self, status, reply_to=None, network=None):
"""Update the user status. Must return the id for the new status.""" """Update the user status. Must return the id for the new status."""
self._proxy()
if reply_to and isinstance(reply_to, NetworkData): if reply_to and isinstance(reply_to, NetworkData):
# If you pass a NetworkData object, we get the proper network # If you pass a NetworkData object, we get the proper network
network = reply_to.network network = reply_to.network
@ -215,12 +247,14 @@ class Networks(object):
def reply_prefix(self, message): def reply_prefix(self, message):
"""Return the prefix to be used in the reply for that message.""" """Return the prefix to be used in the reply for that message."""
assert(isinstance(message, NetworkData)) assert(isinstance(message, NetworkData))
self._proxy()
return self.networks[message.network].reply_prefix(message) return self.networks[message.network].reply_prefix(message)
def repost(self, message): def repost(self, message):
"""Repost a message in the user's timeline. The network used is """Repost a message in the user's timeline. The network used is
the same in the message.""" the same in the message."""
assert(isinstance(message, NetworkData)) assert(isinstance(message, NetworkData))
self._proxy()
self.networks[message.network].repost(message) self.networks[message.network].repost(message)
self._operations += 1 self._operations += 1
self._save() self._save()
@ -229,6 +263,7 @@ class Networks(object):
def favourite(self, message): def favourite(self, message):
"""Change the favourite status of the message.""" """Change the favourite status of the message."""
assert(isinstance(message, NetworkData)) assert(isinstance(message, NetworkData))
self._proxy()
self.networks[message.network].favourite(message) self.networks[message.network].favourite(message)
self._operations += 1 self._operations += 1
self._save() self._save()
@ -241,6 +276,7 @@ class Networks(object):
if isinstance(message, NetworkData): if isinstance(message, NetworkData):
network = message.network network = message.network
self._proxy()
self.networks[network].delete_message(message) self.networks[network].delete_message(message)
self._operations += 1 self._operations += 1
self._save() self._save()
@ -253,6 +289,7 @@ class Networks(object):
if not network in self.networks: if not network in self.networks:
raise NetworksNoSuchNetworkError(network) raise NetworksNoSuchNetworkError(network)
self._proxy()
data = self.networks[network].message(message_id) data = self.networks[network].message(message_id)
data.network = network data.network = network
self._operations += 1 self._operations += 1
@ -268,6 +305,7 @@ class Networks(object):
"""Return a list of NetworkData objects for the replies for the user """Return a list of NetworkData objects for the replies for the user
messages.""" messages."""
result = [] result = []
self._proxy()
for shortcut in self._targets(network): for shortcut in self._targets(network):
for message in self.networks[shortcut].replies(): for message in self.networks[shortcut].replies():
message.network = shortcut message.network = shortcut

15
mitterlib/ui/ui_pygtk.py

@ -1022,7 +1022,7 @@ class Interface(object):
self._options[self.NAMESPACE]['refresh_interval']) self._options[self.NAMESPACE]['refresh_interval'])
self._refresh_interval_field.set_increments(1, 5) 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):')), interface_box.attach(gtk.Label(_('Refresh interval (minutes):')),
0, 1, 0, 1) 0, 1, 0, 1)
interface_box.attach(self._refresh_interval_field, 0, 1, 1, 2) 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'))) 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 # We store the fields in a dictionary, inside dictionaries for each
# NAMESPACE. To set the values, we just run the dictionaries setting # NAMESPACE. To set the values, we just run the dictionaries setting
# self._options. # self._options.

Loading…
Cancel
Save