[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [gettor/master] Deleted extra whitespaces and other formatting (using pep8)
commit db667b37730eb79bb7bea28cfbd9e5b1a7dcfbb5
Author: ilv <ilv@xxxxxxxxxxxxxxxxxxxxxxxx>
Date: Tue Jun 3 00:20:04 2014 -0400
Deleted extra whitespaces and other formatting (using pep8)
---
src/core_demo.py | 3 --
src/gettor.py | 92 ++++++++++++++++++++++++++----------------------------
2 files changed, 44 insertions(+), 51 deletions(-)
diff --git a/src/core_demo.py b/src/core_demo.py
index 19ffd58..3513e46 100644
--- a/src/core_demo.py
+++ b/src/core_demo.py
@@ -14,6 +14,3 @@ except ValueError as e:
print "Value error! " + str(e)
except RuntimeError as e:
print "Internal error! " + str(e)
-
-
-
diff --git a/src/gettor.py b/src/gettor.py
index 573bae7..02f5eb2 100644
--- a/src/gettor.py
+++ b/src/gettor.py
@@ -5,33 +5,32 @@ import logging
class Core:
-
+
"""
Gets links from providers and delivers them to other modules.
-
- Public methods:
+
+ Public methods:
get_links(operating_system, locale)
"""
-
+
def __init__(self):
"""
Initialize a Core object by reading a configuration file.
-
+
Parameters: none
- """
-
+ """
+
# Read configuration file
-
# Dummy info. This should be read from a configuration file.
self.basedir = './providers/'
- self.supported_locales = [ 'en', 'es' ]
- self.supported_os = [ 'windows', 'linux', 'osx' ]
-
+ self.supported_locales = ['en', 'es']
+ self.supported_os = ['windows', 'linux', 'osx']
+
def get_links(self, operating_system, locale):
"""
- Public method to obtain links.
-
+ Public method to obtain links.
+
Checks for supported locales and operating systems. It returns
ValueError if the locale or operating system is not supported.
It raises RuntimeError if something goes wrong while trying
@@ -39,107 +38,104 @@ class Core:
method should be called from the services modules of GetTor
(e.g. SMTP).
"""
-
+
# Log requests
self._log_request(operating_system, locale)
-
+
if locale not in self.supported_locales:
raise ValueError("Locale %s not supported at the moment" % locale)
-
+
if operating_system not in self.supported_os:
- raise ValueError("Operating system %s not supported at the moment"
+ raise ValueError("Operating system %s not supported at the moment"
% operating_system)
-
+
# This could change in the future, let's leave it isolated.
links = self._get_links(operating_system, locale)
-
+
if links is None:
- raise RuntimeError("Something went wrong with GetTor's core")
-
+ raise RuntimeError("Something went wrong with GetTor's core")
+
return links
-
+
def _get_links(self, operating_system, locale):
"""
Private method to obtain the links.
-
- Looks for the links inside each provider file. On success
- returns a string with the links. On failure returns None.
+
+ Looks for the links inside each provider file. On success
+ returns a string with the links. On failure returns None.
This should only be called from get_links() method.
-
+
Parameters:
os: string describing the operating system
locale: string describing the locale
"""
-
+
# There should be a 'providers' directory inside self.basedir
#
# Each .links file begins with a string describing the provider.
# After that, every line should have the following format:
- #
+ #
# operating_system locale link package_signature key_fingerprint
#
- # e.g.
+ # e.g.
#
# Dropbox
# linux en https://foo.bar https://foo.bar.asc 111-222-333-444
# osx es https://bar.baz https://bar.baz.asc 555-666-777-888
#
links = []
-
+
# Look for files ending with .links
p = re.compile('.*\.links$')
-
+
for name in os.listdir(self.basedir):
path = os.path.abspath(os.path.join(self.basedir, name))
if os.path.isfile(path) and p.match(path):
links.append(path)
-
+
# Let's create a dictionary linking each provider with the links
# found for operating_system and locale. This way makes it easy
# to check if no links were found.
providers = {}
-
+
# We trust links have been generated properly
for name in links:
link_file = open(name, 'r')
provider_name = link_file.readline()
-
+
for line in link_file:
words = line.split(' ')
if words[0] == operating_system and words[1] == locale:
providers.setdefault(provider_name, []).append(
- "%s %s %s" % (words[2], words[3], words[4].replace('-', ' '))
+ "%s %s %s" %
+ (words[2], words[3], words[4].replace('-', ' '))
)
-
+
link_file.close()
-
+
# Create the final links list with all providers
all_links = []
-
+
for key in providers.keys():
all_links.append(
"\n%s\n%s\n" % (key, ''.join(providers[key]))
)
-
+
if all_links:
return "".join(all_links)
else:
return None
-
-
-
+
def _log_request(self, operating_system, locale):
"""
Private method to log what service module called to get the links.
-
+
Parameters: none
"""
-
+
caller = inspect.stack()[2]
module = inspect.getmodule(caller[0])
-
+
# Dummy print for now. Should be done with logging
print "\nCalled by %s\nOS: %s\nLocale: %s\n" % \
- (str(module), operating_system, locale)
-
-
+ (str(module), operating_system, locale)
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits