How to use _iterlists method in autotest

Best Python code snippet using autotest_python

__init__.py

Source:__init__.py Github

copy

Full Screen

1# Stub file for six.2#This should have the same interface as the six module,3#but be much more tractable for static analysis.4"""Utilities for writing code that runs on Python 2 and 3"""5# Copyright (c) 2015 Semmle Limited6# All rights reserved7# Note that the original six module is copyright Benjamin Peterson8#9import operator10import sys11import types12__author__ = "Benjamin Peterson <benjamin@python.org>"13__version__ = "1.14.0"14# Useful for very coarse version differentiation.15PY2 = sys.version_info < (3,)16PY3 = sys.version_info >= (3,)17if PY3:18 string_types = str,19 integer_types = int,20 class_types = type,21 text_type = str22 binary_type = bytes23 MAXSIZE = sys.maxsize24else:25 string_types = basestring,26 integer_types = (int, long)27 class_types = (type, types.ClassType)28 text_type = unicode29 binary_type = str30 #We can't compute MAXSIZE, but it doesn't really matter31 MAXSIZE = int((1 << 63) - 1)32def _add_doc(func, doc):33 """Add documentation to a function."""34 func.__doc__ = doc35def _import_module(name):36 """Import module, returning the module after the last dot."""37 __import__(name)38 return sys.modules[name]39import six.moves as moves40def add_move(move):41 """Add an item to six.moves."""42 setattr(_MovedItems, move.name, move)43def remove_move(name):44 """Remove item from six.moves."""45 try:46 delattr(_MovedItems, name)47 except AttributeError:48 try:49 del moves.__dict__[name]50 except KeyError:51 raise AttributeError("no such move, %r" % (name,))52if PY3:53 _meth_func = "__func__"54 _meth_self = "__self__"55 _func_closure = "__closure__"56 _func_code = "__code__"57 _func_defaults = "__defaults__"58 _func_globals = "__globals__"59 _iterkeys = "keys"60 _itervalues = "values"61 _iteritems = "items"62 _iterlists = "lists"63else:64 _meth_func = "im_func"65 _meth_self = "im_self"66 _func_closure = "func_closure"67 _func_code = "func_code"68 _func_defaults = "func_defaults"69 _func_globals = "func_globals"70 _iterkeys = "iterkeys"71 _itervalues = "itervalues"72 _iteritems = "iteritems"73 _iterlists = "iterlists"74try:75 advance_iterator = next76except NameError:77 def advance_iterator(it):78 return it.next()79next = advance_iterator80try:81 callable = callable82except NameError:83 def callable(obj):84 return any("__call__" in klass.__dict__ for klass in type(obj).__mro__)85if PY3:86 def get_unbound_function(unbound):87 return unbound88 create_bound_method = types.MethodType89 Iterator = object90else:91 def get_unbound_function(unbound):92 return unbound.im_func93 def create_bound_method(func, obj):94 return types.MethodType(func, obj, obj.__class__)95 class Iterator(object):96 def next(self):97 return type(self).__next__(self)98 callable = callable99_add_doc(get_unbound_function,100 """Get the function out of a possibly unbound function""")101get_method_function = operator.attrgetter(_meth_func)102get_method_self = operator.attrgetter(_meth_self)103get_function_closure = operator.attrgetter(_func_closure)104get_function_code = operator.attrgetter(_func_code)105get_function_defaults = operator.attrgetter(_func_defaults)106get_function_globals = operator.attrgetter(_func_globals)107def iterkeys(d, **kw):108 """Return an iterator over the keys of a dictionary."""109 return iter(getattr(d, _iterkeys)(**kw))110def itervalues(d, **kw):111 """Return an iterator over the values of a dictionary."""112 return iter(getattr(d, _itervalues)(**kw))113def iteritems(d, **kw):114 """Return an iterator over the (key, value) pairs of a dictionary."""115 return iter(getattr(d, _iteritems)(**kw))116def iterlists(d, **kw):117 """Return an iterator over the (key, [values]) pairs of a dictionary."""118 return iter(getattr(d, _iterlists)(**kw))119def byte2int(ch): #type bytes -> int120 return int(unknown())121def b(s): #type str -> bytes122 """Byte literal"""123 return bytes(unknown())124def u(s): #type str -> unicode125 """Text literal"""126 if PY3:127 unicode = str128 return unicode(unknown())129if PY3:130 unichr = chr131 def int2byte(i): #type int -> bytes132 return bytes(unknown())133 indexbytes = operator.getitem134 iterbytes = iter135 import io136 StringIO = io.StringIO137 BytesIO = io.BytesIO138else:139 unichr = unichr140 int2byte = chr141 def indexbytes(buf, i):142 return int(unknown())143 def iterbytes(buf):144 return (int(unknown()) for byte in buf)145 import StringIO146 StringIO = BytesIO = StringIO.StringIO147if PY3:148 exec_ = getattr(six.moves.builtins, "exec")149 def reraise(tp, value, tb=None):150 """Reraise an exception."""151 if value.__traceback__ is not tb:152 raise value.with_traceback(tb)153 raise value154else:155 def exec_(_code_, _globs_=None, _locs_=None):156 pass157 def reraise(tp, value, tb=None):158 """Reraise an exception."""159 exc = tp(value)160 exc.__traceback__ = tb161 raise exc162print_ = getattr(moves.builtins, "print", None)163if print_ is None:164 def print_(*args, **kwargs):165 """The new-style print function for Python 2.4 and 2.5."""166 pass167def with_metaclass(meta, *bases):168 """Create a base class with a metaclass."""169 return meta("NewBase", bases, {})170def add_metaclass(metaclass):171 """Class decorator for creating a class with a metaclass."""172 def wrapper(cls):173 orig_vars = cls.__dict__.copy()174 orig_vars.pop('__dict__', None)175 orig_vars.pop('__weakref__', None)176 slots = orig_vars.get('__slots__')177 if slots is not None:178 if isinstance(slots, str):179 slots = [slots]180 for slots_var in slots:181 orig_vars.pop(slots_var)182 return metaclass(cls.__name__, cls.__bases__, orig_vars)...

