Repository: thegetty/crom

Issue:
Support tag: URIs for internal identity management

Rather than assigning UUIDs or other final URIs to instances, crom should support tag: URIs that are temporary carriers of the identity conditions, to then be substituted on the way into a more permanent infrastructure.  These would need to be assigned (they can't be auto-generated) and would be similar to the urn:uuid: pattern otherwise.

(/ht @kasei)

Discussion:

Patch:
diff --git a/cromulent/model.py b/cromulent/model.py
index 12997d8..e2363c1 100644
--- a/cromulent/model.py
+++ b/cromulent/model.py
@@ -371,10 +371,19 @@ class ExternalResource(object):
 	_type = ""
 	_embed = True
 
+
+	def _is_uri(self, what):
+		uri_schemes = ['urn:uuid:', 'tag:', 'data:', 'mailto:', 'info:', 'ftp:/', 'sftp:/'] 
+		for u in uri_schemes:
+			if what.startswith(u):
+				return True
+		return False
+
+
 	def __init__(self, ident=None):
 		self._factory = factory
 		if ident is not None:
-			if ident.startswith('urn:uuid'):
+			if self._is_uri(ident):
 				self.id = ident
 			elif ident.startswith('http'):
 				# Try to find prefixable term
@@ -395,7 +404,7 @@ class ExternalResource(object):
 				# Allow explicit setting of empty string
 				self.id = ""
 			else:
-				# Allow for prefixed term
+				# Allow for prefixed term that isn't ambiguously a URI
 				curied = ident.split(':', 1)
 				if len(curied) == 2 and curied[0] in self._factory.prefixes:
 					self.id = ident


Test patch:
diff --git a/tests/test_model.py b/tests/test_model.py
index 281d0f8..e85827c 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -269,6 +269,14 @@ class TestAutoIdentifiers(unittest.TestCase):
 		p4 = model.Person('fish:4')
 		self.assertTrue(p4.id.startswith(model.factory.base_url))
 
+	def test_other_uris(self):
+		p1 = model.Person(ident="tag:some-info-about-person")
+		self.assertEqual(p1.id, "tag:some-info-about-person")
+		p2 = model.Person(ident="info:ulan/500012345")
+		self.assertEqual(p2.id, "info:ulan/500012345")
+		p3 = model.Person(ident="some:random:thing:with:colons")
+		self.assertFalse(p3.id == "some:random:thing:with:colons")
+
 	def test_no_ident(self):
 
 		model.factory.auto_assign_id = True