Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- #-------------------------------------------------------------------------------
- # Name: r_manager
- # Purpose:
- #
- # Author: User
- #
- # Created: 03.07.2020
- # Copyright: (c) User 2020
- # Licence: <your licence>
- #-------------------------------------------------------------------------------
- import itertools
- import time
- import datetime
- class RequestManager:
- def __init__(self, _dct=None):
- self._dict = _dct or {}
- self.removed = []
- self._next = (max(self._dict.keys()) + 1) if self._dict else 0
- def pop(self, key):
- val = self._dict.pop(key, None)
- if val: self.removed.append(key)
- return val
- def append(self, values):
- key = self._get_next()
- self._dict[key] = values
- return key
- def _get_next(self):
- if len(self.removed) > 0:
- key = self.removed.pop()
- return key
- else:
- _next = self._next
- self._next += 1
- return _next
- # has_key
- # del
- def main():
- d = {}
- for i in range(1000000): d[i]=(i+1, datetime.time)
- t = time.clock()
- r_manager = RequestManager(d)
- skey = 000001
- # (skey) # request_time, refresh_token
- # skey - секретный ключ
- # дата создания (нужна для очистки неиспользуемых ключей).
- r_manager.append((skey, datetime.time))
- print(time.clock() - t)
- t = time.clock()
- print r_manager.pop(1)
- print(time.clock() - t)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement