8
8
9
9
class Singleton (type ):
10
10
_instances = {}
11
+
11
12
def __call__ (cls , * args , ** kwargs ):
12
13
if cls not in cls ._instances :
13
- cls ._instances [cls ] = super (Singleton , cls ).__call__ (* args , ** kwargs )
14
+ cls ._instances [cls ] = super (Singleton , cls ).__call__ (
15
+ * args , ** kwargs )
14
16
return cls ._instances [cls ]
15
17
16
18
@@ -92,6 +94,19 @@ def save_text(path, text):
92
94
out .write (text )
93
95
94
96
97
+ def get_reserved_words (resource_path , language ):
98
+ filename = "{}_keywords" .format (language )
99
+ path = os .path .join (resource_path , filename )
100
+ if os .path .isfile (path ):
101
+ with open (path , 'r' ) as f :
102
+ return {
103
+ line .strip ()
104
+ for line in f .readlines ()
105
+ }
106
+ else :
107
+ return set ()
108
+
109
+
95
110
class RandomUtils ():
96
111
97
112
resource_path = os .path .join (os .path .split (__file__ )[0 ], "resources" )
@@ -116,6 +131,11 @@ def word(self):
116
131
self .WORDS .remove (word )
117
132
return word
118
133
134
+ def remove_reserved_words (self , language ):
135
+ reserved_words = get_reserved_words (self .resource_path , language )
136
+ self .INITIAL_WORDS = self .INITIAL_WORDS - reserved_words
137
+ self .WORDS = self .WORDS - reserved_words
138
+
119
139
def integer (self , min_int = 0 , max_int = 10 ):
120
140
return self .r .randint (min_int , max_int )
121
141
0 commit comments