@@ -90,10 +90,7 @@ def __init__(self, net):
9090 self .parsed ,self .netmask = self ._parse_net (net )
9191
9292 def __str__ (self ):
93- try :
94- return next (self .__iter__ ())
95- except StopIteration :
96- return None
93+ return next (self .__iter__ (), None )
9794
9895 def __iter__ (self ):
9996 for d in range (* self .parsed [3 ]):
@@ -102,10 +99,7 @@ def __iter__(self):
10299 for a in range (* self .parsed [0 ]):
103100 yield "%i.%i.%i.%i" % (a ,b ,c ,d )
104101 def choice (self ):
105- ip = []
106- for v in self .parsed :
107- ip .append (str (random .randint (v [0 ],v [1 ]- 1 )))
108- return "." .join (ip )
102+ return "." .join (str (random .randint (v [0 ], v [1 ] - 1 )) for v in self .parsed )
109103
110104 def __repr__ (self ):
111105 return "Net(%r)" % self .repr
@@ -120,10 +114,7 @@ def __contains__(self, other):
120114 p2 = other .parsed
121115 else :
122116 p2 ,nm2 = self ._parse_net (other )
123- for (a1 ,b1 ),(a2 ,b2 ) in zip (self .parsed ,p2 ):
124- if a1 > a2 or b1 < b2 :
125- return False
126- return True
117+ return all (a1 <= a2 and b1 >= b2 for (a1 , b1 ), (a2 , b2 ) in zip (self .parsed , p2 ))
127118 def __rcontains__ (self , other ):
128119 return self in self .__class__ (other )
129120
@@ -193,8 +184,7 @@ def __new__(cls, name, bases, dct):
193184
194185 dct ["fields_desc" ] = final_fld
195186
196- if "__slots__" not in dct :
197- dct ["__slots__" ] = []
187+ dct .setdefault ("__slots__" , [])
198188 for attr in ["name" , "overload_fields" ]:
199189 try :
200190 dct ["_%s" % attr ] = dct .pop (attr )
@@ -242,8 +232,7 @@ def __call__(cls, *args, **kargs):
242232
243233class Field_metaclass (type ):
244234 def __new__ (cls , name , bases , dct ):
245- if "__slots__" not in dct :
246- dct ["__slots__" ] = []
235+ dct .setdefault ("__slots__" , [])
247236 newcls = super (Field_metaclass , cls ).__new__ (cls , name , bases , dct )
248237 return newcls
249238
0 commit comments