]> git.aero2k.de Git - sirius.git/commitdiff
Fix a fair amount of flake8 complaining.
authorTom Hunger <tehunger@gmail.com>
Fri, 16 Jan 2015 10:37:08 +0000 (10:37 +0000)
committerTom Hunger <tehunger@gmail.com>
Fri, 16 Jan 2015 10:37:08 +0000 (10:37 +0000)
Ignoring certain cases where readability > consistency.

sirius/coding/decoders.py
sirius/coding/image_encoding.py
sirius/coding/test_claim_coding.py
sirius/coding/test_image_coding.py
sirius/fake/commands.py
sirius/models/user.py
sirius/protocol/messages.py
sirius/protocol/protocol_loop.py
sirius/web/login.py
sirius/web/test_claiming.py
sirius/web/webapp.py

index 9f14be2e710e581fe2368dd4b98e2f4ece53e750..776ef91ca91579c0e40bccdf10972b1f64d1f58b 100644 (file)
@@ -42,19 +42,20 @@ class DeviceEventConst(object):
     EVENT_DID_POWER_ON_SIZE_SHORT = 58 # No fragmentation
 
     RESET_DICT = {
-        0x0000 : "Undeterminable cause",
-        0x0100 : "FIB bootloader",
-        0x0200 : "Ember bootloader",
-        0x0300 : "External reset",
-        0x0400 : "Power on",
-        0x0500 : "Watchdog",
-        0x0600 : "Software triggered",
-        0x0700 : "Software crash",
-        0x0800 : "Flash failure",
-        0x0900 : "Fatal error",
-        0x0a00 : "Access fault",
+        0x0000: "Undeterminable cause",
+        0x0100: "FIB bootloader",
+        0x0200: "Ember bootloader",
+        0x0300: "External reset",
+        0x0400: "Power on",
+        0x0500: "Watchdog",
+        0x0600: "Software triggered",
+        0x0700: "Software crash",
+        0x0800: "Flash failure",
+        0x0900: "Fatal error",
+        0x0a00: "Access fault",
     }
 
