Best Python code snippet using yandex-tank
readline.py
Source:readline.py
...214 config = ReadlineConfig()215 def __init__(self, f_in=None, f_out=None):216 self.f_in = f_in if f_in is not None else os.dup(0)217 self.f_out = f_out if f_out is not None else os.dup(1)218 def get_reader(self):219 if self.reader is None:220 console = UnixConsole(self.f_in, self.f_out, encoding=ENCODING)221 self.reader = ReadlineAlikeReader(console)222 self.reader.config = self.config223 return self.reader224 def raw_input(self, prompt=''):225 try:226 reader = self.get_reader()227 except _error:228 return _old_raw_input(prompt)229 reader.ps1 = prompt230 return reader.readline(startup_hook=self.startup_hook)231 def multiline_input(self, more_lines, ps1, ps2, returns_unicode=False):232 """Read an input on possibly multiple lines, asking for more233 lines as long as 'more_lines(unicodetext)' returns an object whose234 boolean value is true.235 """236 reader = self.get_reader()237 saved = reader.more_lines238 try:239 reader.more_lines = more_lines240 reader.ps1 = reader.ps2 = ps1241 reader.ps3 = reader.ps4 = ps2242 return reader.readline(returns_unicode=returns_unicode)243 finally:244 reader.more_lines = saved245 def parse_and_bind(self, string):246 pass # XXX we don't support parsing GNU-readline-style init files247 def set_completer(self, function=None):248 self.config.readline_completer = function249 def get_completer(self):250 return self.config.readline_completer251 def set_completer_delims(self, string):252 self.config.completer_delims = dict.fromkeys(string)253 def get_completer_delims(self):254 chars = self.config.completer_delims.keys()255 chars.sort()256 return ''.join(chars)257 def _histline(self, line):258 line = line.rstrip('\n')259 try:260 return unicode(line, ENCODING)261 except UnicodeDecodeError: # bah, silently fall back...262 return unicode(line, 'utf-8', 'replace')263 def get_history_length(self):264 return self.saved_history_length265 def set_history_length(self, length):266 self.saved_history_length = length267 def get_current_history_length(self):268 return len(self.get_reader().history)269 def read_history_file(self, filename='~/.history'):270 # multiline extension (really a hack) for the end of lines that271 # are actually continuations inside a single multiline_input()272 # history item: we use \r\n instead of just \n. If the history273 # file is passed to GNU readline, the extra \r are just ignored.274 history = self.get_reader().history275 f = open(os.path.expanduser(filename), 'r')276 buffer = []277 for line in f:278 if line.endswith('\r\n'):279 buffer.append(line)280 else:281 line = self._histline(line)282 if buffer:283 line = ''.join(buffer).replace('\r', '') + line284 del buffer[:]285 if line:286 history.append(line)287 f.close()288 def write_history_file(self, filename='~/.history'):289 maxlength = self.saved_history_length290 history = self.get_reader().get_trimmed_history(maxlength)291 f = open(os.path.expanduser(filename), 'w')292 for entry in history:293 if isinstance(entry, unicode):294 try:295 entry = entry.encode(ENCODING)296 except UnicodeEncodeError: # bah, silently fall back...297 entry = entry.encode('utf-8')298 entry = entry.replace('\n', '\r\n') # multiline history support299 f.write(entry + '\n')300 f.close()301 def clear_history(self):302 del self.get_reader().history[:]303 def get_history_item(self, index):304 history = self.get_reader().history305 if 1 <= index <= len(history):306 return history[index-1]307 else:308 return None # blame readline.c for not raising309 def remove_history_item(self, index):310 history = self.get_reader().history311 if 0 <= index < len(history):312 del history[index]313 else:314 raise ValueError("No history item at position %d" % index)315 # blame readline.c for raising ValueError316 def replace_history_item(self, index, line):317 history = self.get_reader().history318 if 0 <= index < len(history):319 history[index] = self._histline(line)320 else:321 raise ValueError("No history item at position %d" % index)322 # blame readline.c for raising ValueError323 def add_history(self, line):324 self.get_reader().history.append(self._histline(line))325 def set_startup_hook(self, function=None):326 self.startup_hook = function327 def get_line_buffer(self):328 return self.get_reader().get_buffer()329 def _get_idxs(self):330 start = cursor = self.get_reader().pos331 buf = self.get_line_buffer()332 for i in xrange(cursor - 1, -1, -1):333 if buf[i] in self.get_completer_delims():334 break335 start = i336 return start, cursor337 def get_begidx(self):338 return self._get_idxs()[0]339 def get_endidx(self):340 return self._get_idxs()[1]341 def insert_text(self, text):342 return self.get_reader().insert(text)343_wrapper = _ReadlineWrapper()344# ____________________________________________________________345# Public API346parse_and_bind = _wrapper.parse_and_bind347set_completer = _wrapper.set_completer348get_completer = _wrapper.get_completer349set_completer_delims = _wrapper.set_completer_delims350get_completer_delims = _wrapper.get_completer_delims351get_history_length = _wrapper.get_history_length352set_history_length = _wrapper.set_history_length353get_current_history_length = _wrapper.get_current_history_length354read_history_file = _wrapper.read_history_file355write_history_file = _wrapper.write_history_file356clear_history = _wrapper.clear_history357get_history_item = _wrapper.get_history_item358remove_history_item = _wrapper.remove_history_item359replace_history_item = _wrapper.replace_history_item360add_history = _wrapper.add_history361set_startup_hook = _wrapper.set_startup_hook362get_line_buffer = _wrapper.get_line_buffer363get_begidx = _wrapper.get_begidx364get_endidx = _wrapper.get_endidx365insert_text = _wrapper.insert_text366# Extension367multiline_input = _wrapper.multiline_input368# Internal hook369_get_reader = _wrapper.get_reader370# ____________________________________________________________371# Stubs372def _make_stub(_name, _ret):373 def stub(*args, **kwds):374 import warnings375 warnings.warn("readline.%s() not implemented" % _name, stacklevel=2)376 stub.func_name = _name377 globals()[_name] = stub378for _name, _ret in [379 ('read_init_file', None),380 ('redisplay', None),381 ('set_pre_input_hook', None),382 ]:383 assert _name not in globals(), _name384 _make_stub(_name, _ret)385# ____________________________________________________________386def _setup():387 global _old_raw_input388 if _old_raw_input is not None:389 return # don't run _setup twice390 try:391 f_in = sys.stdin.fileno()392 f_out = sys.stdout.fileno()393 except (AttributeError, ValueError):394 return395 if not os.isatty(f_in) or not os.isatty(f_out):396 return397 _wrapper.f_in = f_in398 _wrapper.f_out = f_out399 if '__pypy__' in sys.builtin_module_names: # PyPy400 def _old_raw_input(prompt=''):401 # sys.__raw_input__() is only called when stdin and stdout are402 # as expected and are ttys. If it is the case, then get_reader()403 # should not really fail in _wrapper.raw_input(). If it still404 # does, then we will just cancel the redirection and call again405 # the built-in raw_input().406 try:407 del sys.__raw_input__408 except AttributeError:409 pass410 return raw_input(prompt)411 sys.__raw_input__ = _wrapper.raw_input412 else:413 # this is not really what readline.c does. Better than nothing I guess414 import __builtin__415 _old_raw_input = __builtin__.raw_input416 __builtin__.raw_input = _wrapper.raw_input...
combine_gifs.py
Source:combine_gifs.py
...9 'frame_animation_SHOTGUN.gif',10 'frame_animation_SINGLEBACK.gif',11 'frame_animation_WILDCAT.gif']12#Create reader object for the gif13gif1 = imageio.get_reader(gifs[0])14gif2 = imageio.get_reader(gifs[1])15gif3 = imageio.get_reader(gifs[2])16gif4 = imageio.get_reader(gifs[3])17#If they don't have the same number of frame take the shorter18number_of_frames = min(gif1.get_length(), gif2.get_length()) 19#Create writer object20new_gif = imageio.get_writer('empty_i_jumbo_pistol.gif')21m = 3522n=12523for frame_number in range(number_of_frames):24 img1 = gif1.get_next_data()[m:576-m,n:576-n]25 img2 = gif2.get_next_data()[m:576-m,n:576-n]26 img3 = gif3.get_next_data()[m:576-m,n:576-n]27 img4 = gif4.get_next_data()[m:576-m,n:576-n]28 #here is the magic29 new_image = np.hstack((img1,img2,img3,img4))30 new_gif.append_data(new_image)31gif1.close()32gif2.close() 33gif3.close() 34gif4.close() 35new_gif.close()36#Create reader object for the gif37gif5 = imageio.get_reader(gifs[4])38gif6 = imageio.get_reader(gifs[5])39gif7 = imageio.get_reader(gifs[6])40#If they don't have the same number of frame take the shorter41number_of_frames = min(gif1.get_length(), gif2.get_length()) 42#Create writer object43new_gif = imageio.get_writer('shot_single_wildcat.gif')44m = 3545n=12546for frame_number in range(number_of_frames):47 img5 = gif5.get_next_data()[m:576-m,n:576-n]48 img6 = gif6.get_next_data()[m:576-m,n:576-n]49 img7 = gif7.get_next_data()[m:576-m,n:576-n]50 #here is the magic51 new_image = np.hstack((img5,img6,img7))52 new_gif.append_data(new_image)53 54gif5.close() 55gif6.close() 56gif7.close() 57new_gif.close()58gifs = ['frame_animation_Cover 0 Man.gif',59 'frame_animation_Cover 1 Man.gif',60 'frame_animation_Cover 2 Man.gif',61 'frame_animation_Cover 2 Zone.gif',62 'frame_animation_Cover 3 Zone.gif',63 'frame_animation_Cover 4 Zone.gif',64 'frame_animation_Cover 6 Zone.gif',65 'frame_animation_Prevent Zone.gif']66#Create reader object for the gif67gif1 = imageio.get_reader(gifs[0])68gif2 = imageio.get_reader(gifs[1])69gif3 = imageio.get_reader(gifs[2])70gif4 = imageio.get_reader(gifs[3])71#If they don't have the same number of frame take the shorter72number_of_frames = min(gif1.get_length(), gif2.get_length()) 73#Create writer object74new_gif = imageio.get_writer('cover_0M_1M_2M_2Z.gif')75m = 3576n=12577for frame_number in range(number_of_frames):78 img1 = gif1.get_next_data()[m:576-m,n:576-n]79 img2 = gif2.get_next_data()[m:576-m,n:576-n]80 img3 = gif3.get_next_data()[m:576-m,n:576-n]81 img4 = gif4.get_next_data()[m:576-m,n:576-n]82 #here is the magic83 new_image = np.hstack((img1,img2,img3,img4))84 new_gif.append_data(new_image)85gif1.close()86gif2.close() 87gif3.close() 88gif4.close() 89new_gif.close()90#Create reader object for the gif91gif5 = imageio.get_reader(gifs[4])92gif6 = imageio.get_reader(gifs[5])93gif7 = imageio.get_reader(gifs[6])94gif8 = imageio.get_reader(gifs[7])95#If they don't have the same number of frame take the shorter96number_of_frames = min(gif1.get_length(), gif2.get_length()) 97#Create writer object98new_gif = imageio.get_writer('cover_3z_4z_6z_pz.gif')99m = 35100n=125101for frame_number in range(number_of_frames):102 img5 = gif5.get_next_data()[m:576-m,n:576-n]103 img6 = gif6.get_next_data()[m:576-m,n:576-n]104 img7 = gif7.get_next_data()[m:576-m,n:576-n]105 img8 = gif8.get_next_data()[m:576-m,n:576-n]106 #here is the magic107 new_image = np.hstack((img5,img6,img7,img8))108 new_gif.append_data(new_image)...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!