# Path: newsmeme/extensions.py

# 
# Path: newsmeme/permissions.py

# 
# Path: newsmeme/models/permissions.py
# class Permissions(object):
# 
#     def __init__(self, obj):
#         self.obj = obj
# 
#     def __getattr__(self, name):
#         return getattr(self.obj, name)
# 
# Path: newsmeme/models/types.py
# class DenormalizedText(types.MutableType, types.TypeDecorator):
#     """
#     Stores denormalized primary keys that can be 
#     accessed as a set. 
# 
#     :param coerce: coercion function that ensures correct
#                    type is returned
# 
#     :param separator: separator character
#     """
# 
#     impl = types.Text
# 
#     def __init__(self, coerce=int, separator=" ", **kwargs):
# 
#         self.coerce = coerce
#         self.separator = separator
#         
#         super(DenormalizedText, self).__init__(**kwargs)
# 
#     def process_bind_param(self, value, dialect):
#         if value is not None:
#             items = [str(item).strip() for item in value]
#             value = self.separator.join(item for item in items if item)
#         return value
# 
#     def process_result_value(self, value, dialect):
#          if not value:
#             return set()
#          return set(self.coerce(item) \
#                    for item in value.split(self.separator))
#         
#     def copy_value(self, value):
#         return set(value)


import hashlib
from datetime import datetime
from werkzeug import generate_password_hash, check_password_hash, \
    cached_property
from flask.ext.sqlalchemy import BaseQuery
from flask.ext.principal import RoleNeed, UserNeed, Permission
from newsmeme.extensions import db
from newsmeme.permissions import null
from newsmeme.models.permissions import Permissions
from newsmeme.models.types import DenormalizedText

        if user:
            authenticated = user.check_openid(openid)
        else:
            authenticated = False

        return user, authenticated


class User(db.Model):

    __tablename__ = "users"

    query_class = UserQuery

    # user roles
    MEMBER = 100
    MODERATOR = 200
    ADMIN = 300

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.Unicode(60), unique=True, nullable=False)
    email = db.Column(db.String(150), unique=True, nullable=False)
    karma = db.Column(db.Integer, default=0)
    date_joined = db.Column(db.DateTime, default=datetime.utcnow)
    activation_key = db.Column(db.String(80), unique=True)
    role = db.Column(db.Integer, default=MEMBER)
    receive_email = db.Column(db.Boolean, default=False)
    email_alerts = db.Column(db.Boolean, default=False)
    followers = db.Column(DenormalizedText)

# Path: newsmeme/extensions.py

# 
# Path: newsmeme/permissions.py

# 
# Path: newsmeme/models/permissions.py
# class Permissions(object):
# 
#     def __init__(self, obj):
#         self.obj = obj
# 
#     def __getattr__(self, name):
#         return getattr(self.obj, name)
# 
# Path: newsmeme/models/types.py
# class DenormalizedText(types.MutableType, types.TypeDecorator):
#     """
#     Stores denormalized primary keys that can be 
#     accessed as a set. 
# 
#     :param coerce: coercion function that ensures correct
#                    type is returned
# 
#     :param separator: separator character
#     """
# 
#     impl = types.Text
# 
#     def __init__(self, coerce=int, separator=" ", **kwargs):
# 
#         self.coerce = coerce
#         self.separator = separator
#         
#         super(DenormalizedText, self).__init__(**kwargs)
# 
#     def process_bind_param(self, value, dialect):
#         if value is not None:
#             items = [str(item).strip() for item in value]
#             value = self.separator.join(item for item in items if item)
#         return value
# 
#     def process_result_value(self, value, dialect):
#          if not value:
#             return set()
#          return set(self.coerce(item) \
#                    for item in value.split(self.separator))
#         
#     def copy_value(self, value):
#         return set(value)


# Path: newsmeme/models/users.py
import hashlib
from datetime import datetime
from werkzeug import generate_password_hash, check_password_hash, \
    cached_property
from flask.ext.sqlalchemy import BaseQuery
from flask.ext.principal import RoleNeed, UserNeed, Permission
from newsmeme.extensions import db
from newsmeme.permissions import null
from newsmeme.models.permissions import Permissions
from newsmeme.models.types import DenormalizedText


        if user:
            authenticated = user.check_openid(openid)
        else:
            authenticated = False

        return user, authenticated


class User(db.Model):

    __tablename__ = "users"

    query_class = UserQuery

    # user roles
    MEMBER = 100
    MODERATOR = 200
    ADMIN = 300

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.Unicode(60), unique=True, nullable=False)
    email = db.Column(db.String(150), unique=True, nullable=False)
    karma = db.Column(db.Integer, default=0)
    date_joined = db.Column(db.DateTime, default=datetime.utcnow)
    activation_key = db.Column(db.String(80), unique=True)
    role = db.Column(db.Integer, default=MEMBER)
    receive_email = db.Column(db.Boolean, default=False)
    email_alerts = db.Column(db.Boolean, default=False)
    followers = db.Column(DenormalizedText)

    following = db.Column(DenormalizedText)