From: Michael Tremer Date: Wed, 10 Oct 2018 10:28:37 +0000 (+0100) Subject: python3: Fix indentation and other import issues X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a69e87a1486b39942c56ac780a29bab31f26b509;p=ipfire.org.git python3: Fix indentation and other import issues Signed-off-by: Michael Tremer --- diff --git a/src/backend/accounts.py b/src/backend/accounts.py index fc315d8b..2449658d 100644 --- a/src/backend/accounts.py +++ b/src/backend/accounts.py @@ -31,14 +31,14 @@ class Accounts(Object): search_base = self.settings.get("ldap_search_base") - try: - results = self.ldap.search_ext_s(search_base, ldap.SCOPE_SUBTREE, - query, attrlist=attrlist, sizelimit=limit) - except: - # Close current connection - del self._ldap - - raise + try: + results = self.ldap.search_ext_s(search_base, ldap.SCOPE_SUBTREE, + query, attrlist=attrlist, sizelimit=limit) + except: + # Close current connection + del self._ldap + + raise return results diff --git a/src/backend/countries.py b/src/backend/countries.py index faabecfd..ec271558 100644 --- a/src/backend/countries.py +++ b/src/backend/countries.py @@ -1,7 +1,7 @@ #!/usr/bin/python # encoding: utf-8 -_ = lambda x: x.decode("utf-8") +_ = lambda x: x country_list = { "AD" : _("Andorra"), diff --git a/src/backend/database.py b/src/backend/database.py index fde06c3e..ed64727c 100644 --- a/src/backend/database.py +++ b/src/backend/database.py @@ -8,8 +8,6 @@ as torndb. """ - - import copy import itertools import logging @@ -163,7 +161,7 @@ class Connection(object): def _ensure_connected(self): if self._db is None: - logging.warning("Database connection was lost...") + logging.warning("Database connection was lost...") self.reconnect() @@ -181,8 +179,8 @@ class Connection(object): self.close() raise - def transaction(self): - return Transaction(self) + def transaction(self): + return Transaction(self) class Row(dict): @@ -195,19 +193,19 @@ class Row(dict): class Transaction(object): - def __init__(self, db): - self.db = db + def __init__(self, db): + self.db = db - self.db.execute("START TRANSACTION") + self.db.execute("START TRANSACTION") - def __enter__(self): - return self + def __enter__(self): + return self - def __exit__(self, exctype, excvalue, traceback): - if exctype is not None: - self.db.execute("ROLLBACK") - else: - self.db.execute("COMMIT") + def __exit__(self, exctype, excvalue, traceback): + if exctype is not None: + self.db.execute("ROLLBACK") + else: + self.db.execute("COMMIT") # Alias some common exceptions diff --git a/src/backend/mirrors.py b/src/backend/mirrors.py index 08f5057b..12d56c3a 100644 --- a/src/backend/mirrors.py +++ b/src/backend/mirrors.py @@ -317,9 +317,9 @@ class Mirror(Object): def path(self): return self._info.path - @property - def supports_https(self): - return self._info.supports_https + @property + def supports_https(self): + return self._info.supports_https @property def address(self): diff --git a/src/backend/releases.py b/src/backend/releases.py index ba898e70..2a4f91f7 100644 --- a/src/backend/releases.py +++ b/src/backend/releases.py @@ -185,10 +185,10 @@ class File(Object): def torrent_hash(self): return self.data.get("torrent_hash", None) - @property - def torrent_url(self): - if self.torrent_hash: - return "%s.torrent" % self.url + @property + def torrent_url(self): + if self.torrent_hash: + return "%s.torrent" % self.url @property def magnet_link(self): @@ -202,11 +202,11 @@ class File(Object): s += "&dn=%s" % urllib.parse.quote(self.basename) # Add our tracker. - for tracker in TRACKERS: - s += "&tr=%s" % tracker + for tracker in TRACKERS: + s += "&tr=%s" % tracker - # Add web download URL - s += "&as=%s" % urllib.parse.quote(self.url) + # Add web download URL + s += "&as=%s" % urllib.parse.quote(self.url) return s diff --git a/src/backend/talk.py b/src/backend/talk.py index 8029a250..a77fcd0b 100644 --- a/src/backend/talk.py +++ b/src/backend/talk.py @@ -125,22 +125,22 @@ class Talk(Object): return self._process_cdr(res) - def get_channels(self, account=None): - channels = [] - for c in a.list_channels(): - if account and not account.sip_id in (c.caller, c.callee): - continue + def get_channels(self, account=None): + channels = [] + for c in a.list_channels(): + if account and not account.sip_id in (c.caller, c.callee): + continue - channels.append(c) + channels.append(c) - return sorted(channels) + return sorted(channels) - def get_channel(self, channel_id, account=None): - channels = self.get_channels(account=account) + def get_channel(self, channel_id, account=None): + channels = self.get_channels(account=account) - for channel in channels: - if channel.id == channel_id: - return channel + for channel in channels: + if channel.id == channel_id: + return channel def get_ongoing_calls(self, account=None, sip_id=None): if account and sip_id is None: diff --git a/src/backend/tracker.py b/src/backend/tracker.py index cabf545a..f2119676 100644 --- a/src/backend/tracker.py +++ b/src/backend/tracker.py @@ -67,16 +67,6 @@ def bdecode(x): raise Exception("invalid bencoded value (data after valid prefix)") return r -from types import StringType, IntType, LongType, DictType, ListType, TupleType - - -class Bencached(object): - - __slots__ = ['bencoded'] - - def __init__(self, s): - self.bencoded = s - def encode_bencached(x,r): r.append(x.bencoded) @@ -108,19 +98,12 @@ def encode_dict(x,r): r.append('e') encode_func = {} -encode_func[Bencached] = encode_bencached -encode_func[IntType] = encode_int -encode_func[LongType] = encode_int -encode_func[StringType] = encode_string -encode_func[ListType] = encode_list -encode_func[TupleType] = encode_list -encode_func[DictType] = encode_dict - -try: - from types import BooleanType - encode_func[BooleanType] = encode_bool -except ImportError: - pass +encode_func[int] = encode_int +encode_func[str] = encode_string +encode_func[list] = encode_list +encode_func[tuple] = encode_list +encode_func[dict] = encode_dict +encode_func[bool] = encode_bool def bencode(x): r = [] diff --git a/src/web/handlers_accounts.py b/src/web/handlers_accounts.py index 85016920..d1dd7fb8 100644 --- a/src/web/handlers_accounts.py +++ b/src/web/handlers_accounts.py @@ -36,8 +36,8 @@ class AccountsAvatarHandler(BaseHandler): else: avatar = account.get_gravatar_url(size) - if avatar.startswith("http://") or avatar.startswith("https://"): - return self.redirect(avatar) + if avatar.startswith("http://") or avatar.startswith("https://"): + return self.redirect(avatar) self.set_header("Cache-Control", "public,max-age=300") self.set_header("Content-Disposition", "inline; filename=\"%s.jpg\"" % who) diff --git a/src/web/handlers_base.py b/src/web/handlers_base.py index 33164af6..7afaa798 100644 --- a/src/web/handlers_base.py +++ b/src/web/handlers_base.py @@ -5,7 +5,7 @@ import datetime import dateutil.parser import http.client -import ipaddr +import ipaddress import logging import time import tornado.locale @@ -48,7 +48,7 @@ class BaseHandler(tornado.web.RequestHandler): for remote_ip in remote_ips: try: - addr = ipaddr.IPAddress(remote_ip) + addr = ipaddress.ip_address(remote_ip) except ValueError: # Skip invalid IP addresses. continue diff --git a/src/web/handlers_boot.py b/src/web/handlers_boot.py index 580aaa5c..14a1568c 100644 --- a/src/web/handlers_boot.py +++ b/src/web/handlers_boot.py @@ -54,9 +54,9 @@ class MenuGPXEHandler(BootBaseHandler): menu.gpxe """ def get(self): - version = self.get_argument("version", None) - if not version or version < LATEST_VERSION: - return self.serve_update() + version = self.get_argument("version", None) + if not version or version < LATEST_VERSION: + return self.serve_update() # Deliver content self.set_header("Content-Type", "text/plain") diff --git a/src/web/handlers_fireinfo.py b/src/web/handlers_fireinfo.py index d5b81864..72c0e6e7 100644 --- a/src/web/handlers_fireinfo.py +++ b/src/web/handlers_fireinfo.py @@ -156,12 +156,12 @@ class FireinfoProfileSendHandler(FireinfoBaseHandler): location = location.country # Handle the profile. - with self.db.transaction(): - try: - self.fireinfo.handle_profile(public_id, profile_blob, location=location) + with self.db.transaction(): + try: + self.fireinfo.handle_profile(public_id, profile_blob, location=location) - except fireinfo.ProfileParserError: - raise tornado.web.HTTPError(400) + except fireinfo.ProfileParserError: + raise tornado.web.HTTPError(400) self.finish("Your profile was successfully saved to the database.") diff --git a/src/web/handlers_talk.py b/src/web/handlers_talk.py index 5b66d9a4..32a63ea7 100644 --- a/src/web/handlers_talk.py +++ b/src/web/handlers_talk.py @@ -35,37 +35,37 @@ class TalkPhonebookAccountHandler(BaseHandler): class TalkDiagnosisHandler(BaseHandler): @tornado.web.authenticated def get(self): - # Access only allowed for admins - if not self.current_user.is_admin(): - raise tornado.web.HTTPError(403) + # Access only allowed for admins + if not self.current_user.is_admin(): + raise tornado.web.HTTPError(403) return self.render("talk/diagnosis.html") class TalkHangupChannelHandler(BaseHandler): - def _get_channel(self, channel_id): - account = None if self.current_user.is_admin() else self.current_user + def _get_channel(self, channel_id): + account = None if self.current_user.is_admin() else self.current_user - channel = self.talk.get_channel(channel_id, account=account) - if not channel: - raise tornado.web.HTTPError(404) + channel = self.talk.get_channel(channel_id, account=account) + if not channel: + raise tornado.web.HTTPError(404) - return channel + return channel - @tornado.web.authenticated - def get(self, channel_id): - channel = self._get_channel(channel_id) + @tornado.web.authenticated + def get(self, channel_id): + channel = self._get_channel(channel_id) - self.render("talk/confirm-hangup.html", channel=channel) + self.render("talk/confirm-hangup.html", channel=channel) - @tornado.web.authenticated - def post(self, channel_id): - channel = self._get_channel(channel_id) + @tornado.web.authenticated + def post(self, channel_id): + channel = self._get_channel(channel_id) - # Hangup - channel.hangup() + # Hangup + channel.hangup() - self.redirect("/") + self.redirect("/") class TalkConferencesHandler(BaseHandler):