diff --git a/deluge/ui/console/main.py b/deluge/ui/console/main.py
index 248060734..3a850d8d9 100644
--- a/deluge/ui/console/main.py
+++ b/deluge/ui/console/main.py
@@ -138,13 +138,13 @@ def load_commands(command_dir, exclude=[]):
class ConsoleUI(component.Component):
def __init__(self, args=None):
component.Component.__init__(self, "ConsoleUI", 2)
-
- try:
- locale.setlocale(locale.LC_ALL, '')
- self.encoding = locale.getpreferredencoding()
- except:
+
+ try:
+ locale.setlocale(locale.LC_ALL, '')
+ self.encoding = locale.getpreferredencoding()
+ except:
self.encoding = sys.getdefaultencoding()
-
+
log.debug("Using encoding: %s", self.encoding)
# Load all the commands
self._commands = load_commands(os.path.join(UI_PATH, 'commands'))
diff --git a/deluge/ui/console/screen.py b/deluge/ui/console/screen.py
index 4e53106a5..984f9031d 100644
--- a/deluge/ui/console/screen.py
+++ b/deluge/ui/console/screen.py
@@ -115,7 +115,7 @@ class Screen(CursesStdIO):
self.encoding = sys.getdefaultencoding()
else:
self.encoding = encoding
-
+
# Do a refresh right away to draw the screen
self.refresh()
@@ -239,8 +239,8 @@ class Screen(CursesStdIO):
if index + 1 == len(parsed):
# This is the last string so lets append some " " to it
s += " " * (self.cols - (col + len(s)) - 1)
- if isinstance(s, unicode):
- #Have to use replace as character counting has already been done
+ if isinstance(s, unicode):
+ #Have to use replace as character counting has already been done
s = s.encode(self.encoding, 'replace')
self.stdscr.addstr(row, col, s, color)
col += len(s)
diff --git a/deluge/ui/web/server.py b/deluge/ui/web/server.py
index a9d84d237..260d9b9ad 100644
--- a/deluge/ui/web/server.py
+++ b/deluge/ui/web/server.py
@@ -36,7 +36,7 @@
import os
import time
import locale
-import shutil
+import shutil
import urllib
import gettext
import hashlib
@@ -82,20 +82,20 @@ CONFIG_DEFAULTS = {
# Misc Settings
"enabled_plugins": [],
"default_daemon": "",
-
+
# Auth Settings
"pwd_salt": "c26ab3bbd8b137f99cd83c2c1c0963bcc1a35cad",
"pwd_sha1": "2ce1a410bcdcc53064129b6d950f2e9fee4edc1e",
"session_timeout": 3600,
"sessions": {},
-
+
# UI Settings
"sidebar_show_zero": False,
"sidebar_show_trackers": False,
"show_session_speed": False,
"show_sidebar": True,
"theme": "slate",
-
+
# Server Settings
"port": 8112,
"https": False,
@@ -245,17 +245,17 @@ class LookupResource(resource.Resource, component.Component):
def __init__(self, name, *directories):
resource.Resource.__init__(self)
component.Component.__init__(self, name)
-
+
self.__paths = {}
for directory in directories:
self.addDirectory(directory)
-
+
def addDirectory(self, directory, path=""):
log.debug("Adding directory `%s` with path `%s`", directory, path)
paths = self.__paths.get(path, [])
paths.append(directory)
self.__paths[path] = paths
-
+
def removeDirectory(self, directory, path=""):
log.debug("Removing directory `%s`", directory)
self.__paths[path].remove(directory)
@@ -267,23 +267,23 @@ class LookupResource(resource.Resource, component.Component):
request.lookup_path = path
return self
- def render(self, request):
+ def render(self, request):
log.debug("Requested path: '%s'", request.lookup_path)
path = os.path.dirname(request.lookup_path)
-
+
if path not in self.__paths:
request.setResponseCode(http.NOT_FOUND)
return "
404 - Not Found
"
-
+
filename = os.path.basename(request.path)
for directory in self.__paths[path]:
if filename in os.listdir(directory):
- path = os.path.join(directory, filename)
+ path = os.path.join(directory, filename)
log.debug("Serving path: '%s'", path)
mime_type = mimetypes.guess_type(path)
request.setHeader("content-type", mime_type[0])
return open(path, "rb").read()
-
+
request.setResponseCode(http.NOT_FOUND)
return "404 - Not Found
"
@@ -383,29 +383,29 @@ class TopLevel(resource.Resource):
@property
def stylesheets(self):
return self.__stylesheets
-
+
def add_script(self, script):
"""
Adds a script to the server so it is included in the element
of the index page.
-
+
:param script: The path to the script
:type script: string
"""
-
+
self.__scripts.append(script)
self.__debug_scripts.append(script)
-
+
def remove_script(self, script):
"""
Removes a script from the server.
-
+
:param script: The path to the script
:type script: string
"""
self.__scripts.remove(script)
self.__debug_scripts.remove(script)
-
+
def getChild(self, path, request):
if path == "":
@@ -421,7 +421,7 @@ class TopLevel(resource.Resource):
debug = True
elif debug_arg == 'false':
debug = False
-
+
if debug:
scripts = self.debug_scripts[:]
else:
@@ -432,7 +432,7 @@ class TopLevel(resource.Resource):
return template.render(scripts=scripts, stylesheets=self.stylesheets, debug=debug)
class ServerContextFactory:
-
+
def getContext(self):
"""Creates an SSL context."""
ctx = SSL.Context(SSL.SSLv3_METHOD)
@@ -449,7 +449,7 @@ class DelugeWeb(component.Component):
def __init__(self):
super(DelugeWeb, self).__init__("DelugeWeb")
self.config = configmanager.ConfigManager("web.conf", CONFIG_DEFAULTS)
-
+
# Check to see if a configuration from the web interface prior to 1.2
# exists and convert it over.
if os.path.exists(configmanager.get_config_dir("webui06.conf")):
@@ -460,13 +460,13 @@ class DelugeWeb(component.Component):
# it.
for key in OLD_CONFIG_KEYS:
self.config[key] = old_config[key]
-
+
# We need to base64 encode the passwords since json can't handle
# them otherwise.
from base64 import encodestring
self.config["old_pwd_md5"] = encodestring(old_config["pwd_md5"])
self.config["old_pwd_salt"] = encodestring(old_config["pwd_salt"])
-
+
# Save our config and if it saved successfully then rename the
# old configuration file.
if self.config.save():
@@ -487,7 +487,7 @@ class DelugeWeb(component.Component):
# Initalize the plugins
self.plugins = PluginManager()
-
+
def install_signal_handlers(self):
# Since twisted assigns itself all the signals may as well make
# use of it.
@@ -512,29 +512,29 @@ class DelugeWeb(component.Component):
self.start_ssl()
else:
self.start_normal()
-
+
component.get("JSON").enable()
if start_reactor:
reactor.run()
-
+
def start_normal(self):
self.socket = reactor.listenTCP(self.port, self.site)
log.info("serving on %s:%s view at http://127.0.0.1:%s", "0.0.0.0",
self.port, self.port)
-
+
def start_ssl(self):
check_ssl_keys()
self.socket = reactor.listenSSL(self.port, self.site, ServerContextFactory())
log.info("serving on %s:%s view at https://127.0.0.1:%s", "0.0.0.0",
self.port, self.port)
-
+
def stop(self):
log.info("Shutting down webserver")
self.plugins.disable_plugins()
log.debug("Saving configuration file")
self.config.save()
-
+
if self.socket:
d = self.socket.stopListening()
self.socket = None
@@ -544,10 +544,10 @@ class DelugeWeb(component.Component):
return d
def shutdown(self, *args):
- self.stop()
- try:
- reactor.stop()
- except error.ReactorNotRunning:
+ self.stop()
+ try:
+ reactor.stop()
+ except error.ReactorNotRunning:
log.debug("Reactor not running")
if __name__ == "__builtin__":