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()
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()
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()
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()
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")
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()
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")
def _disable_insecure_serializers(whitelist=[]): for name in set("pickle", "json", "yaml", "msgpack") - set(whitelist): try: unregister(name) except SerializerNotInstalled: pass
def tearDown(self): unittest.TestCase.tearDown(self) serialization.unregister('adsmsg')