# Path: bnw/core/bnw_objects.py
# class WrappedDict(object):
# class CollectionWrapper(object):
# class MongoObjectCollectionProxy(type):
# class MongoObject(WrappedDict):
# class Message(MongoObject):
# class FeedElement(MongoObject):
# class Comment(MongoObject):
# class User(MongoObject):
# class Subscription(MongoObject):
# class GlobalState(MongoObject):
# class Club(MongoObject):
# class StatMessages(MongoObject):
# class StatComments(MongoObject):
# class StatCharacters(MongoObject):
# class Tag(MongoObject):
# class Today(MongoObject):
# class Timing(MongoObject):
# class Throttle(MongoObject):
# class UserTag(Tag):
#     def __getitem__(self, name):
#     def __setitem__(self, name, value):
#     def __delitem__(self, name):
#     def __contains__(self, name):
#     def items(self):
#     def iteritems(self):
#     def get(self, k, d=None):
#     def update(self, E, **F):
#     def __repr__(self):
#     def __str__(self):
#     def __unicode__(self):
# def fudef(future):
#     def future_callback(f):
# def fudef(future):
#     def future_callback(f):
#     def __init__(self, collection_name):
#     def __getattr__(self, db_method):
#         def fn(*args, **kwargs):
#     def __getattr__(self, mongo_method):
#     def __init__(self, src=None):
#     def count(cls, *args, **kwargs):
#     def find_one(cls, *args, **kwargs):
#     def find(cls, *args, **kwargs):
#     def find_sort(cls, spec, sort, **kwargs):
#     def mupdate(cls, spec, document, *args, **kwargs):
#     def save(cls, w=1):
#     def ensure_indexes(cls):
#     def filter_fields(self):
#     def aggregate(cls, *args, **kwargs):
#     def save(self, safe=True):
#     def deliver(self, target, recommender=None, recocomment=None, sfrom=None):
#     def save(self, safe=True):
#     def deliver(self, target, recommender=None, recocomment=None, sfrom=None):
#     def send_plain(self, message, sfrom=None):
#     def activity(self):
# def massert(condition,code="assert"):
#     def is_remote(self):
#     def subscribe(cls, user, target_type, target, safe=True, sfrom=None):
#     def unsubscribe(self, user, target_type, target, safe=True):
# INDEX_TTL = 946080000  # one year. i don't think you will ever need to change this
# 
# Path: bnw/core/base.py
# def genid(idlen):
# def cropstring(string, maxlen):
# def _(s, user):
# def get_webui_base(user):
# def get_https_webui_base():
# def get_http_webui_base():
# class BnwResponse(Exception):  # we do it idiotic way!


import base64
import bnw.core.base
import bnw.core.bnw_mongo
from cStringIO import StringIO
from twisted.words.xish import domish
from twisted.internet import defer, reactor
from twisted.internet.threads import deferToThread
from twisted.web.client import Agent
from twisted.web.http_headers import Headers
from twisted.web.iweb import IBodyProducer
from zope.interface import implements
from tornado.escape import utf8
from PIL import Image
from base import send_raw
from bnw.core import bnw_objects as objs
from bnw.core.base import config
        im.thumbnail((48, 48), Image.ANTIALIAS)
        thumb_f = StringIO()
        im.save(thumb_f, 'png')
    except IOError:
        return
    return avatar, mimetype, thumb_f.getvalue()


@defer.inlineCallbacks
def vcard(iq, iq_user):
    if (not iq.vCard) or iq['type'] != 'result':
        defer.returnValue(False)
    if not iq_user:
        # User which have been sent IQ not registered.
        defer.returnValue(True)
    v = iq.vCard
    # Update avatar info.
    av_info = iq_user.get('avatar')
    av_key = 'avatars/' + iq_user['name']
    if v.PHOTO and config.blob_storage:
        res = yield deferToThread(get_and_resize_avatar, iq)
        if res:
            avatar, mimetype, thumb = res
            yield agent.request('PUT',utf8(config.blob_storage+'put/'+av_key),
                Headers({'Content-Type': [mimetype]}), StringProducer(avatar))
            yield agent.request('PUT',utf8(config.blob_storage+'put/'+av_key+'/thumb'),
                Headers({'Content-Type': ['image/png']}), StringProducer(thumb))
            yield objs.User.mupdate(
                {'name': iq_user['name']},
                    {'$set': {'avatar': 'blobstorage'}})

