# Path: peanut/utils.py
# def path_to_url(path):
#     if six.PY2:
#         path = path.encode('utf-8')
#     return pathname2url(path)
# 
# def url_safe(string):
#     new_str = re.sub(
#             r'[<>,~!#&\{\}\(\)\[\]\*\^\$\?]', ' ', string
#     )
# 
#     return '-'.join(new_str.strip().split())
# 
# def real_url(base, url):
#     path = urlsplit(base).path
#     if not path.endswith('/'):
#         path = path + '/'
#     url = url.lstrip('/')
#     return urljoin(path, url)
# 
# Path: peanut/options.py
# class ValidationError(Exception):
# class LoadingError(ValidationError):
# class Option(dict):
#     def __init__(self, msg=None):
#     def __init__(self, *args, **kwargs):
#     def __setitem__(self, key, value):
#     def __getitem__(self, name):
#     def __delitem__(self, name):
#     def __real_update(self, key, value):
#     def update(self, *args, **kwargs):
# def verify_path():
# def verify_theme():
# def verify_configs():
# def load_yaml(path):
# def load_configs(path):


import re
import os
from datetime import datetime
from peanut.utils import path_to_url, url_safe, real_url
from peanut.options import configs, env



class BaseModel(object):
    """Base model class
    """

    layout = None

    @property
    def file_path(self):
        template = configs.path.get(self.__class__.layout, '').lstrip('/')
        return url_safe(template.format(**self.__dict__))

    @property
    def url(self):
        relative_url = path_to_url(self.file_path)
        if not relative_url.startswith('/'):
            relative_url = '/'+relative_url
        return real_url(configs.site.url, relative_url)


class Tag(BaseModel):
    """Tag model
    """

    layout = 'tag'

    def __init__(self, title):
        self.title = title

# Path: peanut/utils.py
# def path_to_url(path):
#     if six.PY2:
#         path = path.encode('utf-8')
#     return pathname2url(path)
# 
# def url_safe(string):
#     new_str = re.sub(
#             r'[<>,~!#&\{\}\(\)\[\]\*\^\$\?]', ' ', string
#     )
# 
#     return '-'.join(new_str.strip().split())
# 
# def real_url(base, url):
#     path = urlsplit(base).path
#     if not path.endswith('/'):
#         path = path + '/'
#     url = url.lstrip('/')
#     return urljoin(path, url)
# 
# Path: peanut/options.py
# class ValidationError(Exception):
# class LoadingError(ValidationError):
# class Option(dict):
#     def __init__(self, msg=None):
#     def __init__(self, *args, **kwargs):
#     def __setitem__(self, key, value):
#     def __getitem__(self, name):
#     def __delitem__(self, name):
#     def __real_update(self, key, value):
#     def update(self, *args, **kwargs):
# def verify_path():
# def verify_theme():
# def verify_configs():
# def load_yaml(path):
# def load_configs(path):


# Path: peanut/model.py
import re
import os
from datetime import datetime
from peanut.utils import path_to_url, url_safe, real_url
from peanut.options import configs, env




class BaseModel(object):
    """Base model class
    """

    layout = None

    @property
    def file_path(self):
        template = configs.path.get(self.__class__.layout, '').lstrip('/')
        return url_safe(template.format(**self.__dict__))

    @property
    def url(self):
        relative_url = path_to_url(self.file_path)
        if not relative_url.startswith('/'):
            relative_url = '/'+relative_url
        return real_url(configs.site.url, relative_url)


class Tag(BaseModel):
    """Tag model
    """

    layout = 'tag'

    def __init__(self, title):
        self.title = title

        self.slug = url_safe(title)