# Path: whirlwind/db/mongo.py
# class Mongo(Singleton):
#     
#     db = None
#     
#     def __init__(self):
#         self.connection = None
#     
#     '''
#         register a collection of mongokit model objects
#     '''
#     def register_models(self,models):
#         self.connection.register(models)
#     
#     '''
#         Accessor for ui specific database.
#     '''   
#     @property
#     def ui(self):
#         return self.connection[options.db_name]
#     
#     '''
#         Useage:
#         from whirlwind.db.mongo import Mongo
#         Mongo.create(host='host.com', port='23423', username='mongouser', password='password')
#     '''
#     @staticmethod
#     def create(**kwargs):
#         db = Mongo()
#         db.connection = Connection(kwargs['host'],kwargs['port'])
#         Mongo.db = db
#         if 'debug' in kwargs:
#             print Mongo.db.connection


from mongokit import *
from whirlwind.db.mongo import Mongo
from tornado import options
import datetime
import hashlib, hmac, base64, re

'''
normalizes a username or email address
'''
def normalize(username):
    if not username :
        return None
    #allow legal email address
    name = username.strip().lower()
    name = re.sub(r'[^a-z0-9\\.\\@_\\-~#]+', '', name)
    name = re.sub('\\s+', '_',name)
    
    #don't allow $ and . because they screw up the db.
    name = name.replace(".", "")
    name = name.replace("$", "")
    return name;


# Path: whirlwind/db/mongo.py
# class Mongo(Singleton):
#     
#     db = None
#     
#     def __init__(self):
#         self.connection = None
#     
#     '''
#         register a collection of mongokit model objects
#     '''
#     def register_models(self,models):
#         self.connection.register(models)
#     
#     '''
#         Accessor for ui specific database.
#     '''   
#     @property
#     def ui(self):
#         return self.connection[options.db_name]
#     
#     '''
#         Useage:
#         from whirlwind.db.mongo import Mongo
#         Mongo.create(host='host.com', port='23423', username='mongouser', password='password')
#     '''
#     @staticmethod
#     def create(**kwargs):
#         db = Mongo()
#         db.connection = Connection(kwargs['host'],kwargs['port'])
#         Mongo.db = db
#         if 'debug' in kwargs:
#             print Mongo.db.connection


# Path: whirlwind/conf/app_template/application/models/user.py
from mongokit import *
from whirlwind.db.mongo import Mongo
from tornado import options
import datetime
import hashlib, hmac, base64, re


'''
normalizes a username or email address
'''
def normalize(username):
    if not username :
        return None
    #allow legal email address
    name = username.strip().lower()
    name = re.sub(r'[^a-z0-9\\.\\@_\\-~#]+', '', name)
    name = re.sub('\\s+', '_',name)
    
    #don't allow $ and . because they screw up the db.
    name = name.replace(".", "")
    name = name.replace("$", "")
    return name;


@Mongo.db.connection.register