# Path: bnw/core/bnw_objects.py
# class WrappedDict(object):
# class CollectionWrapper(object):
# class MongoObjectCollectionProxy(type):
# class MongoObject(WrappedDict):
# class Message(MongoObject):
# class FeedElement(MongoObject):
# class Comment(MongoObject):
# class User(MongoObject):
# class Subscription(MongoObject):
# class GlobalState(MongoObject):
# class Club(MongoObject):
# class StatMessages(MongoObject):
# class StatComments(MongoObject):
# class StatCharacters(MongoObject):
# class Tag(MongoObject):
# class Today(MongoObject):
# class Timing(MongoObject):
# class Throttle(MongoObject):
# class UserTag(Tag):
#     def __getitem__(self, name):
#     def __setitem__(self, name, value):
#     def __delitem__(self, name):
#     def __contains__(self, name):
#     def items(self):
#     def iteritems(self):
#     def get(self, k, d=None):
#     def update(self, E, **F):
#     def __repr__(self):
#     def __str__(self):
#     def __unicode__(self):
# def fudef(future):
#     def future_callback(f):
# def fudef(future):
#     def future_callback(f):
#     def __init__(self, collection_name):
#     def __getattr__(self, db_method):
#         def fn(*args, **kwargs):
#     def __getattr__(self, mongo_method):
#     def __init__(self, src=None):
#     def count(cls, *args, **kwargs):
#     def find_one(cls, *args, **kwargs):
#     def find(cls, *args, **kwargs):
#     def find_sort(cls, spec, sort, **kwargs):
#     def mupdate(cls, spec, document, *args, **kwargs):
#     def save(cls, w=1):
#     def ensure_indexes(cls):
#     def filter_fields(self):
#     def aggregate(cls, *args, **kwargs):
#     def save(self, safe=True):
#     def deliver(self, target, recommender=None, recocomment=None, sfrom=None):
#     def save(self, safe=True):
#     def deliver(self, target, recommender=None, recocomment=None, sfrom=None):
#     def send_plain(self, message, sfrom=None):
#     def activity(self):
# def massert(condition,code="assert"):
#     def is_remote(self):
#     def subscribe(cls, user, target_type, target, safe=True, sfrom=None):
#     def unsubscribe(self, user, target_type, target, safe=True):
# INDEX_TTL = 946080000  # one year. i don't think you will ever need to change this
# 
# Path: bnw/core/base.py
# def genid(idlen):
# def cropstring(string, maxlen):
# def _(s, user):
# def get_webui_base(user):
# def get_https_webui_base():
# def get_http_webui_base():
# class BnwResponse(Exception):  # we do it idiotic way!


# Path: bnw/xmpp/iq_handlers.py
import base64
import bnw.core.base
import bnw.core.bnw_mongo
from cStringIO import StringIO
from twisted.words.xish import domish
from twisted.internet import defer, reactor
from twisted.internet.threads import deferToThread
from twisted.web.client import Agent
from twisted.web.http_headers import Headers
from twisted.web.iweb import IBodyProducer
from zope.interface import implements
from tornado.escape import utf8
from PIL import Image
from base import send_raw
from bnw.core import bnw_objects as objs
from bnw.core.base import config

        im.thumbnail((48, 48), Image.ANTIALIAS)
        thumb_f = StringIO()
        im.save(thumb_f, 'png')
    except IOError:
        return
    return avatar, mimetype, thumb_f.getvalue()


@defer.inlineCallbacks
def vcard(iq, iq_user):
    if (not iq.vCard) or iq['type'] != 'result':
        defer.returnValue(False)
    if not iq_user:
        # User which have been sent IQ not registered.
        defer.returnValue(True)
    v = iq.vCard
    # Update avatar info.
    av_info = iq_user.get('avatar')
    av_key = 'avatars/' + iq_user['name']
    if v.PHOTO and config.blob_storage:
        res = yield deferToThread(get_and_resize_avatar, iq)
        if res:
            avatar, mimetype, thumb = res
            yield agent.request('PUT',utf8(config.blob_storage+'put/'+av_key),
                Headers({'Content-Type': [mimetype]}), StringProducer(avatar))
            yield agent.request('PUT',utf8(config.blob_storage+'put/'+av_key+'/thumb'),
                Headers({'Content-Type': ['image/png']}), StringProducer(thumb))
            yield objs.User.mupdate(
                {'name': iq_user['name']},
                    {'$set': {'avatar': 'blobstorage'}})

    elif av_info and config.blob_storage: