]> git.ipfire.org Git - ipfire.org.git/commitdiff
python3: Fix indentation and other import issues
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 10 Oct 2018 10:28:37 +0000 (11:28 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 10 Oct 2018 10:33:18 +0000 (11:33 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
12 files changed:
src/backend/accounts.py
src/backend/countries.py
src/backend/database.py
src/backend/mirrors.py
src/backend/releases.py
src/backend/talk.py
src/backend/tracker.py
src/web/handlers_accounts.py
src/web/handlers_base.py
src/web/handlers_boot.py
src/web/handlers_fireinfo.py
src/web/handlers_talk.py

index fc315d8b599fd759d6b23c4bc8a7b439665afbf3..2449658d0b0c60d021670bfe96959b6041afbfc2 100644 (file)
@@ -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
 
index faabecfd28564c496f78f0490e88127f4a2bb03b..ec271558f08f92ccb11cbc4e330085b3a7f7fb12 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/python
 # encoding: utf-8
 
-_ = lambda x: x.decode("utf-8")
+_ = lambda x: x
 
 country_list = {
        "AD" : _("Andorra"),
index fde06c3e00f76ceba2bf2687875184b3d66c6623..ed64727cc1c84cb3231b822f5d993cb2ab2cf9dc 100644 (file)
@@ -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
index 08f5057ba747f513c10a410f468357e4ccebb075..12d56c3a64e7858e5000a0df1886c3b4ffb04abe 100644 (file)
@@ -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):
index ba898e703ff9ad9ccc59ee4bc3073f2d4c1e3939..2a4f91f79916a14d6ffdfda593fd62a04ff8b2f7 100644 (file)
@@ -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
 
index 8029a2503ffab6ac3abc445d6d50763ea0c72e1a..a77fcd0bd9238034b093231b0f950e4031e15447 100644 (file)
@@ -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:
index cabf545a7ce8b58bde533791533d18ef2a8d4e53..f211967636ee9da7396f3850e172dc6a28b12757 100644 (file)
@@ -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 = []
index 85016920719e49d6b7491570034d2e538fde476f..d1dd7fb8b2580a3a94e12cafb2389f0414965917 100644 (file)
@@ -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)
index 33164af6f0d30d7d57562622d9fb11047dd8325e..7afaa7985d4d8bba36c6442d1dd225d77c3aa429 100644 (file)
@@ -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
index 580aaa5c5cc08c8f97ea0f86dc9afcdcc86bc40e..14a1568c523572c1a2ea73e940b1d1eca3891e6a 100644 (file)
@@ -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")
index d5b81864435c1fc4fa9b3ad4c52423d7b41cace2..72c0e6e7665433897d0da30f5c120a3842fd237b 100644 (file)
@@ -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.")
 
index 5b66d9a42fb262cd340aec4704e3b4606f4d701a..32a63ea77d51f4ec54e3610b9b5d50c81adcb317 100644 (file)
@@ -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):