Full Screen

Full Screen

utility_tags.py

Source:utility_tags.py Github

copy

Full Screen

...7@register.simple_tag(takes_context=True)8def modify_query(context, *params_to_remove, **params_to_change):9 """ Renders a link with modified current query parameters """10 query_params = []11 for key, value_list in context['request'].GET._iterlists():12 if not key in params_to_remove:13 # don't add key-value pairs for params to change14 if key in params_to_change:15 query_params.append((key, params_to_change[key]))16 params_to_change.pop(key)17 else:18 # leave existing parameters as they were if not mentioned in the params_to_change19 for value in value_list:20 query_params.append((key, value))21 # attach new params22 for key, value in params_to_change.items():23 query_params.append((key, value))24 query_string = context['request'].path25 if len(query_params):26 query_string += "?%s" % urllib.urlencode([27 (key, force_str(value)) for (key, value) in query_params if value28 ]).replace("&", "&amp;")29 return query_string30@register.simple_tag(takes_context=True)31def add_to_query(context, *params_to_remove, **params_to_add):32 """ Renders a link with modified current query parameters """33 query_params = []34 # go through current query params..35 for key, value_list in context['request'].GET._iterlists():36 if not key in params_to_remove:37 # don't add key-value pairs which already exist in the query38 if key in params_to_add and unicode(params_to_add[key]) in value_list:39 params_to_add.pop(key)40 for value in value_list:41 query_params.append((key, value))42 # add the rest key-value pairs43 for key, value in params_to_add.items():44 query_params.append((key, value))45 # empty values will be removed46 query_string = context['request'].path47 if len(query_params):48 query_string += "?%s" % urllib.urlencode([49 (key, force_str(value)) for (key, value) in query_params if value50 ]).replace("&", "&amp;")51 return query_string52@register.simple_tag(takes_context=True)53def remove_from_query(context, *args, **kwargs):54 """ Renders a link with modified current query parameters """55 query_params = []56 # go through current query params..57 for key, value_list in context['request'].GET._iterlists():58 # skip keys mentioned in the args59 if not key in args:60 for value in value_list:61 # skip key-value pairs mentioned in kwargs62 if not (key in kwargs and unicode(value) == unicode(kwargs[key])):63 query_params.append((key, value))64 # empty values will be removed65 query_string = context['request'].path66 if len(query_params):67 query_string = "?%s" % urllib.urlencode([68 (key, force_str(value)) for (key, value) in query_params if value69 ]).replace("&", "&amp;")...

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