def handle(self, *args, **options): if args: offsets = dict(enumerate(json.loads(args[0]))) else: offsets = None logreader.consume_forever(cache=cache.get_cache('redis'), offsets=offsets)
def store_json(option, opt_str, value, parser): try: value = json.loads(value) except ValueError: print("Invalid JSON was used for option %s. Received: %s" % (opt_str, value)) sys.exit(1) setattr(parser.values, option.dest, value)
def test_custom_transport(self): c = Client(dsn="mock://*****:*****@localhost:8143/1") data = dict(a=42, b=55, c=list(range(50))) c.send(**data) mock_cls = c._transport_cache['mock://*****:*****@localhost:8143/1'].get_transport() expected_message = zlib.decompress(c.encode(data)) actual_message = zlib.decompress(mock_cls._data) # These loads()/dumps() pairs order the dict keys before comparing the string. # See GH504 self.assertEqual( json.dumps(json.loads(expected_message.decode('utf-8')), sort_keys=True), json.dumps(json.loads(actual_message.decode('utf-8')), sort_keys=True) )
def test_custom_transport(self): c = Client(dsn="mock://*****:*****@localhost:8143/1") data = dict(a=42, b=55, c=list(range(50))) c.send(**data) expected_message = zlib.decompress(base64.b64decode(c.encode(data))) self.assertIn('mock://localhost:8143/api/1/store/', Client._registry._transports) mock_cls = Client._registry._transports['mock://localhost:8143/api/1/store/'] actual_message = zlib.decompress(base64.b64decode(mock_cls._data)) # These loads()/dumps() pairs order the dict keys before comparing the string. # See GH504 self.assertEqual( json.dumps(json.loads(expected_message.decode('utf-8')), sort_keys=True), json.dumps(json.loads(actual_message.decode('utf-8')), sort_keys=True) )
def test_custom_transport(self): c = Client(dsn="mock://*****:*****@localhost:8143/1") data = dict(a=42, b=55, c=list(range(50))) c.send(**data) expected_message = zlib.decompress(base64.b64decode(c.encode(data))) self.assertIn('mock://localhost:8143/api/1/store/', Client._registry._transports) mock_cls = Client._registry._transports[ 'mock://localhost:8143/api/1/store/'] actual_message = zlib.decompress(base64.b64decode(mock_cls._data)) # These loads()/dumps() pairs order the dict keys before comparing the string. # See GH504 self.assertEqual( json.dumps(json.loads(expected_message.decode('utf-8')), sort_keys=True), json.dumps(json.loads(actual_message.decode('utf-8')), sort_keys=True))
def test_sqs_transport(sqs_queue): sqs = boto3.client("sqs", region_name="us-east-1") c = Client( dsn="mock://*****:*****@localhost:8143/1" "?sqs_region=us-east-1&sqs_account=123456789012&sqs_name=sentry-queue", transport=SQSTransport) data = dict(a=42, b=55, c=list(range(50))) expected_message = zlib.decompress(c.encode(data)) c.send(**data) transport = c._transport_cache[ "mock://*****:*****@localhost:8143/1" "?sqs_region=us-east-1&sqs_account=123456789012" "&sqs_name=sentry-queue"].get_transport() assert transport.sqs_account == "123456789012" assert transport.sqs_name == "sentry-queue" assert type(transport.sqs_client).__name__ == type(sqs).__name__ assert transport.queue_url == "https://queue.amazonaws.com/123456789012/sentry-queue" # Check SQS for the message that was sent over: messages = sqs.receive_message(QueueUrl=transport.queue_url)["Messages"] assert len(messages) == 1 body = json.loads(messages[0]["Body"]) assert body["url"] == "mock://localhost:8143/api/1/store/" assert "sentry_secret=some_password" in body["headers"]["X-Sentry-Auth"] decoded_data = base64.b64decode(body["data"]) assert json.dumps(json.loads(expected_message.decode('utf-8')), sort_keys=True) == \ json.dumps(c.decode(decoded_data), sort_keys=True) # noqa
def report(request, project_id=None): if request.method == 'POST': data = request.raw_post_data if not data: return HttpResponseBadRequest() try: decoded = json.loads(data) except json.JSONDecodeError: return HttpResponseBadRequest() response = HttpResponse() client.send(auth_header=extract_auth_vars(request), **decoded) elif request.method == 'OPTIONS': response = HttpResponse() return response
def report(request, project_id=None): if request.method == 'OPTIONS': return HttpResponse() if request.method == 'POST': if hasattr(request, 'body'): data = request.body else: data = request.raw_post_data else: data = request.GET.get('sentry_data') if not data: return HttpResponseBadRequest() try: decoded = json.loads(data.decode('utf8')) except json.JSONDecodeError: return HttpResponseBadRequest() client.send(auth_header=extract_auth_vars(request), **decoded) return HttpResponse()
def report(request, project_id=None): if request.method == 'OPTIONS': return HttpResponse() if request.method == 'POST': if hasattr(request, 'body'): data = request.body else: data = request.raw_post_data else: data = request.GET.get('sentry_data') if not data: return HttpResponseBadRequest() try: decoded = json.loads(data) except json.JSONDecodeError: return HttpResponseBadRequest() client.send(auth_header=extract_auth_vars(request), **decoded) return HttpResponse()
def report(request, project_id=None): if request.method == "OPTIONS": return HttpResponse() if request.method == "POST": if hasattr(request, "body"): data = request.body else: data = request.raw_post_data else: data = request.GET.get("sentry_data") if not data: return HttpResponseBadRequest() try: decoded = json.loads(data.decode("utf8")) except json.JSONDecodeError: return HttpResponseBadRequest() client.send(auth_header=extract_auth_vars(request), **decoded) return HttpResponse()
def decode(self, data): """ Unserializes a string, ``data``. """ return json.loads(zlib.decompress(data).decode('utf8'))
def decode(self, data): """ Unserializes a string, ``data``. """ return json.loads(base64.b64decode(data).decode('zlib'))
def decode(self, data): return json.loads(zlib.decompress(data).decode('utf8'))
def decode(self, data): """ Unserializes a string, ``data``. """ return json.loads(zlib.decompress(base64.b64decode(data)).decode("utf8"))