mirror of https://github.com/rq/rq.git
accomodate py3 imports and builtins
This commit is contained in:
parent
2e517001a9
commit
a3b5ce5e46
|
@ -39,3 +39,14 @@ else:
|
|||
opfunc.__doc__ = getattr(int, opname).__doc__
|
||||
setattr(cls, opname, opfunc)
|
||||
return cls
|
||||
|
||||
|
||||
PY2 = sys.version_info[0] < 3
|
||||
|
||||
if PY2:
|
||||
string_types = (str, unicode)
|
||||
text_type = unicode
|
||||
|
||||
else:
|
||||
string_types = (str,)
|
||||
text_type = str
|
||||
|
|
|
@ -21,6 +21,7 @@ import logging.handlers
|
|||
import re
|
||||
import sys
|
||||
import types
|
||||
from rq.compat import string_types
|
||||
|
||||
IDENTIFIER = re.compile('^[a-z_][a-z0-9_]*$', re.I)
|
||||
|
||||
|
@ -230,7 +231,7 @@ class BaseConfigurator(object):
|
|||
isinstance(value, tuple):
|
||||
value = ConvertingTuple(value)
|
||||
value.configurator = self
|
||||
elif isinstance(value, basestring): # str for py3k
|
||||
elif isinstance(value, string_types): # str for py3k
|
||||
m = self.CONVERT_PATTERN.match(value)
|
||||
if m:
|
||||
d = m.groupdict()
|
||||
|
|
|
@ -2,6 +2,7 @@ from functools import wraps
|
|||
from .queue import Queue
|
||||
from .connections import resolve_connection
|
||||
from .worker import DEFAULT_RESULT_TTL
|
||||
from rq.compat import string_types
|
||||
|
||||
class job(object):
|
||||
|
||||
|
@ -26,7 +27,7 @@ class job(object):
|
|||
def __call__(self, f):
|
||||
@wraps(f)
|
||||
def delay(*args, **kwargs):
|
||||
if isinstance(self.queue, basestring):
|
||||
if isinstance(self.queue, string_types):
|
||||
queue = Queue(name=self.queue, connection=self.connection)
|
||||
else:
|
||||
queue = self.queue
|
||||
|
|
|
@ -2,10 +2,14 @@ import importlib
|
|||
import inspect
|
||||
import times
|
||||
from uuid import uuid4
|
||||
from cPickle import loads, dumps, UnpicklingError
|
||||
try:
|
||||
from cPickle import loads, dumps, UnpicklingError
|
||||
except ImportError: # noqa
|
||||
from pickle import loads, dumps, UnpicklingError # noqa
|
||||
from .local import LocalStack
|
||||
from .connections import resolve_connection
|
||||
from .exceptions import UnpickleError, NoSuchJobError
|
||||
from rq.compat import text_type
|
||||
|
||||
|
||||
def enum(name, *sequential, **named):
|
||||
|
@ -194,7 +198,7 @@ class Job(object):
|
|||
first time the ID is requested.
|
||||
"""
|
||||
if self._id is None:
|
||||
self._id = unicode(uuid4())
|
||||
self._id = text_type(uuid4())
|
||||
return self._id
|
||||
|
||||
def set_id(self, value):
|
||||
|
|
|
@ -17,7 +17,10 @@ except ImportError: # noqa
|
|||
try:
|
||||
from thread import get_ident # noqa
|
||||
except ImportError: # noqa
|
||||
from dummy_thread import get_ident # noqa
|
||||
try:
|
||||
from _thread import get_ident # noqa
|
||||
except ImportError: # noqa
|
||||
from dummy_thread import get_ident # noqa
|
||||
|
||||
|
||||
def release_local(local):
|
||||
|
|
|
@ -3,7 +3,7 @@ from .connections import resolve_connection
|
|||
from .job import Job, Status
|
||||
from .exceptions import (NoSuchJobError, UnpickleError,
|
||||
InvalidJobOperationError, DequeueTimeout)
|
||||
from .compat import total_ordering
|
||||
from .compat import total_ordering, string_types
|
||||
|
||||
|
||||
def get_failed_queue(connection=None):
|
||||
|
@ -154,7 +154,7 @@ class Queue(object):
|
|||
* A string, representing the location of a function (must be
|
||||
meaningful to the import context of the workers)
|
||||
"""
|
||||
if not isinstance(f, basestring) and f.__module__ == '__main__':
|
||||
if not isinstance(f, string_types) and f.__module__ == '__main__':
|
||||
raise ValueError(
|
||||
'Functions from the __main__ module cannot be processed '
|
||||
'by workers.')
|
||||
|
|
|
@ -3,7 +3,10 @@ from datetime import datetime
|
|||
from tests import RQTestCase
|
||||
from tests.fixtures import Number, some_calculation, say_hello, access_self
|
||||
from tests.helpers import strip_milliseconds
|
||||
from cPickle import loads
|
||||
try:
|
||||
from cPickle import loads
|
||||
except ImportError:
|
||||
from pickle import loads
|
||||
from rq.job import Job, get_current_job
|
||||
from rq.exceptions import NoSuchJobError, UnpickleError
|
||||
from rq.queue import Queue
|
||||
|
|
Loading…
Reference in New Issue