本文整理汇总了Python中sentry.utils.is_float函数的典型用法代码示例。如果您正苦于以下问题:Python is_float函数的具体用法?Python is_float怎么用?Python is_float使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了is_float函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_data_timestamp
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
示例2: process_data_timestamp
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
示例3: process_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']
示例4: process_data_timestamp
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
示例5: process_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):
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
示例6: _process_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 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
示例7: process_data_timestamp
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
示例8: abort
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)
示例9: abort
# 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 ""
示例10: abort
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 ''
示例11: abort
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 ""