예제 #1
0
 def test_unregister(self):
     with self.assertRaises(SerializerNotInstalled):
         unregister('nonexisting')
     registry.encode('foo', serializer='pickle')
     unregister('pickle')
     with self.assertRaises(SerializerNotInstalled):
         registry.encode('foo', serializer='pickle')
     register_pickle()
예제 #2
0
 def test_unregister(self):
     with self.assertRaises(SerializerNotInstalled):
         unregister('nonexisting')
     registry.encode('foo', serializer='pickle')
     unregister('pickle')
     with self.assertRaises(SerializerNotInstalled):
         registry.encode('foo', serializer='pickle')
     register_pickle()
예제 #3
0
 def test_unregister(self):
     self.assertRaises(SerializerNotInstalled,
                       unregister, "nonexisting")
     registry.encode("foo", serializer="pickle")
     unregister("pickle")
     self.assertRaises(SerializerNotInstalled,
                       registry.encode, "foo", serializer="pickle")
     register_pickle()
예제 #4
0
 def test_unregister(self):
     with pytest.raises(SerializerNotInstalled):
         unregister('nonexisting')
     dumps('foo', serializer='pickle')
     unregister('pickle')
     with pytest.raises(SerializerNotInstalled):
         dumps('foo', serializer='pickle')
     register_pickle()
예제 #5
0
 def test_unregister(self):
     with self.assertRaises(SerializerNotInstalled):
         unregister("nonexisting")
     registry.encode("foo", serializer="pickle")
     unregister("pickle")
     with self.assertRaises(SerializerNotInstalled):
         registry.encode("foo", serializer="pickle")
     register_pickle()
예제 #6
0
 def test_unregister(self):
     with pytest.raises(SerializerNotInstalled):
         unregister('nonexisting')
     dumps('foo', serializer='pickle')
     unregister('pickle')
     with pytest.raises(SerializerNotInstalled):
         dumps('foo', serializer='pickle')
     register_pickle()
예제 #7
0
 def test_unregister(self):
     with self.assertRaises(SerializerNotInstalled):
         unregister("nonexisting")
     registry.encode("foo", serializer="pickle")
     unregister("pickle")
     with self.assertRaises(SerializerNotInstalled):
         registry.encode("foo", serializer="pickle")
     register_pickle()
예제 #8
0
 def test_unregister(self):
     self.assertRaises(SerializerNotInstalled, unregister, "nonexisting")
     registry.encode("foo", serializer="pickle")
     unregister("pickle")
     self.assertRaises(SerializerNotInstalled,
                       registry.encode,
                       "foo",
                       serializer="pickle")
     register_pickle()
예제 #9
0
    def custom_serializer(self, rabbit_config):
        def encode(value):
            value = json.dumps(value)
            return value.upper()

        def decode(value):
            value = value.lower()
            return json.loads(value)

        # register new serializer
        register("upperjson", encode, decode, "application/x-upper-json",
                 "utf-8")
        # update config so consumers expect it
        rabbit_config['serializer'] = "upperjson"
        yield
        unregister("upperjson")
예제 #10
0
def fernet_loads(encoded_message):
    statsd.incr('basket.news.celery.fernet_loads')
    if FERNET:
        try:
            encoded_message = FERNET.decrypt(force_bytes(encoded_message))
        except InvalidToken:
            statsd.incr('basket.news.celery.fernet_loads.unencrypted')
        else:
            statsd.incr('basket.news.celery.fernet_loads.encrypted')
    else:
        statsd.incr('basket.news.celery.fernet_loads.unencrypted')

    return json.loads(encoded_message)


serialization.unregister('json')
serialization.register('json',
                       fernet_dumps,
                       fernet_loads,
                       content_type='application/json',
                       content_encoding='utf-8')

app = Celery('basket')

# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
#   should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings', namespace='CELERY')
# Load task modules from all registered Django app configs.
app.autodiscover_tasks()
예제 #11
0
def fernet_loads(encoded_message):
    statsd.incr("basket.news.celery.fernet_loads")
    if FERNET:
        try:
            encoded_message = FERNET.decrypt(force_bytes(encoded_message))
        except InvalidToken:
            statsd.incr("basket.news.celery.fernet_loads.unencrypted")
        else:
            statsd.incr("basket.news.celery.fernet_loads.encrypted")
    else:
        statsd.incr("basket.news.celery.fernet_loads.unencrypted")

    return json.loads(encoded_message)


serialization.unregister("json")
serialization.register(
    "json",
    fernet_dumps,
    fernet_loads,
    content_type="application/json",
    content_encoding="utf-8",
)

app = Celery("basket")

# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
#   should have a `CELERY_` prefix.
app.config_from_object("django.conf:settings", namespace="CELERY")
예제 #12
0
파일: __init__.py 프로젝트: a5an0/celery
def _disable_insecure_serializers(whitelist=[]):
    for name in set("pickle", "json", "yaml", "msgpack") - set(whitelist):
        try:
            unregister(name)
        except SerializerNotInstalled:
            pass
예제 #13
0
 def tearDown(self):
     unittest.TestCase.tearDown(self)
     serialization.unregister('adsmsg')