def get_token(self) -> str: """ return String, Int """ time = DateUtils.datetime_to_unix(datetime.datetime.now()) hash = hashlib.sha256( str(self.secret).encode("utf-8") + str(time).encode("utf-8") ).hexdigest() return "_".join([str(self.user_id), hash, str(time)])
def get_token(self) -> str: """ return String, Int """ time = DateUtils.datetime_to_unix(datetime.datetime.now()) hash = hashlib.sha256( str(self.secret).encode("utf-8") + str(time).encode("utf-8")).hexdigest() return "_".join([str(self.user_id), hash, str(time)])
def _get_renderer_url(self, stat_name, start_dt, end_dt=None, interval=INTERVAL_1_MINUTE, func=FUNCTION_SUM): url = self._get_graphite_endpoint() stat_name = stat_name + ".count" url += "/render?" url += "target=summarize(" + stat_name + ',"' + str( interval) + 'second","' + func + '",true)' url += "&from=" + str(DateUtils.datetime_to_unix(start_dt)) if end_dt: url += "&until=" + str(DateUtils.datetime_to_unix(end_dt)) url += "&format=json" return url
def parse(cls, token, max_time=3600): try: provider_id, hash, ts = token.split("_") now = DateUtils.datetime_to_unix(datetime.datetime.now()) if int(ts) + max_time < now: raise ExpiredTokenException() except ValueError: raise InvalidTokenException() return provider_id, hash, int(ts)
def json_helper(value): #stringifies otherwise non-json nodes try: value.set_context(context) return value.to_dict(True, optional_keys, for_api=True) except AttributeError: pass try: if isinstance(value, datetime.datetime): return DateUtils.datetime_to_unix(value) if stringify_remainder: return str(value) except AttributeError: pass raise TypeError()
def _stringify_id(self, value): # try int try: if value > Id.MAX_32_BIT_INT: return str(value) except (TypeError, AttributeError) as e: pass if isinstance(value, datetime.datetime): return DateUtils.datetime_to_unix(value) # try bytes try: return base64.standard_b64encode(value).decode("utf-8") except (TypeError, AttributeError) as e: pass return value
def set_date(self, dt=None): if dt is None: dt = datetime.datetime.now() self._ts = DateUtils.datetime_to_unix(dt) return self
def _add_in_extra_keys(self): self._data_dict["success"] = self._success self._data_dict["now_ts"] = DateUtils.datetime_to_unix() self._data_dict["v"] = SERVER_VERSION self._data_dict["min_v"] = MIN_SUPPORTED_CLIENTS