# Path: OSMPythonTools/cachingStrategy/strategy.py
# class CachingStrategy():
#     __strategy = JSON()
#     @classmethod
#     def use(cls, strategy, **kwargs):
#         cls.__strategy.close()
#         cls.__strategy = strategy(**kwargs)
#         return cls.__strategy
#     @classmethod
#     def get(cls, key):
#         return cls.__strategy.get(key)
#     @classmethod
#     def set(cls, key, value):
#         cls.__strategy.set(key, value)


import datetime
import hashlib
import os
import time
import ujson
import urllib.request
import OSMPythonTools
from OSMPythonTools.cachingStrategy import CachingStrategy


class CacheObject:
    def __init__(self, prefix, endpoint, waitBetweenQueries=None, jsonResult=True, userAgent=None):
        self._prefix = prefix
        self._endpoint = endpoint
        self.__waitBetweenQueries = waitBetweenQueries
        self.__lastQuery = None
        self.__jsonResult = jsonResult
        self.__userAgentProvidedByUser = userAgent
    
    def query(self, *args, onlyCached=False, shallow=False, **kwargs):
        queryString, hashString, params = self._queryString(*args, **kwargs)
        key = self._prefix + '-' + self.__hash(hashString + ('????' + urllib.parse.urlencode(sorted(params.items())) if params else ''))

# Path: OSMPythonTools/cachingStrategy/strategy.py
# class CachingStrategy():
#     __strategy = JSON()
#     @classmethod
#     def use(cls, strategy, **kwargs):
#         cls.__strategy.close()
#         cls.__strategy = strategy(**kwargs)
#         return cls.__strategy
#     @classmethod
#     def get(cls, key):
#         return cls.__strategy.get(key)
#     @classmethod
#     def set(cls, key, value):
#         cls.__strategy.set(key, value)


# Path: OSMPythonTools/internal/cacheObject.py
import datetime
import hashlib
import os
import time
import ujson
import urllib.request
import OSMPythonTools
from OSMPythonTools.cachingStrategy import CachingStrategy



class CacheObject:
    def __init__(self, prefix, endpoint, waitBetweenQueries=None, jsonResult=True, userAgent=None):
        self._prefix = prefix
        self._endpoint = endpoint
        self.__waitBetweenQueries = waitBetweenQueries
        self.__lastQuery = None
        self.__jsonResult = jsonResult
        self.__userAgentProvidedByUser = userAgent
    
    def query(self, *args, onlyCached=False, shallow=False, **kwargs):
        queryString, hashString, params = self._queryString(*args, **kwargs)
        key = self._prefix + '-' + self.__hash(hashString + ('????' + urllib.parse.urlencode(sorted(params.items())) if params else ''))

        data = CachingStrategy.get(key)