+
 def decode_message(data):
     """Decodes a single incoming message from data.
 
@@ -185,7 +186,7 @@ def _decode_device_event(data):
         else:
             return messages.MalformedEvent(
                 data, 'power_on payload wrong size. Is {}. Expected: {}'.format(
-                len(payload_length),
+                    len(payload_length),
             ))
 
         deviceType, firmwareBuildVersion, loaderBuildVersion, protocolVersion, resetDescription = power_on_fields
index 13909b3d54bc22b9cd4f4cec54f754f114f8da92..4ce2bd111ab20266b2f6502d393700f2149dcc3e 100644 (file)
@@ -7,7 +7,8 @@ import tempfile
 WHITE = 0
 BLACK = 1
 THRESHOLD = 127
-TRANSLATE = [ (1536, 255), (1152, 254), (768, 253), (384, 252), (251, 251) ]
+TRANSLATE = [(1536, 255), (1152, 254), (768, 253), (384, 252), (251, 251)]
+
 
 def pixel_to_bw(p):
     if p == (0, 0, 0, 0):
@@ -17,7 +18,11 @@ def pixel_to_bw(p):
     else:
         return BLACK
 
-def ilen(i): return sum(1 for _ in i)
+
+def ilen(i):
+    "Returns length of an iterator in constant space."
+    return sum(1 for _ in i)
+
 
 # so what we have is a list of runs, alternating white and black,
 # starting with white.
@@ -66,7 +71,7 @@ def rle_image(im):
     # create list of tuples (WHITE|BLACK, run_length)
     groups = []
     for k, g in grouped:
-        groups.append( (k, ilen(g)) )
+        groups.append((k, ilen(g)))
 
     # the decoder assumes that the first run is white, so if the
     # first pixel is black, add a zero run of white
@@ -87,24 +92,24 @@ def rle_image(im):
 
 
 def html_to_png(html):
-       """ This works:
-       <html><body style="width: 384px; margin: 0;">
-       <img src="https://dl.dropboxusercontent.com/u/165957/Escher.gif">
-       </body></html>
-       """
-       from selenium import webdriver
-        try:
-            driver = webdriver.PhantomJS('phantomjs')
-            driver.set_window_size(384, 5)
-
-            # note that the .html suffix is required to make phantomjs
-            # pick up the mime-type and render correctly.
-            with tempfile.NamedTemporaryFile(suffix='.html') as f:
-                f.write(html)
-                f.flush()
-                driver.get('file://' + f.name)
-                p = driver.get_screenshot_as_png()
-
-            return Image.open(io.BytesIO(p))
-        finally:
-            driver.quit()
+    """ This works:
+    <html><body style="width: 384px; margin: 0;">
+    <img src="https://dl.dropboxusercontent.com/u/165957/Escher.gif">
+    </body></html>
+    """
+    from selenium import webdriver
+    try:
+        driver = webdriver.PhantomJS('phantomjs')
+        driver.set_window_size(384, 5)
+
+        # note that the .html suffix is required to make phantomjs
+        # pick up the mime-type and render correctly.
+        with tempfile.NamedTemporaryFile(suffix='.html') as f:
+            f.write(html)
+            f.flush()
+            driver.get('file://' + f.name)
+            p = driver.get_screenshot_as_png()
+
+        return Image.open(io.BytesIO(p))
+    finally:
+        driver.quit()
index b0980b821856ee4e77159acbe5c3c5adc2c14d78..1583c63e3523cfd2e3a06a8de0081ea7e70d4fdc 100644 (file)
@@ -1,7 +1,6 @@
 import unittest
 
 from sirius.coding import claiming
-from sirius.coding import bitshuffle
 
 
 CC_TEST_VECTORS = [
index fd8fcd46043550ff1e485e935a5f09879ee1fe53..4033129491de70d29bbaba578cb2c45afe3b2fca 100644 (file)
@@ -2,6 +2,7 @@ import unittest
 
 from sirius.coding import image_encoding
 
+
 class ImageCase(unittest.TestCase):
 
     def test_normal_text(self):
index cfdec7ce2bffb2bf5f3bbffa1307885b6a0def4f..dc0580bcd31290406e375dad843138a5815dba33 100644 (file)
@@ -10,11 +10,14 @@ from sirius.models.db import db
 from sirius.coding import bitshuffle
 from sirius.coding import claiming
 
+
 def sub_opts(app, **kwargs):
     pass
 
+
 fake_manager = script.Manager(sub_opts, usage="Fake printer interactions.")
 
+
 @fake_manager.command
 def printer():
     device_address = os.urandom(8).encode('hex')
index 35d43c1217d3f834ba9e3209b2515686fbd3964a..c21efe0f38c43cbb08d020089825361751011d41 100644 (file)
@@ -8,6 +8,7 @@ from sirius.coding import claiming
 from sirius.models.db import db
 from sirius.models import hardware
 
+
 class User(db.Model):
     id = db.Column(db.Integer, primary_key=True)
     created = db.Column(db.DateTime, default=datetime.datetime.utcnow)
@@ -70,6 +71,6 @@ class TwitterOAuth(db.Model):
 
 TwitterOAuth.user = db.relationship(
     User,
-    primaryjoin=TwitterOAuth.user_id==User.id,
+    primaryjoin=TwitterOAuth.user_id == User.id,
     backref=db.backref('twitteroauth', lazy='dynamic'),
 )
index 8fe1577b944fca73a92151fd0ac9789b1cb00fd8..8668976d4697e91bd71c3245ee6a2bca7bb9c07c 100644 (file)
@@ -64,7 +64,7 @@ DeviceCommandResponse = namedtuple('DeviceCommandResponse', [
 
 SetDeliveryAndPrint = namedtuple('SetDeliveryAndPrint', [
     'device_address',
-    'pixels', # 384 pixels wide
+    'pixels',  # 384 pixels wide
 ])
 
 SetDelivery = namedtuple('SetDelivery', [
@@ -73,7 +73,7 @@ SetDelivery = namedtuple('SetDelivery', [
 ])
 
 SetLogLevel = namedtuple('SetLogLevel', [
-    'level', # lower-case string, e.g. 'critical'
+    'level',  # lower-case string, e.g. 'critical'
 ])
 
 EnableCloudLogging = namedtuple('EnableCloudLogging', [])
@@ -83,11 +83,11 @@ DisableCloudLogging = namedtuple('DisableCloudLogging', [])
 Leave = namedtuple('Leave', [])
 
 Form = namedtuple('Form', [
-    'channels', # list of numbers
+    'channels',  # list of numbers
 ])
 
 Pjoin = namedtuple('Pjoin', [
-    'duration', # int
+    'duration',  # int
 ])
 
 Restart = namedtuple('Restart', [])
@@ -95,11 +95,11 @@ Restart = namedtuple('Restart', [])
 Reboot = namedtuple('Reboot', [])
 
 SetCommandPollFrequency = namedtuple('SetCommandPollFrequency', [
-    'frequency', # int in seconds, clamped to [10, 30]
+    'frequency',  # int in seconds, clamped to [10, 30]
 ])
 
 SetBridgeLogFrequency = namedtuple('SetBridgeLogFrequency', [
-    'frequency', # int in seconds, clamped to [10, 30]
+    'frequency',  # int in seconds, clamped to [10, 30]
 ])
 
 EnableSlowEvents = namedtuple('EnableSlowEvents', [])
index a689d8166c2c1a4252d02e4d8d4dc031a1410300..72682d5022f866c2825e496f557934041279427d 100644 (file)
@@ -124,7 +124,7 @@ def _decoder_loop(ws):
     while True:
         raw_data = ws.receive()
         if raw_data == '':
-            break # websocket closed by client
+            break  # websocket closed by client
 
         try:
             data = json.loads(raw_data)
@@ -150,7 +150,7 @@ def _accept_step(x, bridge_state):
         bridge_state.connected_devices.discard(x.device_address)
 
     elif type(x) == messages.BridgeLog:
-        pass # TODO - write log to a place
+        pass  # TODO - write log to a place
 
     elif type(x) == messages.EncryptionKeyRequired:
         hardware.Printer.phone_home(x.device_address)
index bb71238447249619bd0069c76f5fcb8719047c8b..bf4c705a714a97716bceb19165680c57b2c59b3f 100644 (file)
@@ -4,6 +4,7 @@ from sirius.models import user
 
 manager = login.LoginManager()
 
+
 @manager.user_loader
 def load_user(user_id):
     return user.User.query.get(user_id)
index 6d14cbd6b9ff78104cc048d5281d4b4245ccd9fa..5b4310316d9b0a8b7a4025ba25dfef57d6b72175 100644 (file)
@@ -7,6 +7,7 @@ from sirius.models import hardware
 from sirius.models.db import db
 from sirius.web import webapp
 
+
 class Base(testing.TestCase):
 
     def create_app(self):
index 3f4a7051363f47cfd660687c142cb6ce1fb0e814..0b0ab47bb2f9cc0136a9ca00e6e799765d0e6f8d 100644 (file)
@@ -15,7 +15,7 @@ from sirius.protocol import protocol_loop
 from sirius import stats
 from sirius import config
 
- # Import models so they get picked up for migrations.
+# Import models so they get picked up for migrations.
 from sirius.models import db
 from sirius.models import hardware
 from sirius.models import user