def remove_reference(self, name, expire=MARKER): file_path = self.get_reference_path(name) temporary_file_path = file_path + '.' + make_uuid_hash() move_file(file_path, temporary_file_path, retries=self.retries, retry_errno=self.retry_errno) references = self._get_references(temporary_file_path, name='') if name in references: references.remove(name) # Validate if references still exists if references: if expire is MARKER: # Dont use expire, we only need to know if file exists expire = None for name in references: path = self.get_file_path(name) if not self._contains(path, expire=expire): references.remove(name) if references: references = maybe_list(references) references.append(b_linesep) put_binary_on_file( file_path, binary=bytes_join(b_linesep, references), mode='ab', retries=self.retries, retry_errno=self.retry_errno) self._delete_path(temporary_file_path)
def put_reference(self, name): if name not in self.get_references(name): put_binary_on_file( self.get_reference_path(name), bytes_join(b_linesep, [name, '']), mode='ab', retries=self.retries, retry_errno=self.retry_errno)
def make_token_lock(request, token, session_id): return make_sha256( bytes_join( '-', [to_unicode(request.user_agent or ''), to_unicode(request.ip_address), to_unicode(token), to_unicode(session_id)]))
def replace_values(self, name, values, expire=MARKER): if not values: self.remove(name) else: values = maybe_list(values) values.append(b_linesep) self.put_binary( name, binary=bytes_join(b_linesep, values), expire=expire)
def make_unique_hash(length=64): code = u('') while len(code) < length: code += make_sha256_no_cache( bytes_join( '.', (uuid4().hex, str(NOW()), str(PROCESS_ID), str(DOMAIN_NAME)))) return code[:length]