|
|
|
@ -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 |
|
|
|
|