How to use try_bind method in autotest

Best Python code snippet using autotest_python

grider.py

Source:grider.py Github

copy

Full Screen

...17 self.clean = False18 def run( self ):19 conn = None20 addr = None21 self.sock = self.parent.try_bind(9992)22 if self.sock is not None:23 self.sock.listen(1)24 print '[Paster] clean on port 9992'25 self.clean = True26 else:27 print '[Paster ERROR] no paste on port 9992'28 while self.clean:29 try:30 conn,addr = self.sock.accept()31 print '[Paster] Got copy from', addr32 except socket.timeout:33 pass34 except socket.error, e:35 if self.clean == False:36 print "[Paster] Socket Error /return : "+str(e)37 return38 else:39 print "[Paster] Socket Error /break : "+str(e)40 break41 else:42 data = conn.recv(4096)43 if data :44 l=len(data)45 print "[DEBUG] received data : "+data+"/"+str(l)+"/"+str(data.find("\n"))46 if data.find('\n')==-1 and data.find('\r')==-1:47 if data.find("#?#")!=-1:48 print "[DEBUG] adding to grid"49 fc=open(self.parent.target_dir+"grid.txt","a")50 fc.write(data+"\n")51 fc.close()52 elif data.find("#!#")!=-1:53 print "[DEBUG] adding to board"54 fc=open(self.parent.target_dir+"board.txt","a")55 fc.write(data+"\n")56 fc.close()57 elif data.find("#-#")!=-1:58 print "[DEBUG] adding to wargames"59 fc=open(self.parent.target_dir+"wargames.txt","a")60 fc.write(data+"\n")61 fc.close()62 conn.close()63 print '[Paster] done'64 self.sock.close()65 66class Grider ( Thread ):67 def __init__(self):68 Thread.__init__( self )69 self.daemon = True70 self.awake = True71 self.tmp_dir = "/tmp/"72 self.target_dir = '/var/www/ufonet/' 73 self.blackray = None74 self.absorber = None75 self.computer = None76 def dream(self):77 if not os.path.exists(self.target_dir+"grid.txt"):78 grid_fail = 079 try:80 fc = open(self.target_dir+'grid.txt', 'wb')81 fc.close()82 except:83 print "[Error] no grid.txt file in "+self.target_dir84 grid_fail = grid_fail + 185 else:86 grid_fail = 087 if not os.path.exists(self.target_dir+"board.txt"):88 board_fail = 089 try:90 fc = open(self.target_dir+'board.txt', 'wb')91 fc.close()92 except:93 print "[Error] no board.txt file in "+self.target_dir94 board_fail = board_fail + 195 else:96 board_fail = 097 if not os.path.exists(self.target_dir+"wargames.txt"):98 wargames_fail = 099 try:100 fc = open(self.target_dir+'wargames.txt', 'wb')101 fc.close()102 except:103 print "[Error] no wargames.txt file in "+self.target_dir104 wargames_fail = wargames_fail + 1105 else:106 wargames_fail = 0107 if not os.access(self.target_dir+"grid.txt",os.W_OK):108 print "[Error] write access denied for grid file in "+self.target_dir109 grid_fail = grid_fail + 1110 if not os.access(self.target_dir+"board.txt",os.W_OK):111 print "[Error] write access denied for board file in "+self.target_dir112 board_fail = board_fail + 1113 if not os.access(self.target_dir+"wargames.txt",os.W_OK):114 print "[Error] write access denied for wargames file in "+self.target_dir115 wargames_fail = wargames_fail + 1116 if grid_fail > 0 and board_fail > 0 and wargames_fail > 0:117 print "[Error] grid, board and wargames are unuseable. Aborting..."118 sys.exit(2)119 self.paster = Paster(self)120 self.awake = False121 print "[Grider] Having sweet dreams..."122 def try_bind(self, port):123 s=None124 try:125 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)126 s.settimeout(10)127 s.bind(('', port))128 except socket.error as e:129 if e.errno == 98: # if is in use wait a bit and retry130 time.sleep(3)131 return self.try_bind(port)132 print("[Grider Warning] socket busy, connection failed on port " + str(port))133 return s134 def run(self):135 self.dream()136 try:137 self.paster.start()138 if self.paster.clean:139 print "[Grider] Advancing time in another space (waiting for server)"+os.linesep140 time.sleep(1)141 while self.paster.clean:142 print "[Grider] Advancing time in another space (waiting for server)"+os.linesep143 time.sleep(1)144 print "\n[Grider] sheets are all up and ready"145 while self.paster.clean:...

Full Screen

Full Screen

proadmin_config_default.py

Source:proadmin_config_default.py Github

copy

Full Screen

...53 login = connection_settings[ 'login' ]54 password = connection_settings[ 'password' ]55 active_config = LDAPConfig( active_config.attributes, active_config.name )56 # try to connect to active directory by some dn57 def try_bind( dn ):58 return LDAPConnection.try_bind( server, dn, password )59 # if login cantains '=' and ',' symbols - it's some dn string60 if re.search('[=,]', login):61 dn = login62 else:63 user_dn = 'cn=Users'64 dn = "%(uid)s=%(login)s,%(user_dn)s,%(base_dn)s" % {65 "uid" : active_config.get_attribute( 'user_guid' ),66 "login" : login,67 "user_dn" : user_dn,68 "base_dn" : active_config.get_attribute( 'base_dn' ),69 }70 if not try_bind( dn ):71 dn += ',' + active_config.get_attribute( 'base_dn' )72 user_connection = LDAPConnection()73 user_connection.bind( server, dn, password )74 server = '127.0.0.1'75 login = 'cn=admin,dc=vdombox,dc=local'76 password = 'passwd'77 local_connection = LDAPConnection()78 local_connection.bind( server, login, password )79 scheme = ProAdmin.external_scheme( application.id, local_connection, user_connection, active_config )80 scheme.set_option( 'base_dn', connection_settings[ 'base_dn' ] )81 scheme.set_option( 'root_user', connection_settings[ 'root_user' ] )...

Full Screen

Full Screen

scope.py

Source:scope.py Github

copy

Full Screen

...14 def add_label(self, label):15 symbol = label.symbol16 name = self.get_mark_name(symbol.name)17 mark = label.mark(name)18 self.try_bind(symbol, mark)19 def add_definition(self, definition):20 symbol = definition.symbol21 name = self.get_mark_name(symbol.name)22 mark = definition.definition.mark(name).from_node(definition)23 self.try_bind(symbol, mark)24 def get_mark(self, symbol, *, required=True):25 name = symbol.name26 mark = self.find_name(name)27 if mark is not None:28 return mark29 elif required:30 msg = f'Unresolved symbol \'{name}\''31 self.optimizer.add_error(symbol, msg)32 def get_mark_name(self, name):33 if self.parent is None:34 return name35 elif self.id is None:36 self.id = self.get_next_id()37 return f'{name}.{self.id}'38 def try_bind(self, symbol, mark):39 name = symbol.name40 current = self.symbols.get(name)41 if current is None:42 self.symbols[name] = mark43 else:44 self.duplicates.add(name)45 msg = f'Symbol \'{name}\' already defined at l:{current.line}, c:{current.column}'46 self.optimizer.add_error(symbol, msg)47 def find_name(self, name):48 if name in self.duplicates:49 return50 elif name in self.symbols:51 return self.symbols[name]52 elif self.parent is not None:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful