# Path: common/models.py
# PRIVACY_PRIVATE = 1
# PRIVACY_CONTACTS = 2
# PRIVACY_PUBLIC = 3
# ACTOR_ALLOWED_EXTRA = ('contact_count', 
#                        'follower_count', 
#                        'icon', 
#                        'description',
#                        'member_count', 
#                        'admin_count', 
#                        'given_name', 
#                        'family_name'
#                        )
# ACTOR_LIMITED_EXTRA = ('icon', 
#                        'description',
#                        'given_name', 
#                        'family_name'
#                        )
# def _get_actor_type_from_nick(nick):
# def _get_actor_urlnick_from_nick(nick):
# def _to_api(v):
#   def to_api(self):
#   def __init__(self, parent=None, key_name=None, _app=None, **kw):
#   def key_from(cls, **kw):
#   def _remove_from_cache(self):
#   def put(self):
#   def save(self):
#   def delete(self):
#   def get_by_key_name(cls, key_names, parent=None):
#   def db_get_count(cls):
#   def reset_cache(cls):
#   def enable_cache(cls, enabled = True):
#   def reset_get_count(cls):
#   def gql(cls, *args, **kw):
#   def Query(cls):
#   def mark_as_deleted(self):
#   def is_deleted(self):
# def actor_url(nick, actor_type, path='', request=None, mobile=False):
#   def url(self, path="", request=None, mobile=False):
#   def shortnick(self):
#   def display_nick(self):
#   def to_api(self):
#   def to_api_limited(self):
#   def is_channel(self):
#   def is_public(self):
#   def is_restricted(self):
#   def __repr__(self):
#   def stream_entry_keyname(self):
#   def to_string(self):
#   def url(self):
#   def to_string(self):
#   def is_public(self):
#   def is_restricted(self):
#   def keyname(self):
#   def url(self, with_anchor=True, request=None, mobile=False):
#   def keyname(self):
#   def title(self):
#   def is_comment(self):
#   def is_channel(self):
#   def entry_actor(self):
#   def is_subscribed(self):
# class ApiMixinModel(aed_models.BaseModel):
# class CachingModel(ApiMixinModel):
# class DeletedMarkerModel(CachingModel):
# class AbuseReport(CachingModel):
# class Activation(CachingModel):
# class Actor(DeletedMarkerModel):
# class Image(CachingModel):
# class InboxEntry(CachingModel):
# class Invite(CachingModel):
# class KeyValue(CachingModel):
# class OAuthAccessToken(CachingModel):
# class OAuthConsumer(CachingModel):
# class OAuthNonce(CachingModel):
# class OAuthRequestToken(CachingModel):
# class Presence(CachingModel):
# class Task(CachingModel):
# class Relation(CachingModel):
# class Stream(DeletedMarkerModel):
# class StreamEntry(DeletedMarkerModel):
# class Subscription(CachingModel):


import datetime
import re
from markdown import markdown2
from django import template
from django.conf import settings
from django.template.defaultfilters import stringfilter
from django.utils.safestring import mark_safe
from django.utils.html import escape
from django.utils.timesince import timesince
from common.util import create_nonce, safe, display_nick, url_nick
from common import clean
from common import models
# http://www.manamplified.org/archives/2006/10/url-regex-pattern.html
autolink_regex = re.compile(r'(^|\s|>)([A-Za-z][A-Za-z0-9+.-]{1,120}:[A-Za-z0-9/](([A-Za-z0-9$_.+!*,;/?:@&~=-])|%[A-Fa-f0-9]{2}){1,333}(#([a-zA-Z0-9][a-zA-Z0-9$_.+!*,;/?:@&~=%-]{0,1000}))?)')
bold_regex = re.compile(r'\*([^*]+)\*')
italic_regex = re.compile(r'_([^_]+)_')


@register.filter(name="format_fancy")
@safe
def format_fancy(value, arg=None):
  value = italic_regex.sub(r'<i>\1</i>', value)
  value = bold_regex.sub(r'<b>\1</b>', value)
  return value


@register.filter(name="format_links")
@safe
def format_links(value, arg=None):
  value = link_regex.sub(r'<a href="\2" target=_new>\1</a>', value)
  return value

@register.filter(name="format_autolinks")
@safe
def format_autolinks(value, arg=None):
  value = autolink_regex.sub(r'\1<a href="\2" target="_new">\2</a>', value)
  return value

