# Path: wire/utils.py
# def autoinc(redis, key):
#     key = "_incs:%s" % key
#     if not redis.exists(key):
#         redis.set(key, 0)
# 
#     return redis.incr(key)
# 
# Path: wire/utils.py
# class Hasher:
#     def __init__(self, strength=16):
#         self._strength = strength
# 
#     def hash(self, password, salt=False, encode=True):
#         if salt is False:
#             salt = urandom(32)
#         if encode:
#             salt = b64encode(salt)
#         return "$w$%s$%s$%s" % (
#             self._strength,
#             salt,
#             self._hash_multi(salt + password, self._strength)
#         )
# 
#     def check(self, attempt, h):
#         bits = h.split("$")
#         try:
#             if self._hash_multi(bits[3] + attempt, float(bits[2])) != bits[4]:
#                 raise HashMismatch()
#         except IndexError:
#             raise HashMismatch()
# 
#     def _hash_multi(self, string, strength):
#         for i in range(int(math.pow(2, strength))):
#             string = b2a_hex(whirlpool.hash(string))
#         return string


import copy
import json
import re
from datetime import datetime, time, date
from wire.utils import autoinc
from wire.utils import Hasher
                pass
            self.messages.append(m)
        if len(self.messages) < 1:
            self.delete()
            raise DestroyedThreadError
        try:
            self.sender = self.messages[0].data['sender']
        except KeyError:
            self.delete_message(self.messages[0])

    def delete(self, recipient=False):
        r = self.redis
        if recipient:
            r.lrem('user:%s:threads' % recipient.key, self.key, 0)
        if self.recipients:
            for recipient_key in self.recipients:
                r.lrem('user:%s:threads' % recipient_key, self.key, 0)
                r.delete('user:%s:thread:%s:unreads' % \
                    (recipient_key, self.key))

        [m.delete() for m in self.messages]

        r.delete('thread:%s:data' % self.key)
        r.delete('thread:%s:recipients' % self.key)
        r.delete('thread:%s:messages' % self.key)

    def unsubscribe(self):
        r = self.redis
        r.lrem('thread:%s:recipients' % self.key, self.user.key, 0)
        r.lrem('user:%s:threads' % self.user.key, self.key, 0)

# Path: wire/utils.py
# def autoinc(redis, key):
#     key = "_incs:%s" % key
#     if not redis.exists(key):
#         redis.set(key, 0)
# 
#     return redis.incr(key)
# 
# Path: wire/utils.py
# class Hasher:
#     def __init__(self, strength=16):
#         self._strength = strength
# 
#     def hash(self, password, salt=False, encode=True):
#         if salt is False:
#             salt = urandom(32)
#         if encode:
#             salt = b64encode(salt)
#         return "$w$%s$%s$%s" % (
#             self._strength,
#             salt,
#             self._hash_multi(salt + password, self._strength)
#         )
# 
#     def check(self, attempt, h):
#         bits = h.split("$")
#         try:
#             if self._hash_multi(bits[3] + attempt, float(bits[2])) != bits[4]:
#                 raise HashMismatch()
#         except IndexError:
#             raise HashMismatch()
# 
#     def _hash_multi(self, string, strength):
#         for i in range(int(math.pow(2, strength))):
#             string = b2a_hex(whirlpool.hash(string))
#         return string


# Path: wire/models.py
import copy
import json
import re
from datetime import datetime, time, date
from wire.utils import autoinc
from wire.utils import Hasher

                pass
            self.messages.append(m)
        if len(self.messages) < 1:
            self.delete()
            raise DestroyedThreadError
        try:
            self.sender = self.messages[0].data['sender']
        except KeyError:
            self.delete_message(self.messages[0])

    def delete(self, recipient=False):
        r = self.redis
        if recipient:
            r.lrem('user:%s:threads' % recipient.key, self.key, 0)
        if self.recipients:
            for recipient_key in self.recipients:
                r.lrem('user:%s:threads' % recipient_key, self.key, 0)
                r.delete('user:%s:thread:%s:unreads' % \
                    (recipient_key, self.key))

        [m.delete() for m in self.messages]

        r.delete('thread:%s:data' % self.key)
        r.delete('thread:%s:recipients' % self.key)
        r.delete('thread:%s:messages' % self.key)

    def unsubscribe(self):
        r = self.redis
        r.lrem('thread:%s:recipients' % self.key, self.user.key, 0)
        r.lrem('user:%s:threads' % self.user.key, self.key, 0)

        self._update_recipients()