def _compare_by_hash(self, update_hash=False): md5 = hashlib.new('md5') key = str(self.user.key()) for item in self.netprint.list(): md5.update(item.id or '') namespace = get_namespace() digest = md5.hexdigest() previous_digest = memcache.get(key, namespace=namespace) logging.debug('Generated digest is %s, and cached is %s', digest, previous_digest) changed = digest != previous_digest if update_hash and changed: memcache.set(key, digest, namespace=namespace) return changed
def test_do_not_make_report_if_no_change(self): import hashlib from google.appengine.api import memcache from netprintbox.data import FileState from netprintbox.utils import ( normalize_name, get_namespace) NETPRINT_ID = 'latest' ORIGINAL_PATH = '/latest.data' NETPRINT_NAME = normalize_name(ORIGINAL_PATH) user = create_user() create_file_info(user, path=ORIGINAL_PATH, netprint_id=NETPRINT_ID, netprint_name=NETPRINT_NAME, state=FileState.LATEST) class netprint(object): @staticmethod def list(): return [ create_netprint_item( id=NETPRINT_ID, name=NETPRINT_NAME) ] md5 = hashlib.new('md5') md5.update(NETPRINT_ID) memcache.set(str(user.key()), md5.hexdigest(), namespace=get_namespace()) service = self._getOUT(user) service.netprint = netprint (need_report, _result) = service._make_report() self.assertFalse(need_report) # check no exception is occurred. service.make_report()
def delete(key): logging.debug(u"Deleting token by key: %s", key) memcache.delete(key, namespace=get_namespace())
def put(self): if self.key is None or self.token is None: raise ValueError logging.debug(u"Saving token: %s", self.token) memcache.set(self.key, str(self.token), namespace=get_namespace())
def get(key): logging.debug(u"Getting token by key: %s", key) return OAuthToken.from_string( memcache.get(key, namespace=get_namespace()))