[cc-commits] [git]cc.license: Python API for selecting licenses and retrieving metadata (branch next) updated. edeeb5a450e320b1cb26e891f49ad8d90d6fae3e

Gitosis User webmaster at creativecommons.org
Wed Sep 28 12:09:08 EDT 2011


The branch, next has been updated
       via  edeeb5a450e320b1cb26e891f49ad8d90d6fae3e (commit)
       via  cfeefb4a33208450a9f49c13085735d1dad83027 (commit)
       via  ce4181c3e8a2fdd288a7a6af01c9d99f11180727 (commit)
       via  b91971055b0ce875ddf660cc10109546433bb738 (commit)
       via  994011f83f57e54e01ea9195e474203c59fbd59b (commit)
       via  afbed625308744ba40fcf6418875c0a67441fc21 (commit)
       via  8e566742a3ffe989b355d995bc420d3e3b967ce2 (commit)
      from  fc7119405aaf8a7e7af8de48d340bac478ffc085 (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 edeeb5a450e320b1cb26e891f49ad8d90d6fae3e
Merge: cfeefb4 fc71194
Author: Jonathan Palecek <jonathan at creativecommons.org>
Date:   Wed Sep 28 11:07:00 2011 -0500

    Merge branch 'next' of code.creativecommons.org:cc.license into next

commit cfeefb4a33208450a9f49c13085735d1dad83027
Merge: 8e56674 ce4181c
Author: Jonathan Palecek <jonathan at creativecommons.org>
Date:   Wed Sep 28 11:06:48 2011 -0500

    Merge branch 'issue879' into next

commit ce4181c3e8a2fdd288a7a6af01c9d99f11180727
Author: Jonathan Palecek <jonathan at creativecommons.org>
Date:   Wed Sep 28 10:51:44 2011 -0500

    Updated the tests

commit b91971055b0ce875ddf660cc10109546433bb738
Author: Jonathan Palecek <jonathan at creativecommons.org>
Date:   Wed Sep 28 10:26:01 2011 -0500

    Removed obsolete code for the jurisdiction.languages property

commit 8e566742a3ffe989b355d995bc420d3e3b967ce2
Author: Jonathan Palecek <jonathan at creativecommons.org>
Date:   Thu Aug 18 16:05:26 2011 -0500

    Renamed MalformedURIError to InvalidURIError

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

Summary of changes (followed by patch):
 cc/license/__init__.py                 |    4 ++--
 cc/license/_lib/exceptions.py          |    2 +-
 cc/license/_lib/functions.py           |   10 +++++-----
 cc/license/_lib/rdf_helper.py          |   27 ---------------------------
 cc/license/jurisdictions/__init__.py   |    2 +-
 cc/license/jurisdictions/classes.py    |   16 +++-------------
 cc/license/tests/test_jurisdictions.py |    7 +------
 cc/license/tests/test_lib.py           |    6 ------
 setup.py                               |    2 +-
 9 files changed, 14 insertions(+), 62 deletions(-)

diff --git a/cc/license/__init__.py b/cc/license/__init__.py
index cb66a36..037b9c7 100644
--- a/cc/license/__init__.py
+++ b/cc/license/__init__.py
@@ -5,13 +5,13 @@ from _lib.classes import License, Question, JurisdictionQuestion
 from jurisdictions.classes import Jurisdiction
 from selectors.classes import LicenseSelector
 from _lib.functions import locales, by_code, by_uri
-from _lib.exceptions import CCLicenseError, MalformedURIError
+from _lib.exceptions import CCLicenseError, InvalidURIError
 from _lib.exceptions import SelectorQAError, ExistentialException
 
 __all__ = ['selectors', 'formatters', 'jurisdictions', # modules
            'License', 'Question', 'Jurisdiction', 'LicenseSelector', # classes
            'locales', 'by_code', 'by_uri', # functions
-           'CCLicenseError', 'MalformedURIError', # exceptions
+           'CCLicenseError', 'InvalidURIError', # exceptions
            'SelectorQAError', 'ExistentialException'
           ]
 
diff --git a/cc/license/_lib/exceptions.py b/cc/license/_lib/exceptions.py
index 4f71c20..14d6637 100644
--- a/cc/license/_lib/exceptions.py
+++ b/cc/license/_lib/exceptions.py
@@ -12,7 +12,7 @@ class CCLicenseError(Exception):
     """Generic exception when misuse cc.license"""
     pass
 
-class MalformedURIError(CCLicenseError):
+class InvalidURIError(CCLicenseError):
     """Raised when a URI is unusuable because of it being formatted wrong."""
     pass
 
diff --git a/cc/license/_lib/functions.py b/cc/license/_lib/functions.py
index 2a6b5ec..d8d8f35 100644
--- a/cc/license/_lib/functions.py
+++ b/cc/license/_lib/functions.py
@@ -6,7 +6,7 @@ import RDF
 import rdf_helper
 
 from cc.license.jurisdictions.classes import Jurisdiction
-from cc.license._lib.exceptions import MalformedURIError
+from cc.license._lib.exceptions import InvalidURIError
 import cc.license
 
 
@@ -27,7 +27,7 @@ def locales():
         SELECT ?lang
         WHERE
          {
-            ?x dc:language ?lang .
+            ?x cc:defaultLanguage ?lang .
             ?x rdf:type cc:Jurisdiction .
          }
                   """
@@ -86,7 +86,7 @@ def code_from_uri(uri):
     elif uri.startswith(CC0_BASE):
         return 'CC0'
     else:
-        raise MalformedURIError, "Invalid License URI"
+        raise InvalidURIError, "Invalid License URI"
 
 def uri2dict(uri):
     """Take a license uri and convert it into a dictionary of values."""
@@ -100,7 +100,7 @@ def uri2dict(uri):
         info_list = raw_info.split('/') 
 
         if len(info_list) not in (1,2,3):
-            raise MalformedURIError, "Malformed Creative Commons URI: <%s>"%uri
+            raise InvalidURIError, "Invalid Creative Commons URI: <%s>"%uri
 
         retval = dict( code=info_list[0] )
         if len(info_list) > 1:
@@ -127,7 +127,7 @@ def uri2dict(uri):
 
 
     else:
-        raise MalformedURIError, "Malformed Creative Commons URI: <%s>" % uri
+        raise InvalidURIError, "Invalid Creative Commons URI: <%s>" % uri
 
 def dict2uri(license_info):
     """Take a dictionary of license values and convert it into a uri."""
diff --git a/cc/license/_lib/rdf_helper.py b/cc/license/_lib/rdf_helper.py
index 46b2565..90691ec 100644
--- a/cc/license/_lib/rdf_helper.py
+++ b/cc/license/_lib/rdf_helper.py
@@ -441,33 +441,6 @@ def get_jurisdiction_default_language(juris_uri):
     else:
         return None
 
-def get_jurisdiction_languages(juris_uri):
-    """
-    Get all languages for given jurisdiction
-
-    Args:
-    - juris_uri: URI for the jurisdiction in question
-    
-    Returns:
-      List of all languages
-    """
-
-    qstring = """
-              PREFIX dc: <http://purl.org/dc/elements/1.1/>
-              PREFIX cc: <http://creativecommons.org/ns#>
-
-              SELECT ?language
-              WHERE {
-                     <%s> dc:language ?language
-                    }
-              """
-    query = RDF.Query(qstring % juris_uri, query_language='sparql')
-    results = [
-        str(result['language'])
-        for result in query.execute(JURI_MODEL)]
-    return results
-
-
 JURISDICTIONS_FOR_SELECTOR_CACHE = {}
 def jurisdictions_for_selector(selector_uri):
     """
diff --git a/cc/license/jurisdictions/__init__.py b/cc/license/jurisdictions/__init__.py
index be0a430..dd81a99 100644
--- a/cc/license/jurisdictions/__init__.py
+++ b/cc/license/jurisdictions/__init__.py
@@ -65,7 +65,7 @@ def uri2code(uri):
         return '' # trivial case
     base = 'http://creativecommons.org/international/' 
     if not uri.startswith(base):
-        raise cc.license.MalformedURIError, "Malformed jurisdiction URI"
+        raise cc.license.InvalidURIError, "Invalid jurisdiction URI"
     blen = len(base)
     return uri[blen:-1]
 
diff --git a/cc/license/jurisdictions/classes.py b/cc/license/jurisdictions/classes.py
index 67725f8..5d3a076 100644
--- a/cc/license/jurisdictions/classes.py
+++ b/cc/license/jurisdictions/classes.py
@@ -2,7 +2,7 @@ import zope.interface
 import RDF
 
 import cc.license
-from cc.license._lib.exceptions import NoValuesFoundError, MalformedURIError
+from cc.license._lib.exceptions import NoValuesFoundError, InvalidURIError
 from cc.license._lib import interfaces, rdf_helper
 
 class Jurisdiction(object):
@@ -13,7 +13,6 @@ class Jurisdiction(object):
            a valid jurisdiction URI. For a complete list, see
            cc.license.jurisdictions.list_uris()"""
         self._default_language = None
-        self._languages = None
 
         if uri == '': # handle default jurisdiction case
             self.code = ''
@@ -24,7 +23,7 @@ class Jurisdiction(object):
             return
         if not uri.startswith('http://creativecommons.org/international/') \
            or not uri.endswith('/'):
-            raise MalformedURIError, "Malformed jurisdiction URI: <%s>" % uri
+            raise InvalidURIError, "Invalid jurisdiction URI: <%s>" % uri
         self.code = cc.license.jurisdictions.uri2code(uri)
         self.id = uri
         self._titles = rdf_helper.get_titles(self.id, rdf_helper.JURI_MODEL)
@@ -71,7 +70,7 @@ class Jurisdiction(object):
         except KeyError, e:
             import sys
             tb = sys.exc_info()[2]
-            raise MalformedURIError, \
+            raise InvalidURIError, \
                 "Language %s does not exist for jurisdiction %s" \
                 % (language, self.code), tb
 
@@ -83,12 +82,3 @@ class Jurisdiction(object):
         self._default_language = rdf_helper.get_jurisdiction_default_language(
             self.id)
         return self._default_language
-
-    @property
-    def languages(self):
-        if self._languages:
-            return self._languages
-
-        self._languages = rdf_helper.get_jurisdiction_languages(
-            self.id)
-        return self._languages
diff --git a/cc/license/tests/test_jurisdictions.py b/cc/license/tests/test_jurisdictions.py
index 3f7ba3f..e57ac81 100644
--- a/cc/license/tests/test_jurisdictions.py
+++ b/cc/license/tests/test_jurisdictions.py
@@ -168,10 +168,5 @@ class TestCustomization:
 def test_default_language():
     juris = cc.license.Jurisdiction(
         'http://creativecommons.org/international/be/')
-    assert juris.default_language == 'fr-be'
+    assert juris.default_language == 'fr'
     
-
-def test_languages():
-    juris = cc.license.Jurisdiction(
-        'http://creativecommons.org/international/be/')
-    assert set(juris.languages) == set(['fr-be', 'nl-be'])
diff --git a/cc/license/tests/test_lib.py b/cc/license/tests/test_lib.py
index c3892e4..4006ee8 100644
--- a/cc/license/tests/test_lib.py
+++ b/cc/license/tests/test_lib.py
@@ -112,12 +112,6 @@ class TestFunctions:
             assert lib.dict2uri(d) == \
                    'http://creativecommons.org/licenses/sampling+/1.0/'
 
-def test_get_jurisdiction_languages():
-    result = lib.rdf_helper.get_jurisdiction_languages(
-        'http://creativecommons.org/international/be/')
-    assert set(result) == set(['nl-be', 'fr-be'])
-
-
 def test_jurisdictions_for_selector():
     """
     Test for rdf_helper.jurisdictions_for_selector
diff --git a/setup.py b/setup.py
index 5486071..f2d3853 100644
--- a/setup.py
+++ b/setup.py
@@ -1,7 +1,7 @@
 from setuptools import setup, find_packages
 
 setup(name='cc.license',
-      version='0.14.20',
+      version='0.14.21',
       namespace_packages = ['cc',],
       description="License selection based on ccREL-based metadata.",
       classifiers=[],


hooks/post-receive
-- 
cc.license: Python API for selecting licenses and retrieving metadata


More information about the cc-commits mailing list