1010
1111from centralnicreseller .apiconnector .logger import Logger
1212from centralnicreseller .apiconnector .response import Response
13- from centralnicreseller .apiconnector .responsetemplatemanager import ResponseTemplateManager as RTM
13+ from centralnicreseller .apiconnector .responsetemplatemanager import (
14+ ResponseTemplateManager as RTM ,
15+ )
1416from centralnicreseller .apiconnector .socketconfig import SocketConfig
1517from centralnicreseller .apiconnector .idnaconverter import IDNAConverter
1618from urllib .parse import quote , unquote , urlparse , urlencode
@@ -124,8 +126,9 @@ def getPOSTData(self, cmd, secured=False):
124126 tmp = cmd .rstrip ("\n " )
125127 else :
126128 tmp = "\n " .join (
127- "{}={}" .format (key , re .sub (r'[\r\n]' , '' , str (cmd [key ])))
128- for key in sorted (cmd .keys ()) if cmd [key ] is not None
129+ "{}={}" .format (key , re .sub (r"[\r\n]" , "" , str (cmd [key ])))
130+ for key in sorted (cmd .keys ())
131+ if cmd [key ] is not None
129132 )
130133
131134 if secured :
@@ -134,7 +137,7 @@ def getPOSTData(self, cmd, secured=False):
134137 if tmp :
135138 return f"{ data } { quote ('s_command' )} ={ quote (tmp )} "
136139 else :
137- return data if not data .endswith ('&' ) else data .rstrip ('&' )
140+ return data if not data .endswith ("&" ) else data .rstrip ("&" )
138141
139142 def getURL (self ):
140143 """
@@ -203,7 +206,12 @@ def reuseSession(self, session):
203206 Use existing configuration out of session
204207 to rebuild and reuse connection settings
205208 """
206- if not session or "socketcfg" not in session or "login" not in session ["socketcfg" ] or "session" not in session ["socketcfg" ]:
209+ if (
210+ not session
211+ or "socketcfg" not in session
212+ or "login" not in session ["socketcfg" ]
213+ or "session" not in session ["socketcfg" ]
214+ ):
207215 return self
208216 self .setCredentials (session ["socketcfg" ]["login" ])
209217 self .__socketConfig .setSession (session ["socketcfg" ]["session" ])
@@ -217,7 +225,7 @@ def setURL(self, value):
217225 return self
218226
219227 def setPersistent (self ):
220- """echo
228+ """echo
221229 Set persistent connection to be used for API communication
222230 """
223231 self .__socketConfig .setPersistent ()
@@ -231,24 +239,29 @@ def setCredentials(self, uid, pw=""):
231239 self .__socketConfig .setPassword (pw )
232240 return self
233241
234- def setRoleCredentials (self , uid , role , pw = "" ):
242+ def setRoleCredentials (self , uid , role , pw = "" ):
235243 """
236244 Set Credentials to be used for API communication
237245 """
238246 if role == "" :
239247 return self .setCredentials (uid , pw )
240- return self .setCredentials (("{0}{1}{2}" ).format (uid , self .__roleSeparator , role ), pw )
248+ return self .setCredentials (
249+ ("{0}{1}{2}" ).format (uid , self .__roleSeparator , role ), pw
250+ )
241251
242252 def login (self ):
243253 """
244254 Perform API login to start session-based communication
245255 """
246256 self .setPersistent ()
247257 rr = self .request ([], False )
248- self .__socketConfig .setSession (None ) # clean up all session related data
258+ self .__socketConfig .setSession (None ) # clean up all session related data
249259 if rr .isSuccess ():
250260 col = rr .getColumn ("SESSIONID" )
251- self .__socketConfig .setSession (col .getData ()[0 ] if (col is not None ) else None )
261+ print ("session id" , col )
262+ self .__socketConfig .setSession (
263+ col .getData ()[0 ] if (col is not None ) else None
264+ )
252265 return rr
253266
254267 def logout (self ):
@@ -261,7 +274,7 @@ def logout(self):
261274 }
262275 )
263276 if rr .isSuccess ():
264- self .__socketConfig .setSession (None ) # clean up all session related data
277+ self .__socketConfig .setSession (None ) # clean up all session related data
265278 return rr
266279
267280 def request (self , cmd = [], setUserView = True ):
@@ -407,16 +420,21 @@ def __autoIDNConvert(self, cmd):
407420 """
408421 key_pattern = re .compile (r"(?i)^(NAMESERVER|NS|DNSZONE)([0-9]*)$" )
409422 obj_class_pattern = re .compile (
410- r"(?i)^(DOMAIN(APPLICATION|BLOCKING)?|NAMESERVER|NS|DNSZONE)$" )
423+ r"(?i)^(DOMAIN(APPLICATION|BLOCKING)?|NAMESERVER|NS|DNSZONE)$"
424+ )
411425 ascii_pattern = re .compile (r"^[A-Za-z0-9.\-]+$" )
412426
413427 to_convert = []
414428 idxs = []
415429
416430 for key , val in cmd .items ():
417- if ((key_pattern .match (key ) or
418- (key .upper () == "OBJECTID" and obj_class_pattern .match (cmd .get ("OBJECTCLASS" , "" ))))
419- and not ascii_pattern .match (val )):
431+ if (
432+ key_pattern .match (key )
433+ or (
434+ key .upper () == "OBJECTID"
435+ and obj_class_pattern .match (cmd .get ("OBJECTCLASS" , "" ))
436+ )
437+ ) and not ascii_pattern .match (val ):
420438 to_convert .append (val )
421439 idxs .append (key )
422440
0 commit comments