# TODO(tyler): Combine these with validate
user_regex = re.compile(
    r'@([a-zA-Z][a-zA-Z0-9]{%d,%d})' 
    % (clean.NICK_MIN_LENGTH - 1, clean.NICK_MAX_LENGTH - 1)

# Path: common/models.py
# PRIVACY_PRIVATE = 1
# PRIVACY_CONTACTS = 2
# PRIVACY_PUBLIC = 3
# ACTOR_ALLOWED_EXTRA = ('contact_count', 
#                        'follower_count', 
#                        'icon', 
#                        'description',
#                        'member_count', 
#                        'admin_count', 
#                        'given_name', 
#                        'family_name'
#                        )
# ACTOR_LIMITED_EXTRA = ('icon', 
#                        'description',
#                        'given_name', 
#                        'family_name'
#                        )
# def _get_actor_type_from_nick(nick):
# def _get_actor_urlnick_from_nick(nick):
# def _to_api(v):
#   def to_api(self):
#   def __init__(self, parent=None, key_name=None, _app=None, **kw):
#   def key_from(cls, **kw):
#   def _remove_from_cache(self):
#   def put(self):
#   def save(self):
#   def delete(self):
#   def get_by_key_name(cls, key_names, parent=None):
#   def db_get_count(cls):
#   def reset_cache(cls):
#   def enable_cache(cls, enabled = True):
#   def reset_get_count(cls):
#   def gql(cls, *args, **kw):
#   def Query(cls):
#   def mark_as_deleted(self):
#   def is_deleted(self):
# def actor_url(nick, actor_type, path='', request=None, mobile=False):
#   def url(self, path="", request=None, mobile=False):
#   def shortnick(self):
#   def display_nick(self):
#   def to_api(self):
#   def to_api_limited(self):
#   def is_channel(self):
#   def is_public(self):
#   def is_restricted(self):
#   def __repr__(self):
#   def stream_entry_keyname(self):
#   def to_string(self):
#   def url(self):
#   def to_string(self):
#   def is_public(self):
#   def is_restricted(self):
#   def keyname(self):
#   def url(self, with_anchor=True, request=None, mobile=False):
#   def keyname(self):
#   def title(self):
#   def is_comment(self):
#   def is_channel(self):
#   def entry_actor(self):
#   def is_subscribed(self):
# class ApiMixinModel(aed_models.BaseModel):
# class CachingModel(ApiMixinModel):
# class DeletedMarkerModel(CachingModel):
# class AbuseReport(CachingModel):
# class Activation(CachingModel):
# class Actor(DeletedMarkerModel):
# class Image(CachingModel):
# class InboxEntry(CachingModel):
# class Invite(CachingModel):
# class KeyValue(CachingModel):
# class OAuthAccessToken(CachingModel):
# class OAuthConsumer(CachingModel):
# class OAuthNonce(CachingModel):
# class OAuthRequestToken(CachingModel):
# class Presence(CachingModel):
# class Task(CachingModel):
# class Relation(CachingModel):
# class Stream(DeletedMarkerModel):
# class StreamEntry(DeletedMarkerModel):
# class Subscription(CachingModel):


# Path: common/templatetags/format.py
import datetime
import re
from markdown import markdown2
from django import template
from django.conf import settings
from django.template.defaultfilters import stringfilter
from django.utils.safestring import mark_safe
from django.utils.html import escape
from django.utils.timesince import timesince
from common.util import create_nonce, safe, display_nick, url_nick
from common import clean
from common import models

# http://www.manamplified.org/archives/2006/10/url-regex-pattern.html
autolink_regex = re.compile(r'(^|\s|>)([A-Za-z][A-Za-z0-9+.-]{1,120}:[A-Za-z0-9/](([A-Za-z0-9$_.+!*,;/?:@&~=-])|%[A-Fa-f0-9]{2}){1,333}(#([a-zA-Z0-9][a-zA-Z0-9$_.+!*,;/?:@&~=%-]{0,1000}))?)')
bold_regex = re.compile(r'\*([^*]+)\*')
italic_regex = re.compile(r'_([^_]+)_')


@register.filter(name="format_fancy")
@safe
def format_fancy(value, arg=None):
  value = italic_regex.sub(r'<i>\1</i>', value)
  value = bold_regex.sub(r'<b>\1</b>', value)
  return value


@register.filter(name="format_links")
@safe
def format_links(value, arg=None):
  value = link_regex.sub(r'<a href="\2" target=_new>\1</a>', value)
  return value

@register.filter(name="format_autolinks")
@safe
def format_autolinks(value, arg=None):
  value = autolink_regex.sub(r'\1<a href="\2" target="_new">\2</a>', value)
  return value

# TODO(tyler): Combine these with validate
user_regex = re.compile(
    r'@([a-zA-Z][a-zA-Z0-9]{%d,%d})' 
    % (clean.NICK_MIN_LENGTH - 1, clean.NICK_MAX_LENGTH - 1)

    )