Commits

dan mackinlay  committed 45b09fb

quick reshuffle into usable code chunks

  • Participants
  • Parent commits f78cd1a

Comments (0)

Files changed (4)

File resocializedtext/flickr.py

Empty file added.

File resocializedtext/thecode.py

-"""
-how to define ReST 'interpreted roles' can be found here.
-http://docutils.sourceforge.net/docs/howto/rst-roles.html
-http://docutils.sourceforge.net/docs/howto/rst-directives.html
-http://www.krugle.org/kse/files/cvs/cvs.sourceforge.net/scriba/scriba/scriba/utils/rstwrap.py#2
-http://codespeak.net/py/dist/bin.html
-http://www.hvergi.net/2008/06/restructuredtext-extensions/
-http://www.djangosnippets.org/snippets/1217/
-http://pygments.org/docs/rstdirective/
-http://pygments.org/docs/quickstart/
-"""
-from docutils.parsers.rst import roles, directives, Directive, nodes
-from docutils.core import publish_parts
-from django.utils.encoding import smart_str, force_unicode
-from django.utils.safestring import mark_safe
-from django.conf import settings
-import dateutil.parser as dateparser
-# dateparseinfo=dateutil.parser(yearfirst=True)
-
-_values = {}
-
-def metadata_directive(name, arguments, options, content, lineno,
-                    content_offset, block_text, state, state_machine):
-    for key, val in options.items():
-        if key in set(['created', 'modified']):
-            _values[key] = dateparser.parse(val)
-        if key in set(['publicness', 'lucidity']):
-            _values[key] = float(val)
-        if key in set(["tags", 'remove_tags']):
-            _values[key] = set(
-              [tag.strip() for tag in val.split(" ")]
-            )
-            
-    return []
-
-metadata_directive.content = False
-metadata_directive.options = {
-  'publicness': directives.unchanged,
-  'lucidity': directives.unchanged,
-  'tags': directives.unchanged,
-  'remove_tags' : directives.unchanged,#necessary because of autotagging
-  'created' : directives.unchanged,
-  'modified' : directives.unchanged,
-} 
-directives.register_directive('metadata', metadata_directive)
-
-def cul_role(role, rawtext, text, lineno, inliner,
-                       options={}, content=[]):
-    try:
-        culnum = int(text)
-        if culnum <= 0:
-            raise ValueError
-    except ValueError:
-        msg = inliner.reporter.error(
-            'cul ref num must be a number greater than or equal to 1; '
-            '"%s" is invalid.' % text, line=lineno)
-        prb = inliner.problematic(rawtext, rawtext, msg)
-        return [prb], [msg]
-    ref="http://www.citeulike.org/user/livingthingdan/article/%d" % culnum
-    node = nodes.references(rawtext, 'ref', refuri=ref, **options) #not sure I'm handling options right - http://docutils.sourceforge.net/docs/howto/rst-roles.html
-    return [], []
-roles.register_local_role('cul', cul_role)
-
-def globalref_role(role, rawtext, text, lineno, inliner,
-                       options={}, content=[]):
-    return [], []
-roles.register_local_role('globalref', cul_role)
-
-def globalanchor_role(role, rawtext, text, lineno, inliner,
-                       options={}, content=[]):
-    return [], []
-roles.register_local_role('globalanchor', cul_role)
-
-class AdhocRestParser(object):
-    """
-    we wrap ReST parsing in a class to have a place to stash info gleaned from the parsing process
-    ReST.adhoc_rest("\n.. metadata::\n  :publicness: 5\n")
-    """
-    is_safe = True
-    values = _values
-    
-    def __init__(self):
-        pass
-        
-    def __call__(self, value):
-        self.values.clear()
-        docutils_settings = getattr(settings, "RESTRUCTUREDTEXT_FILTER_SETTINGS", {})
-        parts = publish_parts(
-          source=smart_str(value), writer_name="html4css1",
-          settings_overrides=docutils_settings
-        )
-        if parts['title']:
-            self.values['title']= parts['title']
-        return mark_safe(force_unicode(parts["fragment"]))
-
-adhoc_rest = AdhocRestParser()
-# register = template.Library()
-# register.filter(adhoc_rest)

File tests/test_date.py

-#! /usr/bin/env python
-
-# $Id: test_date.py 4667 2006-07-12 21:40:56Z wiemann $
-# Author: David Goodger <goodger@python.org>
-# Copyright: This module has been placed in the public domain.
-
-"""
-Tests for the misc.py "date" directive.
-"""
-
-from __init__ import DocutilsTestSupport
-import time
-
-
-def suite():
-    s = DocutilsTestSupport.ParserTestSuite()
-    s.generateTests(totest)
-    return s
-
-totest = {}
-
-totest['date'] = [
-["""\
-.. |date| date::
-
-Today's date is |date|.
-""",
-"""\
-<document source="test data">
-    <substitution_definition names="date">
-        %s
-    <paragraph>
-        Today's date is \n\
-        <substitution_reference refname="date">
-            date
-        .
-""" % time.strftime('%Y-%m-%d')],
-["""\
-.. |date| date:: %a, %d %b %Y
-""",
-"""\
-<document source="test data">
-    <substitution_definition names="date">
-        %s
-""" % time.strftime('%a, %d %b %Y')],
-["""\
-.. date::
-""",
-"""\
-<document source="test data">
-    <system_message level="3" line="1" source="test data" type="ERROR">
-        <paragraph>
-            Invalid context: the "date" directive can only be used within a substitution definition.
-        <literal_block xml:space="preserve">
-            .. date::
-"""],
-]
-
-
-if __name__ == '__main__':
-    import unittest
-    unittest.main(defaultTest='suite')

File tests/test_flickr.py

+#! /usr/bin/env python
+
+# $Id: test_date.py 4667 2006-07-12 21:40:56Z wiemann $
+# Author: David Goodger <goodger@python.org>
+# Copyright: This module has been placed in the public domain.
+
+"""
+Tests for the misc.py "date" directive.
+"""
+
+from __init__ import DocutilsTestSupport
+import time
+
+
+def suite():
+    s = DocutilsTestSupport.ParserTestSuite()
+    s.generateTests(totest)
+    return s
+
+totest = {}
+
+totest['date'] = [
+["""\
+.. |date| date::
+
+Today's date is |date|.
+""",
+"""\
+<document source="test data">
+    <substitution_definition names="date">
+        %s
+    <paragraph>
+        Today's date is \n\
+        <substitution_reference refname="date">
+            date
+        .
+""" % time.strftime('%Y-%m-%d')],
+["""\
+.. |date| date:: %a, %d %b %Y
+""",
+"""\
+<document source="test data">
+    <substitution_definition names="date">
+        %s
+""" % time.strftime('%a, %d %b %Y')],
+["""\
+.. date::
+""",
+"""\
+<document source="test data">
+    <system_message level="3" line="1" source="test data" type="ERROR">
+        <paragraph>
+            Invalid context: the "date" directive can only be used within a substitution definition.
+        <literal_block xml:space="preserve">
+            .. date::
+"""],
+]
+
+
+if __name__ == '__main__':
+    import unittest
+    unittest.main(defaultTest='suite')