[cc-commits] [SCM] cc.api: (branch next) updated. 5dc18bc48b83f1728dd73015289fd87cee31595f

git version control git at a7.creativecommons.org
Thu Nov 11 12:35:30 EST 2010


The branch, next has been updated
       via  5dc18bc48b83f1728dd73015289fd87cee31595f (commit)
       via  57a8ffc7b4cc7f2b6f3d9a530c212d15686f5638 (commit)
      from  6715444b341e8c0b28bacc4cf0d9587b653228cf (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 5dc18bc48b83f1728dd73015289fd87cee31595f
Author: JED3 <john at creativecommons.org>
Date:   Thu Nov 11 09:35:05 2010 -0800

    Moving PDM support into the API

commit 57a8ffc7b4cc7f2b6f3d9a530c212d15686f5638
Author: JED3 <john at creativecommons.org>
Date:   Fri Oct 22 14:06:10 2010 -0700

    Added docstrings to the support functions

-----------------------------------------------------------------------

Summary of changes (followed by patch):
 cc/api/app.py                         |    1 +
 cc/api/resources/license.py           |   21 +++++++++++++++++----
 cc/api/support.py                     |   32 +++++++++++++++++++++++++++-----
 cc/api/tests/schemata/issue.relax.xml |   27 +++++++++++++++++++++++++++
 cc/api/tests/test_common.py           |    4 ++--
 cc/api/tests/test_license.py          |    4 ++++
 6 files changed, 78 insertions(+), 11 deletions(-)

diff --git a/cc/api/app.py b/cc/api/app.py
index dbef018..b2ffb1a 100644
--- a/cc/api/app.py
+++ b/cc/api/app.py
@@ -31,6 +31,7 @@ urls = ( # tuple of url to resource method mappings
     '/license/([\w\d]+)',       'cc.api.resources.license.index',
     '/license/([\w\d]+)/issue', 'cc.api.resources.license.issue',
     '/license/([\w\d]+)/get',   'cc.api.resources.license.issue_get',
+    
     '/license/standard/jurisdiction/([\w]*)', 'cc.api.resources.license.jurisdiction',
     
     '/simple/chooser',        'cc.api.resources.simple.chooser',
diff --git a/cc/api/resources/license.py b/cc/api/resources/license.py
index 4886ecb..1c43aa6 100644
--- a/cc/api/resources/license.py
+++ b/cc/api/resources/license.py
@@ -34,6 +34,7 @@ class index:
 
         try:
             assert selector != 'software'
+            if selector == 'publicdomain': selector = 'zero'
             lclass = cc.license.selectors.choose(selector)
         except:
             return api_exceptions.invalidclass()
@@ -77,7 +78,10 @@ class issue:
 
         try:
             assert selector != 'software'
-            lclass = cc.license.selectors.choose(selector)
+            if selector == 'publicdomain':
+                lclass = cc.license.selectors.choose('zero')
+            else:
+                lclass = cc.license.selectors.choose(selector)
         except:
             return api_exceptions.invalidclass()
 
@@ -85,8 +89,16 @@ class issue:
             return api_exceptions.missingparam('answers')
 
         try:
+            answers_xml = web.input().get('answers')
+            if selector == 'publicdomain':
+                answers_xml = answers_xml.replace(
+                    '<license-publicdomain>',
+                    '<license-zero>').replace(
+                    '</license-publicdomain>',
+                    '</license-zero>')
+            
             # parse the answers argument into an xml tree
-            answers = ET.parse(StringIO(web.input().get('answers')))
+            answers = ET.parse(StringIO(answers_xml))
             
         except ET.XMLSyntaxError, e:
             return api_exceptions.invalidanswer()
@@ -133,6 +145,7 @@ class issue_get:
         
         try:
             assert selector != 'software'
+            if selector == 'publicdomain': selector = 'zero'
             lclass = cc.license.selectors.choose(selector)
         except:
             return api_exceptions.invalidclass()
@@ -145,9 +158,9 @@ class issue_get:
             return api_exceptions.invalidanswer()
         
         answers_dict = support.build_answers_dict(lclass, answers)
-
+        
         issued_license = lclass.by_answers(answers_dict)
-
+        
         work_dict = support.build_work_dict(issued_license, answers)
         work_xml = support.build_work_xml(issued_license, answers)
         
diff --git a/cc/api/support.py b/cc/api/support.py
index 2a75b77..692716c 100644
--- a/cc/api/support.py
+++ b/cc/api/support.py
@@ -43,6 +43,7 @@ FORMATTERS = {
     'zero': CC0HTMLFormatter,
     'standard': HTMLFormatter,
     'recombo': HTMLFormatter,
+    'mark': PDMarkHTMLFormatter,
     'publicdomain': PublicDomainHTMLFormatter,
     }
 
@@ -76,7 +77,13 @@ CC0_FORMATTER_KEYS = [
     ]
     
 def validate_answers(selector, answers):
-
+    """ Takes an xml string `answers` and ensures that
+    all of the required questions have values for the given
+    selector class. Valid answers must be a member of the
+    enumeration for that question, if not, then this function
+    with throw an exception, signalling to the caller that the
+    answers string is not a valid one. """
+    
     assert answers.xpath('/answers/license-%s' % selector.id), \
            'license-class required'
     
@@ -101,7 +108,8 @@ def validate_answers(selector, answers):
     return True
 
 def build_answers_dict(selector, answers):
-    # builds answer dict thats usable in cc.license
+    """ cc.license uses a dict form of the answers xml.
+    This function converts the xml string `answers` into a python dict. """
     
     answers_dict = {}      
     questions = answers.xpath('/answers/license-%s' % selector.id)[0]
@@ -112,6 +120,11 @@ def build_answers_dict(selector, answers):
     return answers_dict
 
 def build_answers_xml(selector, args):
+    """ builds an answers xml string for a selector class using
+    default answers for the selector's questions. If any other attributes
+    were included in the call, they are appended to as part of the
+    work-info. """
+    
     # build an answers xml tree
     answers = ET.Element('answers')
     questions = ET.SubElement(answers, 'license-%s' % selector.id)
@@ -133,7 +146,10 @@ def build_answers_xml(selector, args):
     return answers
     
 def build_work_dict(license, answers=None):
-
+    """ Extract work-info elements from the `answers` ElementTree
+    and constructs a dict so that it may be passed to a cc.license
+    formatter. """
+    
     work_dict = {}
     
     if answers is None or \
@@ -160,7 +176,10 @@ def build_work_dict(license, answers=None):
     return work_dict
 
 def build_work_xml(license, answers=None):
-
+    """ Accept the work-information parameters defined in the api doc's
+    and build an RDF-XML tree containing accurate predicates for the
+    paremeters contained in the answers xml. """
+    
     RDF = lambda p: '{http://www.w3.org/1999/02/22-rdf-syntax-ns#}%s' % p
     DC = lambda p: '{http://purl.org/dc/elements/1.1/}%s' % p
     work_types = ['Text', 'StillImage', 'MovingImage', 'InteractiveResource',
@@ -215,7 +234,10 @@ def build_work_xml(license, answers=None):
     return root
                  
 def build_results_tree(license, work_xml=None, work_dict=None, locale='en'):
-
+    """ Build an ElementTree to be returned for an issue or details call.
+    Properly wraps the formatter markup of a license as a valid xhtml tree.
+    """    
+    
     root = ET.Element('result')
     # add the license uri and name
     ET.SubElement(root, 'license-uri').text = license.uri
diff --git a/cc/api/tests/schemata/issue.relax.xml b/cc/api/tests/schemata/issue.relax.xml
index 91be0c4..ba540d6 100644
--- a/cc/api/tests/schemata/issue.relax.xml
+++ b/cc/api/tests/schemata/issue.relax.xml
@@ -24,6 +24,7 @@
             <choice> 
               <ref name="standard" />
               <ref name="zero" />
+              <ref name="mark" />
             </choice>
         </element>
       </group>
@@ -129,6 +130,32 @@
               </element>
             </define>
 
+           <define name="mark">
+              <element name="p">
+                  
+                <ref name="badge_html" />
+
+                <element name="br">
+                  <empty/>
+                </element>
+
+                <text />
+                <optional>
+                <element name="span">
+                  <attribute name="rel">
+                    <text />
+                  </attribute>
+                  <attribute name="resource">
+                    <text />
+                  </attribute>
+                  <text />
+                </element>
+                </optional>
+                <text />
+                  
+              </element>
+           </define>
+
 
 
 
diff --git a/cc/api/tests/test_common.py b/cc/api/tests/test_common.py
index cd03ba4..b68bb72 100644
--- a/cc/api/tests/test_common.py
+++ b/cc/api/tests/test_common.py
@@ -79,8 +79,8 @@ class TestData:
         """Retrieve the license information for this class, and generate 
            a set of answers for use with testing."""
         enums = [('jurisdiction', ['', 'us', 'de', 'uk'])]
-        if lclass in ['publicdomain', 'zero']:
-            return enums
+        if lclass in ['publicdomain', 'zero', 'mark']:
+            return enums            
         elif lclass == 'recombo':
             enums.append(('sampling',
                           ['sampling','samplingplus','ncsamplingplus']))
diff --git a/cc/api/tests/test_license.py b/cc/api/tests/test_license.py
index 53437bd..38e81cc 100644
--- a/cc/api/tests/test_license.py
+++ b/cc/api/tests/test_license.py
@@ -130,6 +130,10 @@ class TestLicenseIssue(TestApi):
         """/issue issues publicdomain licenses successfully."""
         self._issue('publicdomain')
 
+    def test_license_mark(self):
+        """/issue issues pdm successfully."""
+        self._issue('mark')
+
     def test_license_zero(self):
         """/issue issues zero licenses successfully."""
         self._issue('zero')


hooks/post-receive
-- 
cc.api:



More information about the cc-commits mailing list