Ignoring certain cases where readability > consistency.
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.
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
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):
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.
# 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
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()
import unittest
from sirius.coding import claiming
-from sirius.coding import bitshuffle
CC_TEST_VECTORS = [
from sirius.coding import image_encoding
+
class ImageCase(unittest.TestCase):
def test_normal_text(self):
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')
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)
TwitterOAuth.user = db.relationship(
User,
- primaryjoin=TwitterOAuth.user_id==User.id,
+ primaryjoin=TwitterOAuth.user_id == User.id,
backref=db.backref('twitteroauth', lazy='dynamic'),
)
SetDeliveryAndPrint = namedtuple('SetDeliveryAndPrint', [
'device_address',
- 'pixels', # 384 pixels wide
+ 'pixels', # 384 pixels wide
])
SetDelivery = namedtuple('SetDelivery', [
])
SetLogLevel = namedtuple('SetLogLevel', [
- 'level', # lower-case string, e.g. 'critical'
+ 'level', # lower-case string, e.g. 'critical'
])
EnableCloudLogging = namedtuple('EnableCloudLogging', [])
Leave = namedtuple('Leave', [])
Form = namedtuple('Form', [
- 'channels', # list of numbers
+ 'channels', # list of numbers
])
Pjoin = namedtuple('Pjoin', [
- 'duration', # int
+ 'duration', # int
])
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', [])
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)
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)
manager = login.LoginManager()
+
@manager.user_loader
def load_user(user_id):
return user.User.query.get(user_id)
from sirius.models.db import db
from sirius.web import webapp
+
class Base(testing.TestCase):
def create_app(self):
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