/usr/share/pyshared/tp/netlib/GenericRS.py is in python-tp-netlib 0.2.5-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 109 110 111 112 | class References(dict):
def __init__(self, references):
self.references = references
self.dirty = True
def types(self):
if len(self.references) > 0:
if self.dirty:
self.__types = zip(*self.references)[0]
return self.__types
return []
types = property(types)
def __len__(self):
return len(self.references)
def __iter__(self):
return self.references.__iter__()
def __str__(self):
s = "<References\n"
for type, value in self.references:
if type > 0:
s += "\t%s: %s\n" % (Types[type], value)
else:
value = globals()[Types[type].replace(" ","")][value]
s += "\t%s: '%s'\n" % (Types[type], value)
return s[:-1]+">"
def GetReferenceValue(self, type, value):
if type <= 0:
return globals()[Types[type].replace(" ","")][value]
else:
return value
class ReferenceDict(dict):
def __init__(self, dict):
self.reverse = {}
for key, value in dict.items():
self.reverse[value[0]] = key
self.forward = {}
for key, value in dict.items():
self.forward[key] = value[0]
self.__help = {}
for key, value in dict.items():
self.__help[key] = value[1]
self.__help[value[0]] = value[1]
def help(self, key):
"""\
A description of the object.
"""
return self.__help[key]
def __getitem__(self, key):
if self.forward.has_key(key):
return self.forward[key]
elif self.reverse.has_key(key):
return self.reverse[key]
raise KeyError("%s doesn't exist in the dictionary.")
def __setitem__(self, key, value):
raise RuntimeError("This dictionary is read only")
def __len__(self):
return len(self.forward)
Types = ReferenceDict({
-1000: ("Server Specific", ""),
-5: ("Design Action", ""),
-4: ("Player Action", ""),
-3: ("Message Action", ""),
-2: ("Order Action", ""),
-1: ("Object Action", ""),
0: ("Misc", ""),
1: ("Object", ""),
2: ("Order Type", ""),
3: ("Order Instance", ""),
4: ("Board", ""),
5: ("Message", ""),
6: ("Resource Description", ""),
7: ("Player", ""),
})
Misc = ReferenceDict({
1: ("System", "This message is from a the internal game system."),
2: ("Administration","This message is an message from game administrators."),
3: ("Important", "This message is flagged to be important."),
4: ("Unimportant", "This message is flagged as unimportant."),
})
PlayerAction = ReferenceDict({
1: ("Player Eliminated", "This message refers to the elimination of a player from the game"),
2: ("Player Quit", "This message refers to a player leaving the game"),
3: ("Player Joined", "This message refers to a new player joining the game"),
})
OrderAction = ReferenceDict({
1: ("Order Completion", "This message refers to a completion of an order."),
2: ("Order Canceled", "This message refers to the cancellation of an order."),
3: ("Order Incompatible", "This message refers to the inability to complete an order."),
4: ("Order Invalid", "This message refers to an order which is invalid."),
})
ObjectAction = ReferenceDict({
1: ("Object Idle", "this message refers to an object having nothing to do"),
})
if __name__ == "__main__":
print Misc[1], Misc["System"], Misc.help(1), Misc.help("System")
print References([(-1, 1), (-2, 3)])
|