# Path: gitcms/pages/models.py
# class Article(models.Model):
#     title = models.CharField(u'title', max_length=255)
#     url = models.CharField(u'url', max_length=255)
#     meta = models.TextField(u'meta')
#     author = models.TextField(u'author', max_length=255)
#     tags = models.ManyToManyField(Tag)
#     content = models.TextField(u'content')
#     def __unicode__(self):
#         return '%s (%s)' % (self.title, self.url)
# 
# Path: gitcms/tagging/models.py
# def tag_for(slug):
#     '''
#     tag = tag_for(slug)
# 
#     Returns the Tag object corresponding to slug
# 
#     Raises an exception if not found.
#     '''
#     tags = Tag.objects.filter(slug=slug).all()
#     if len(tags) == 1:
#         return tags[0]
#     if not tags:
#         raise ValueError("gitcms.tagging.tag_for: No tag for slug '%s'" % slug)
#     raise ValueError("gitcms.tagging.tag_for: Multiple tags for slug '%s' (%s)" % (slug, [t.name for t in tags]))
# 
# Path: gitcms/pages/rest.py
# def preprocess_rst_content(value):
#     # This is adapted from django source
#     value = _precontent + value
#     docutils_settings = getattr(settings, "RESTRUCTUREDTEXT_FILTER_SETTINGS", {})
#     parts = publish_parts(source=smart_str(value), writer_name="html4css1", settings_overrides=docutils_settings)
#     return mark_safe(parts["fragment"])


from .models import Article
from os import path
from gitcms.tagging.models import tag_for
from .rest import preprocess_rst_content
import os
            import warnings
            import warnings
            header[tag] = value
        blank = input.readline()
        linenr += 1
        if blank.strip():
            raise IOError('Blank line expected while processing file (%s:%s)\nGot "%s"' % (artfile, linenr,blank))
        content = input.read()
        content = preprocess_rst_content(content)

        url = header['url']
        if url and url[-1] == '/':
            warnings.warn('''\
gitcms.pages.loaddir: Removing / at end of url (%s)

(Both versions will work for accessing the page.)
''' % url)
            url = url[:-1]

        if url and url[0] == '/':
            warnings.warn('gitcms.pages.loaddir: Removing / at start of url ({0})'
                        .format(url))
            url = url[1:]

        if url in urls:
            raise IOError('gitcms.pages.loaddir: repeated URL detected (%s)' % url)

        taglist = []
        for c in header.get('categories','').split():
            taglist.append(tag_for(c))
        # if we got so far, implies that our article is safe to store.
        urls.add(url)

# Path: gitcms/pages/models.py
# class Article(models.Model):
#     title = models.CharField(u'title', max_length=255)
#     url = models.CharField(u'url', max_length=255)
#     meta = models.TextField(u'meta')
#     author = models.TextField(u'author', max_length=255)
#     tags = models.ManyToManyField(Tag)
#     content = models.TextField(u'content')
#     def __unicode__(self):
#         return '%s (%s)' % (self.title, self.url)
# 
# Path: gitcms/tagging/models.py
# def tag_for(slug):
#     '''
#     tag = tag_for(slug)
# 
#     Returns the Tag object corresponding to slug
# 
#     Raises an exception if not found.
#     '''
#     tags = Tag.objects.filter(slug=slug).all()
#     if len(tags) == 1:
#         return tags[0]
#     if not tags:
#         raise ValueError("gitcms.tagging.tag_for: No tag for slug '%s'" % slug)
#     raise ValueError("gitcms.tagging.tag_for: Multiple tags for slug '%s' (%s)" % (slug, [t.name for t in tags]))
# 
# Path: gitcms/pages/rest.py
# def preprocess_rst_content(value):
#     # This is adapted from django source
#     value = _precontent + value
#     docutils_settings = getattr(settings, "RESTRUCTUREDTEXT_FILTER_SETTINGS", {})
#     parts = publish_parts(source=smart_str(value), writer_name="html4css1", settings_overrides=docutils_settings)
#     return mark_safe(parts["fragment"])


# Path: gitcms/pages/load.py
from .models import Article
from os import path
from gitcms.tagging.models import tag_for
from .rest import preprocess_rst_content
import os
            import warnings
            import warnings

            header[tag] = value
        blank = input.readline()
        linenr += 1
        if blank.strip():
            raise IOError('Blank line expected while processing file (%s:%s)\nGot "%s"' % (artfile, linenr,blank))
        content = input.read()
        content = preprocess_rst_content(content)

        url = header['url']
        if url and url[-1] == '/':
            warnings.warn('''\
gitcms.pages.loaddir: Removing / at end of url (%s)

(Both versions will work for accessing the page.)
''' % url)
            url = url[:-1]

        if url and url[0] == '/':
            warnings.warn('gitcms.pages.loaddir: Removing / at start of url ({0})'
                        .format(url))
            url = url[1:]

        if url in urls:
            raise IOError('gitcms.pages.loaddir: repeated URL detected (%s)' % url)

        taglist = []
        for c in header.get('categories','').split():
            taglist.append(tag_for(c))
        # if we got so far, implies that our article is safe to store.
        urls.add(url)

        A = Article(title=header['title'], url=url, meta=header.get('meta', ''), author=header.get('author', ''), content=content)