Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/sugar
diff options
context:
space:
mode:
authorVincent Vinet <vince.vinet@gmail.com>2009-03-25 18:33:18 (GMT)
committer Vincent Vinet <vince.vinet@gmail.com>2009-03-31 14:01:20 (GMT)
commit18871f0d1b5eef4c6c3621e50a651f8760756ab6 (patch)
treea32cc9ccb61b7932782cdbf476d485757a946af3 /src/sugar
parent7f030fd302c0be7ca7dc38863e1d9250df00ca31 (diff)
Add the Universal Addressing Module (basic)
Diffstat (limited to 'src/sugar')
-rw-r--r--src/sugar/tutorius/Makefile.am1
-rw-r--r--src/sugar/tutorius/tests/uamtests.py45
-rw-r--r--src/sugar/tutorius/uam.py63
3 files changed, 109 insertions, 0 deletions
diff --git a/src/sugar/tutorius/Makefile.am b/src/sugar/tutorius/Makefile.am
index 9ff425e..b78fbd3 100644
--- a/src/sugar/tutorius/Makefile.am
+++ b/src/sugar/tutorius/Makefile.am
@@ -9,4 +9,5 @@ sugar_PYTHON = \
services.py \
overlayer.py \
editor.py \
+ uam.py \
linear_creator.py
diff --git a/src/sugar/tutorius/tests/uamtests.py b/src/sugar/tutorius/tests/uamtests.py
new file mode 100644
index 0000000..5bbebd4
--- /dev/null
+++ b/src/sugar/tutorius/tests/uamtests.py
@@ -0,0 +1,45 @@
+# Copyright (C) 2009, Tutorius.org
+# Copyright (C) 2009, Michael Janelle-Montcalm <michael.jmontcalm@gmail.com>
+# Copyright (C) 2009, Vincent Vinet <vince.vinet@gmail.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+import unittest
+
+from sugar.tutorius.uam import parse_uri
+
+PARSE_SUITE={
+#URI SCHEME HOST PARAMS PATH QUERY FRAGMENT
+"tap://act.tut.org/": ["tap", "act.tut.org","", "/", "", ""],
+"tap.gtk://a.t.o/0/1": ["tap.gtk","a.t.o","","/0/1","","",""],
+"tap.gobject://a.t.o/Timer?timeout=5":["tap.gobject","a.t.o","","/Timer","timeout=5",""],
+}
+
+class ParseUriTests(unittest.TestCase):
+ def test_parse_uri(self):
+ for uri, test in PARSE_SUITE.items():
+ res = parse_uri(uri)
+
+ assert res.scheme == test[0], "%s : Expected scheme %s, got %s" % (uri, test[0], res.scheme)
+ assert res.netloc == test[1], "%s : Expected netloc %s, got %s" % (uri, test[1], res.netloc)
+ assert res.params == test[2], "%s : Expected params %s, got %s" % (uri, test[2], res.params)
+ assert res.path == test[3], "%s : Expected path %s, got %s" % (uri, test[3], res.path)
+ assert res.query == test[4], "%s : Expected query %s, got %s" % (uri, test[4], res.query)
+ assert res.fragment == test[5], "%s : Expected fragment %s, got %s" % (uri, test[5], res.fragment)
+
+
+if __name__ == "__main__":
+ unittest.main()
+
diff --git a/src/sugar/tutorius/uam.py b/src/sugar/tutorius/uam.py
new file mode 100644
index 0000000..b55ae28
--- /dev/null
+++ b/src/sugar/tutorius/uam.py
@@ -0,0 +1,63 @@
+# Copyright (C) 2009, Tutorius.org
+# Copyright (C) 2009, Vincent Vinet <vince.vinet@gmail.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+"""
+Universal addressing module
+
+Allows addressing Events, signals, widgets, etc for supported platforms
+"""
+
+from urllib2 import urlparse
+
+SCHEMA="tap" #Tutorius Adressing Protocol
+
+SUBSCHEMAS = [
+ "gtk",
+ "pygame",
+ "gobject",
+]
+
+def __add_to_urlparse(name):
+ #Add to uses_netloc
+ if not name in urlparse.uses_netloc:
+ urlparse.uses_netloc.append(name)
+
+ #Add to uses_relative
+ if not name in urlparse.uses_relative:
+ urlparse.uses_relative.append(name)
+
+# #Add to uses_params
+# if not name in urlparse.uses_params:
+# urlparse.uses_params.append(name)
+
+ #Add to uses_query
+ if not name in urlparse.uses_query:
+ urlparse.uses_query.append(name)
+
+ #Add to uses_frament
+ if not name in urlparse.uses_fragment:
+ urlparse.uses_fragment.append(name)
+
+
+#Add schemas to urlparse
+__add_to_urlparse(SCHEMA)
+
+for subschema in [".".join([SCHEMA,s]) for s in SUBSCHEMAS]:
+ __add_to_urlparse(subschema)
+
+
+#For now, just export the urlparse urlparse method
+parse_uri = urlparse.urlparse