summaryrefslogtreecommitdiff
path: root/plugins/python/androperms/stack.py
blob: 38431dce9a4d610992f6650713d54e2032e211c7 (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/python -u
# -*- coding: utf-8 -*-


class NamespaceStack():


    def __init__(self):

        #        self.increaseDepth()


        self._depth = 1

        self._prefix_2_uri = {}
        self._uri_2_prefix = {}

        self._pairs = []

        pass



    def getDepth(self):

        return self._depth


    def incDepth(self):

        self._depth += 1


    def decDepth(self):

        self._depth -= 1





    def count(self):
        """Provider the current number of active namespaces."""

        return len(self._pairs)







    def push(self, prefix, uri):

        self._prefix_2_uri[prefix] = uri
        self._uri_2_prefix[uri] = prefix

        self._pairs.append((prefix, uri))

        #print "PUSH", prefix, uri




    def pop(self):

        self._pairs.pop()

        #print "POP"





    def getPrefix(self, index):

        if index < len(self._pairs):
            return self._pairs[index][0]

        else:
            return -1


    def findPrefix(self, uri):

        if uri in self._uri_2_prefix:
            return self._uri_2_prefix[uri]

        else:
            return -1


    def getUri(self, index):

        if index < len(self._pairs):
            return self._pairs[index][1]

        else:
            return -1


    def findUri(self, prefix):

        if prefix in self._prefix_2_uri:
            return self._prefix_2_uri[prefix]

        else:
            return -1