Rhys ! avatar Rhys ! committed 572fc7f

split non-RDF_TYPE stuff from Typed into new superclass Description

Comments (0)

Files changed (1)

 from rdfview import RdfQuery, one, each
 from namespaces import RDF, DCTERMS, prefixes
 
+__all__ = ['Term', 'RDFDoc', 'one', 'each', 'one_uri', 'each_uri',
+    'Description', 'Typed', 'Data']
+
 class Term(URIRef):
     namespace = None
     prefix = None
             if term in terms:
                 if 'from' in terms[term]:
                     if terms[term]['from'] != prefix:
-                        raise ValueError('Term collision: new term %s from %s collides with term %s from %s.' % (term, prefix, term, terms[term]['from']))
+                        raise ValueError('Term collision: new term %s from %s '
+                            'collides with term %s from %s.' % (term, prefix,
+                            term, terms[term]['from']))
                 else:
-                    raise ValueError('Cannot determine where term %s is from.' % term)
+                    raise ValueError(
+                        'Cannot determine where term %s is from.' % term)
             elif value:
                 many = isinstance(value, list)
                 if many:
                 if isinstance(value, Term):
                     terms[term] = {'from': prefix, 'symbol': True, 'many': many}
                 elif isinstance(value, URIRef):
-                    terms[term] = {'from': prefix, 'reference': True, 'many': many}
+                    terms[term] = {'from': prefix, 'reference': True,
+                        'many': many}
                 else:
                     terms[term] = {'from': prefix, 'many': many}
             else:
             n[k] = v
         return n
 
-    def to_json(self, ensure_ascii=False, indent=None, separators=(',', ':'), **kwargs):
-        return json.dumps(self._json_conv(self.to_tree()), ensure_ascii=ensure_ascii, indent=indent, separators=separators, **kwargs)
+    def to_json(self, ensure_ascii=False, indent=None, separators=(',', ':'),
+        **kwargs):
+
+        return json.dumps(self._json_conv(self.to_tree()),
+            ensure_ascii=ensure_ascii, indent=indent, separators=separators,
+            **kwargs)
 
 class one_uri(one):
     def type_raw_value(self, value, lang):
         else:
             return URIRef(value)
 
-class Typed(RdfQuery):
-    RDF_TYPE = None
-    a = one_uri(RDF.type)
-
+class Description(RdfQuery):
     def __init__(self, subject, *args, **kwargs):
-        super(Typed, self).__init__(_Graph(), '', subject if isinstance(subject, URIRef) else URIRef(subject), *args, **kwargs)
-        if self.RDF_TYPE:
-            self.a = self.RDF_TYPE
+        super(Description, self).__init__(_Graph(), '',
+            subject if isinstance(subject, URIRef) else URIRef(subject),
+            *args, **kwargs)
         self.prefixes = prefixes
 
     def __iter__(self):
 
     def to_graph(self, *args, **kwargs):
         if args:
-            g, args = args[0], args[1:]
+            g = args.pop(0)
         else:
             g = kwargs.pop('lgraph', _Graph())
         for prefix, uri in self.prefixes.iteritems():
             g.bind(prefix, uri)
-        return super(Typed, self).to_graph(lgraph=g, *args, **kwargs)
+        return super(Description, self).to_graph(lgraph=g, *args, **kwargs)
 
     def to_dict_untyped(self, keepSubject=False):
         d = {}
         if keepSubject:
             # TODO: sync with new property 'uri'
-            subjectKey = isinstance(keepSubject, str) and keepSubject or 'resource'
+            subjectKey = isinstance(keepSubject, str
+                ) and keepSubject or 'resource'
             subj = self._subject
             if subj and not isinstance(subj, BNode):
                 d[subjectKey] = self._subject
         else:
             return value # TODO: simple type conversions?
 
+class Typed(Description):
+    RDF_TYPE = None
+    a = one_uri(RDF.type)
+
+    def __init__(self, subject, *args, **kwargs):
+        super(Typed, self).__init__(subject, *args, **kwargs)
+        if self.RDF_TYPE:
+            self.a = self.RDF_TYPE
+
 class Data(Typed):
     isPartOf = one_uri(DCTERMS.isPartOf)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.