def process_data_timestamp(data, current_datetime=None): if is_float(data['timestamp']): try: data['timestamp'] = datetime.fromtimestamp(float(data['timestamp'])) except Exception: raise InvalidTimestamp('Invalid value for timestamp: %r' % data['timestamp']) elif not isinstance(data['timestamp'], datetime): if '.' in data['timestamp']: format = '%Y-%m-%dT%H:%M:%S.%f' else: format = '%Y-%m-%dT%H:%M:%S' if 'Z' in data['timestamp']: # support UTC market, but not other timestamps format += 'Z' try: data['timestamp'] = datetime.strptime(data['timestamp'], format) except Exception: raise InvalidTimestamp('Invalid value for timestamp: %r' % data['timestamp']) if current_datetime is None: current_datetime = datetime.now() if data['timestamp'] > current_datetime + timedelta(minutes=1): raise InvalidTimestamp('Invalid value for timestamp (in future): %r' % data['timestamp']) if data['timestamp'] < current_datetime - timedelta(days=30): raise InvalidTimestamp('Invalid value for timestamp (too old): %r' % data['timestamp']) data['timestamp'] = float(data['timestamp'].strftime('%s')) return data
def process_data_timestamp(data, current_datetime=None): if is_float(data["timestamp"]): try: data["timestamp"] = datetime.fromtimestamp(float(data["timestamp"])) except Exception: raise InvalidTimestamp("Invalid value for timestamp: %r" % data["timestamp"]) elif not isinstance(data["timestamp"], datetime): if "." in data["timestamp"]: format = "%Y-%m-%dT%H:%M:%S.%f" else: format = "%Y-%m-%dT%H:%M:%S" if "Z" in data["timestamp"]: # support UTC market, but not other timestamps format += "Z" try: data["timestamp"] = datetime.strptime(data["timestamp"], format) except Exception: raise InvalidTimestamp("Invalid value for timestamp: %r" % data["timestamp"]) if current_datetime is None: current_datetime = datetime.now() if data["timestamp"] > current_datetime + timedelta(minutes=1): raise InvalidTimestamp("Invalid value for timestamp (in future): %r" % data["timestamp"]) if data["timestamp"] < current_datetime - timedelta(days=30): raise InvalidTimestamp("Invalid value for timestamp (too old): %r" % data["timestamp"]) data["timestamp"] = float(data["timestamp"].strftime("%s")) return data
def process_data_timestamp(data, current_datetime=None): if is_float(data['timestamp']): try: data['timestamp'] = datetime.fromtimestamp(float( data['timestamp'])) except Exception: raise InvalidTimestamp('Invalid value for timestamp: %r' % data['timestamp']) elif not isinstance(data['timestamp'], datetime): if '.' in data['timestamp']: format = '%Y-%m-%dT%H:%M:%S.%f' else: format = '%Y-%m-%dT%H:%M:%S' if 'Z' in data['timestamp']: # support UTC market, but not other timestamps format += 'Z' try: data['timestamp'] = datetime.strptime(data['timestamp'], format) except Exception: raise InvalidTimestamp('Invalid value for timestamp: %r' % data['timestamp']) if current_datetime is None: current_datetime = datetime.now() if data['timestamp'] > current_datetime + timedelta(minutes=1): raise InvalidTimestamp('Invalid value for timestamp (in future): %r' % data['timestamp']) if data['timestamp'] < current_datetime - timedelta(days=30): raise InvalidTimestamp('Invalid value for timestamp (too old): %r' % data['timestamp']) return data
def process_data_timestamp(data): if is_float(data['timestamp']): try: data['timestamp'] = datetime.fromtimestamp( float(data['timestamp'])) except Exception: raise InvalidTimestamp( 'Invalid value for timestamp: %r' % data['timestamp']) elif not isinstance(data['timestamp'], datetime): if '.' in data['timestamp']: format = '%Y-%m-%dT%H:%M:%S.%f' else: format = '%Y-%m-%dT%H:%M:%S' if 'Z' in data['timestamp']: # support UTC market, but not other timestamps format += 'Z' try: data['timestamp'] = datetime.strptime(data['timestamp'], format) except Exception: raise InvalidTimestamp( 'Invalid value for timestamp: %r' % data['timestamp']) if data['timestamp'] > datetime.now() + timedelta(minutes=1): raise InvalidTimestamp( 'Invalid value for timestamp (in future): %r' % data['timestamp']) return data
def process_data_timestamp(data): if is_float(data['timestamp']): try: data['timestamp'] = datetime.fromtimestamp(float(data['timestamp'])) except: logger.exception('Failed reading timestamp') del data['timestamp'] elif not isinstance(data['timestamp'], datetime): try: data['timestamp'] = dateutil.parser.parse(data['timestamp']) except: logger.exception('Failed reading timestamp') del data['timestamp']
def process_data_timestamp(data): if is_float(data['timestamp']): try: data['timestamp'] = datetime.fromtimestamp( float(data['timestamp'])) except: logger.exception('Failed reading timestamp') del data['timestamp'] elif not isinstance(data['timestamp'], datetime): try: data['timestamp'] = dateutil.parser.parse(data['timestamp']) except: logger.exception('Failed reading timestamp') del data['timestamp']
def _process_data_timestamp(self, data, current_datetime=None): value = data['timestamp'] if not value: del data['timestamp'] return data elif is_float(value): try: value = datetime.fromtimestamp(float(value)) except Exception: raise InvalidTimestamp('Invalid value for timestamp: %r' % data['timestamp']) elif not isinstance(value, datetime): # all timestamps are in UTC, but the marker is optional if 'Z' in value: value = data['timestamp'][:-1] if '.' in value: # Python doesn't support long microsecond values # https://github.com/getsentry/sentry/issues/1610 ts_bits = value.split('.', 1) value = '%s.%s' % (ts_bits[0], ts_bits[1][:2]) fmt = '%Y-%m-%dT%H:%M:%S.%f' else: fmt = '%Y-%m-%dT%H:%M:%S' try: value = datetime.strptime(value, fmt) except Exception: raise InvalidTimestamp('Invalid value for timestamp: %r' % data['timestamp']) if current_datetime is None: current_datetime = datetime.now() if value > current_datetime + timedelta(minutes=1): raise InvalidTimestamp( 'Invalid value for timestamp (in future): %r' % value) if value < current_datetime - timedelta(days=30): raise InvalidTimestamp( 'Invalid value for timestamp (too old): %r' % value) data['timestamp'] = float(value.strftime('%s')) return data
def process_data_timestamp(data): if is_float(data['timestamp']): try: data['timestamp'] = datetime.fromtimestamp(float(data['timestamp'])) except Exception: logger.exception('Failed reading timestamp') del data['timestamp'] elif not isinstance(data['timestamp'], datetime): if '.' in data['timestamp']: format = '%Y-%m-%dT%H:%M:%S.%f' else: format = '%Y-%m-%dT%H:%M:%S' if 'Z' in data['timestamp']: # support UTC market, but not other timestamps format += 'Z' try: data['timestamp'] = datetime.strptime(data['timestamp'], format) except Exception: raise InvalidTimestamp('Invalid value for timestamp: %r' % data['timestamp']) return data
def process_data_timestamp(data): if is_float(data["timestamp"]): try: data["timestamp"] = datetime.fromtimestamp(float(data["timestamp"])) except: logger.exception("Failed reading timestamp") del data["timestamp"] elif not isinstance(data["timestamp"], datetime): if "." in data["timestamp"]: format = "%Y-%m-%dT%H:%M:%S.%f" else: format = "%Y-%m-%dT%H:%M:%S" if "Z" in data["timestamp"]: # support UTC market, but not other timestamps format += "Z" try: data["timestamp"] = datetime.strptime(data["timestamp"], format) except: raise InvalidTimestamp("Invalid value for timestamp: %r" % data["timestamp"]) return data
def _process_data_timestamp(self, data, current_datetime=None): value = data['timestamp'] if not value: del data['timestamp'] return data elif is_float(value): try: value = datetime.fromtimestamp(float(value)) except Exception: raise InvalidTimestamp('Invalid value for timestamp: %r' % data['timestamp']) elif not isinstance(value, datetime): # all timestamps are in UTC, but the marker is optional if value.endswith('Z'): value = value[:-1] if '.' in value: # Python doesn't support long microsecond values # https://github.com/getsentry/sentry/issues/1610 ts_bits = value.split('.', 1) value = '%s.%s' % (ts_bits[0], ts_bits[1][:2]) fmt = '%Y-%m-%dT%H:%M:%S.%f' else: fmt = '%Y-%m-%dT%H:%M:%S' try: value = datetime.strptime(value, fmt) except Exception: raise InvalidTimestamp('Invalid value for timestamp: %r' % data['timestamp']) if current_datetime is None: current_datetime = datetime.now() if value > current_datetime + timedelta(minutes=1): raise InvalidTimestamp('Invalid value for timestamp (in future): %r' % value) if value < current_datetime - timedelta(days=30): raise InvalidTimestamp('Invalid value for timestamp (too old): %r' % value) data['timestamp'] = float(value.strftime('%s')) return data
def process_data_timestamp(data): if is_float(data['timestamp']): try: data['timestamp'] = datetime.fromtimestamp(float( data['timestamp'])) except Exception: logger.exception('Failed reading timestamp') del data['timestamp'] elif not isinstance(data['timestamp'], datetime): if '.' in data['timestamp']: format = '%Y-%m-%dT%H:%M:%S.%f' else: format = '%Y-%m-%dT%H:%M:%S' if 'Z' in data['timestamp']: # support UTC market, but not other timestamps format += 'Z' try: data['timestamp'] = datetime.strptime(data['timestamp'], format) except Exception: raise InvalidTimestamp('Invalid value for timestamp: %r' % data['timestamp']) return data
def process_data_timestamp(data): if is_float(data["timestamp"]): try: data["timestamp"] = datetime.fromtimestamp(float(data["timestamp"])) except Exception: raise InvalidTimestamp("Invalid value for timestamp: %r" % data["timestamp"]) elif not isinstance(data["timestamp"], datetime): if "." in data["timestamp"]: format = "%Y-%m-%dT%H:%M:%S.%f" else: format = "%Y-%m-%dT%H:%M:%S" if "Z" in data["timestamp"]: # support UTC market, but not other timestamps format += "Z" try: data["timestamp"] = datetime.strptime(data["timestamp"], format) except Exception: raise InvalidTimestamp("Invalid value for timestamp: %r" % data["timestamp"]) if data["timestamp"] > datetime.now() + timedelta(minutes=1): raise InvalidTimestamp("Invalid value for timestamp (in future): %r" % data["timestamp"]) return data
# This error should be caught as it suggests that there's a # bug somewhere in the client's code. logger.exception("Bad data received") abort(400, "Bad data decoding request (%s, %s)" % (e.__class__.__name__, e)) try: data = simplejson.loads(data) except Exception, e: # This error should be caught as it suggests that there's a # bug somewhere in the client's code. logger.exception("Bad data received") abort(403, "Bad data reconstructing object (%s, %s)" % (e.__class__.__name__, e)) # XXX: ensure keys are coerced to strings data = dict((str(k), v) for k, v in data.iteritems()) if "timestamp" in data: if is_float(data["timestamp"]): data["timestamp"] = datetime.datetime.fromtimestamp(float(data["timestamp"])) else: if "." in data["timestamp"]: format = "%Y-%m-%dT%H:%M:%S.%f" else: format = "%Y-%m-%dT%H:%M:%S" data["timestamp"] = datetime.datetime.strptime(data["timestamp"], format) # TODO store() return ""
logger.exception('Bad data received') abort(400, 'Bad data decoding request (%s, %s)' % (e.__class__.__name__, e)) try: data = simplejson.loads(data) except Exception, e: # This error should be caught as it suggests that there's a # bug somewhere in the client's code. logger.exception('Bad data received') abort( 403, 'Bad data reconstructing object (%s, %s)' % (e.__class__.__name__, e)) # XXX: ensure keys are coerced to strings data = dict((str(k), v) for k, v in data.iteritems()) if 'date' in data: if is_float(data['date']): data['date'] = datetime.datetime.fromtimestamp(float(data['date'])) else: if '.' in data['date']: format = '%Y-%m-%dT%H:%M:%S.%f' else: format = '%Y-%m-%dT%H:%M:%S' data['date'] = datetime.datetime.strptime(data['date'], format) event, group = app.client.store(**data) return event.pk
except Exception, e: # This error should be caught as it suggests that there's a # bug somewhere in the client's code. logger.exception("Bad data received") abort(400, "Bad data decoding request (%s, %s)" % (e.__class__.__name__, e)) try: data = simplejson.loads(data) except Exception, e: # This error should be caught as it suggests that there's a # bug somewhere in the client's code. logger.exception("Bad data received") abort(403, "Bad data reconstructing object (%s, %s)" % (e.__class__.__name__, e)) # XXX: ensure keys are coerced to strings data = dict((str(k), v) for k, v in data.iteritems()) if "date" in data: if is_float(data["date"]): data["date"] = datetime.datetime.fromtimestamp(float(data["date"])) else: if "." in data["date"]: format = "%Y-%m-%dT%H:%M:%S.%f" else: format = "%Y-%m-%dT%H:%M:%S" data["date"] = datetime.datetime.strptime(data["date"], format) app.client.store(**data) return ""
try: if format == 'pickle': data = pickle.loads(data) elif format == 'json': data = simplejson.loads(data) except Exception, e: # This error should be caught as it suggests that there's a # bug somewhere in the client's code. logger.exception('Bad data received') abort(403, 'Bad data reconstructing object (%s, %s)' % (e.__class__.__name__, e)) # XXX: ensure keys are coerced to strings data = dict((smart_str(k), v) for k, v in data.iteritems()) if 'timestamp' in data: if is_float(data['timestamp']): data['timestamp'] = datetime.datetime.fromtimestamp(float(data['timestamp'])) else: if '.' in data['timestamp']: format = '%Y-%m-%dT%H:%M:%S.%f' else: format = '%Y-%m-%dT%H:%M:%S' data['timestamp'] = datetime.datetime.strptime(data['timestamp'], format) GroupedMessage.objects.from_kwargs(**data) return '' @login_required def group_plugin_action(request, group_id, slug): group = get_object_or_404(GroupedMessage, pk=group_id)
data = base64.b64decode(data).decode('zlib') except Exception, e: # This error should be caught as it suggests that there's a # bug somewhere in the client's code. logger.exception('Bad data received') abort(400, 'Bad data decoding request (%s, %s)' % (e.__class__.__name__, e)) try: data = simplejson.loads(data) except Exception, e: # This error should be caught as it suggests that there's a # bug somewhere in the client's code. logger.exception('Bad data received') abort(403, 'Bad data reconstructing object (%s, %s)' % (e.__class__.__name__, e)) # XXX: ensure keys are coerced to strings data = dict((str(k), v) for k, v in data.iteritems()) if 'date' in data: if is_float(data['date']): data['date'] = datetime.datetime.fromtimestamp(float(data['date'])) else: if '.' in data['date']: format = '%Y-%m-%dT%H:%M:%S.%f' else: format = '%Y-%m-%dT%H:%M:%S' data['date'] = datetime.datetime.strptime(data['date'], format) app.client.store(**data) return ''
data = pickle.loads(data) elif format == 'json': data = json.loads(data) except Exception, e: # This error should be caught as it suggests that there's a # bug somewhere in the client's code. logger.exception('Bad data received') return HttpResponseForbidden( 'Bad data reconstructing object (%s, %s)' % (e.__class__.__name__, e)) # XXX: ensure keys are coerced to strings data = dict((smart_str(k), v) for k, v in data.iteritems()) if 'timestamp' in data: if is_float(data['timestamp']): try: data['timestamp'] = datetime.datetime.fromtimestamp( float(data['timestamp'])) except: logger.exception('Failed reading timestamp') del data['timestamp'] elif not isinstance(data['timestamp'], datetime.datetime): if '.' in data['timestamp']: format = '%Y-%m-%dT%H:%M:%S.%f' else: format = '%Y-%m-%dT%H:%M:%S' if 'Z' in data['timestamp']: # support GMT market, but not other timestamps format += 'Z' try: