Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tutorius/uam/__init__.py
blob: bcd67e10ec60508fc6330e10cbea67d84d0a154f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# 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 Mechanism module

Allows addressing Events, signals, widgets, etc for supported platforms
"""

from urllib2 import urlparse

import gtkparser
import gobjectparser


SCHEME="tap" #Tutorius Adressing Protocol

__parsers = {
    gtkparser.SCHEME:gtkparser.parse_gtk,
    gobjectparser.SCHEME:gobjectparser.parse_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 schemes to urlparse
__add_to_urlparse(SCHEME)

for subscheme in [".".join([SCHEME,s]) for s in __parsers]:
    __add_to_urlparse(subscheme)


class SchemeError(Exception):
    def __init__(self, message):
        Exception.__init__(self, message)
        ## Commenting this line as it is causing an error in the tests
        ##self.message = message


def parse_uri(uri):
    res = urlparse.urlparse(uri)

    scheme = res.scheme.split(".")[0]
    subscheme = ".".join(res.scheme.split(".")[1:])
    if not scheme == SCHEME:
        raise SchemeError("Scheme %s not supported" % scheme)

    if subscheme != "" and not subscheme in __parsers:
        raise SchemeError("SubScheme %s not supported" % subscheme)

    if subscheme:
        return __parsers[subscheme](res)

    return res