-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathname_handler.py
33 lines (24 loc) · 980 Bytes
/
name_handler.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
import collections
class NameHandlerImpl:
def __init__(self):
self.cannonical_name = {}
self.aliases = collections.defaultdict(list)
self.collided_names = set()
for line in open('name_collisions.txt', 'r'):
self.collided_names.add(line.strip())
for line in open('aliases.txt', 'r'):
split_line = line.strip().split(',')
primary = split_line[0]
for source in split_line:
self.cannonical_name[source] = primary
if source != primary:
self.aliases[primary].append(source)
def GetPrimaryName(self, name, server):
#if name in self.collided_names:
# name = name + '@' + server
if name in self.cannonical_name:
return self.cannonical_name[name]
return name
def GetAliases(self, name):
return self.aliases[name]
name_handler = NameHandlerImpl()