-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontext.py
53 lines (44 loc) · 1.25 KB
/
context.py
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
#!/usr/bin/env python
# -*- coding: utf-8
#
#* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
# File Name : context.py
# Creation Date : 12-05-2012
# Last Modified : Sat 12 May 2012 09:25:05 PM EEST
# Created By : Greg Liras <[email protected]>
#_._._._._._._._._._._._._._._._._._._._._.*/
class GlobalLookupError(Exception):
def __init__(self,value):
self.value = value
def __str__(self):
return repr(self.value)
class LocalLookupError(Exception):
def __init__(self,value):
self.value = value
def __str__(self):
return repr(self.value)
class context(object):
def __init__(self,name,parent=None):
self.__name = name
self.__parent = parent
self.__entries = {}
def add(self,entry):
try:
sth = self.__entries[entry.name]
except:
self.__entries[entry.name] = entry
def lookupGL(self,st):
try:
return self.__entries[st]
except:
try:
return self.__parent.lookupGL(st)
except:
raise GlobalLookupError
def lookupCR(self,st):
try:
return self.__entries[st]
except:
raise LocalLookupError
def pop(self):
return self.__parent