Skip to content

Commit

Permalink
Run 2to3 and apply suggested changes. All tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Rech committed Nov 30, 2012
1 parent d006377 commit 97fadcc
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 27 deletions.
16 changes: 10 additions & 6 deletions huey/bin/huey_consumer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#!/usr/bin/env python
from __future__ import print_function
import datetime
import logging
import os
import Queue

try:
import Queue
except ImportError: # py3
import queue as Queue

import signal
import sys
import time
Expand All @@ -12,19 +17,18 @@
from huey.exceptions import QueueException, QueueReadException, DataStorePutException, QueueWriteException
from huey.queue import Invoker, CommandSchedule
from huey.registry import registry
from huey.utils import load_class


class IterableQueue(Queue.Queue):
def __iter__(self):
return self

def next(self):
def __next__(self):
result = self.get()
if result is StopIteration:
raise result
return result

next = __next__

class Consumer(object):
def __init__(self, invoker, config):
Expand Down Expand Up @@ -265,7 +269,7 @@ def run(self):
self.logger.info('shutdown...')

def err(s):
print '\033[91m%s\033[0m' % s
print('\033[91m%s\033[0m' % s)
sys.exit(1)

def load_config(config):
Expand Down
14 changes: 7 additions & 7 deletions huey/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ def crontab(month='*', day='*', day_of_week='*', hour='*', minute='*'):
m,n = run on m and n
"""
validation = (
('m', month, range(1, 13)),
('d', day, range(1, 32)),
('w', day_of_week, range(7)),
('H', hour, range(24)),
('M', minute, range(60))
('m', month, list(range(1, 13))),
('d', day, list(range(1, 32))),
('w', day_of_week, list(range(7))),
('H', hour, list(range(24))),
('M', minute, list(range(60)))
)
cron_settings = []
min_interval = None
Expand All @@ -145,10 +145,10 @@ def crontab(month='*', day='*', day_of_week='*', hour='*', minute='*'):
else:
dash_match = dash_re.match(piece)
if dash_match:
lhs, rhs = map(int, dash_match.groups())
lhs, rhs = list(map(int, dash_match.groups()))
if lhs not in acceptable or rhs not in acceptable:
raise ValueError('%s is not a valid input' % piece)
settings.update(range(lhs, rhs+1))
settings.update(list(range(lhs, rhs+1)))
continue

every_match = every_re.match(piece)
Expand Down
4 changes: 3 additions & 1 deletion huey/djhuey/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import print_function

import sys

from django.conf import settings
Expand Down Expand Up @@ -82,7 +84,7 @@ class name of the result store.

config = getattr(settings, 'HUEY_CONFIG', None)
if not config or 'QUEUE' not in config:
print configuration_message
print(configuration_message)
sys.exit(1)

queue = config['QUEUE']
Expand Down
6 changes: 2 additions & 4 deletions huey/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def serialize_commands(self):
return pickle.dumps(messages)

def commands(self):
return self._schedule.values()
return list(self._schedule.values())

def should_run(self, cmd, dt=None):
dt = dt or datetime.datetime.now()
Expand Down Expand Up @@ -229,7 +229,7 @@ def __init__(cls, name, bases, attrs):
registry.register(cls)


class QueueCommand(object):
class QueueCommand(object, metaclass=QueueCommandMetaClass):
"""
A class that encapsulates the logic necessary to 'do something' given some
arbitrary data. When enqueued with the :class:`Invoker`, it will be
Expand All @@ -253,8 +253,6 @@ def execute(self):
)
"""

__metaclass__ = QueueCommandMetaClass

def __init__(self, data=None, task_id=None, execute_time=None, retries=0, retry_delay=0):
"""
Initialize the command object with a receiver and optional data. The
Expand Down
4 changes: 3 additions & 1 deletion huey/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def get_command_class(self, klass_str):
klass = self._registry.get(klass_str)

if not klass:
raise QueueException, '%s not found in CommandRegistry' % klass_str
raise QueueException('%s not found in CommandRegistry' % klass_str)

return klass

Expand All @@ -67,6 +67,8 @@ def get_command_for_message(self, msg):

klass = self.get_command_class(klass_str)

data = eval(data)

This comment has been minimized.

Copy link
@coleifer

coleifer Nov 30, 2012

whoa, why is this getting evaled?

execute_time = eval(execute_time)
command_data = pickle.loads(data)
ex_time = pickle.loads(execute_time)
retries = int(retries)
Expand Down
10 changes: 5 additions & 5 deletions huey/tests/crontab.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def test_crontab_month(self):
valids = [1, 4, 7, 8, 9]
validate_m = crontab(month='1,4,*/6,8-9')

for x in xrange(1, 13):
for x in range(1, 13):
res = validate_m(datetime.datetime(2011, x, 1))
self.assertEqual(res, x in valids)

Expand All @@ -19,7 +19,7 @@ def test_crontab_day(self):
valids = [1, 4, 7, 8, 9, 13, 19, 25, 31]
validate_d = crontab(day='*/6,1,4,8-9')

for x in xrange(1, 32):
for x in range(1, 32):
res = validate_d(datetime.datetime(2011, 1, x))
self.assertEqual(res, x in valids)

Expand All @@ -28,7 +28,7 @@ def test_crontab_hour(self):
valids = [0, 1, 4, 6, 8, 9, 12, 18]
validate_h = crontab(hour='8-9,*/6,1,4')

for x in xrange(24):
for x in range(24):
res = validate_h(datetime.datetime(2011, 1, 1, x))
self.assertEqual(res, x in valids)

Expand All @@ -41,7 +41,7 @@ def test_crontab_minute(self):
valids = [0, 1, 4, 6, 8, 9, 12, 18, 24, 30, 36, 42, 48, 54]
validate_m = crontab(minute='4,8-9,*/6,1')

for x in xrange(60):
for x in range(60):
res = validate_m(datetime.datetime(2011, 1, 1, 1, x))
self.assertEqual(res, x in valids)

Expand All @@ -51,7 +51,7 @@ def test_crontab_day_of_week(self):
valids = [2, 4, 9, 11, 16, 18, 23, 25, 30]
validate_dow = crontab(day_of_week='0,2')

for x in xrange(1, 32):
for x in range(1, 32):
res = validate_dow(datetime.datetime(2011, 1, x))
self.assertEqual(res, x in valids)

Expand Down
4 changes: 3 additions & 1 deletion huey/tests/test_cmd.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import absolute_import

from huey.decorators import queue_command
from config import test_invoker
from .config import test_invoker

@queue_command(test_invoker)
def test_command_xxx(val):
Expand Down
4 changes: 2 additions & 2 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import sys
import unittest

from huey import tests
import huey.tests

def runtests(*test_args):
suite = unittest.TestLoader().loadTestsFromModule(tests)
suite = unittest.TestLoader().loadTestsFromModule(huey.tests)
result = unittest.TextTestRunner(verbosity=2).run(suite)
if result.failures:
sys.exit(1)
Expand Down

0 comments on commit 97fadcc

Please sign in to comment.