Best Python code snippet using pyresttest_python
taghash.py
Source:taghash.py
...300 """301 Patch `bs4.Tag` to include new functionality.302 :return:303 """304 bs4.Tag._feature_hash = six.get_unbound_function(TagHash._feature_hash)305 bs4.Tag._tag_hash = six.get_unbound_function(TagHash._tag_hash)306 bs4.Tag.hash = six.get_unbound_function(TagHash._hash)307 bs4.Tag.hash_compare = six.get_unbound_function(TagHash._tag_hash_compare)308 bs4.Tag._recursive_structure_xpath = six.get_unbound_function(TagHash._recursive_structure_xpath)309 bs4.Tag.structure_xpath = six.get_unbound_function(TagHash._structure_xpath)310 bs4.Tag._tag_sibling_position = six.get_unbound_function(TagHash._tag_sibling_position)311 bs4.Tag.identifying_xpath = six.get_unbound_function(TagHash._identifying_xpath)312 bs4.Tag.relative_xpath = six.get_unbound_function(TagHash._relative_xpath)313 bs4.Tag._recursive_count = six.get_unbound_function(TagHash._recursive_count)314 bs4.Tag.count = six.get_unbound_function(TagHash._count)315 bs4.Tag.lxml = TagHash._lxml316 bs4.Tag.iterate = six.get_unbound_function(TagHash._iterate)317 bs4.Tag.inner_text = TagHash._inner_text318 bs4.Tag.level = TagHash._level319 bs4.Tag.is_list = six.get_unbound_function(TagHash._is_list)...
repo.py
Source:repo.py
...11 """Object store that keeps all objects in a mysql database."""12 def __init__(self, repo):13 super(MysqlObjectStore, self).__init__()14 self._repo = repo15 add_objects = get_unbound_function(MemoryObjectStore.add_objects)16 add_thin_pack = get_unbound_function(MemoryObjectStore.add_thin_pack)17 contains_packed = get_unbound_function(MemoryObjectStore.contains_packed)18 packs = MemoryObjectStore.packs19 _complete_thin_pack = get_unbound_function(20 MemoryObjectStore._complete_thin_pack)21 def _to_hexsha(self, sha):22 if len(sha) == 40:23 return sha24 elif len(sha) == 20:25 return sha_to_hex(sha)26 else:27 raise ValueError("Invalid sha %r" % (sha,))28 def _has_sha(self, sha):29 """Look for the sha in the database."""30 return Objs.objects.filter(repo=self._repo, oid=sha).exists()31 def _all_shas(self):32 """Return all db sha keys."""33 for obj in Objs.objects.filter(repo=self._repo).only('oid').iterator():34 yield obj.oid35 def contains_loose(self, sha):36 """Check if a particular object is present by SHA1 and is loose."""37 return self._has_sha(self._to_hexsha(sha))38 def __iter__(self):39 """Iterate over the SHAs that are present in this store."""40 return self._all_shas()41 def get_raw(self, name):42 """Obtain the raw text for an object.43 :param name: sha for the object.44 :return: tuple with numeric type and object contents.45 """46 try:47 obj = Objs.objects.only('type', 'data')\48 .get(repo=self._repo, oid=self._to_hexsha(name))49 except Objs.DoesNotExist:50 # last resort fallback, this exception will cause a retry51 raise ObjectMissing(name)52 else:53 return obj.type, obj.data54 def add_object(self, obj):55 data = obj.as_raw_string()56 oid = obj.id57 tnum = obj.get_type()58 try:59 Objs.objects.update_or_create(60 repo=self._repo, oid=oid, type=tnum, size=len(data), data=data)61 except IntegrityError:62 pass63 def delete_objects(self, object_ids):64 Objs.objects.filter(repo=self._repo, oid__in=object_ids).delete()65class MysqlRefsContainer(RefsContainer):66 """RefsContainer backed by MySql.67 This container does not support packed references.68 """69 def __init__(self, repo):70 super(MysqlRefsContainer, self).__init__()71 self._repo = repo72 get_packed_refs = get_unbound_function(DictRefsContainer.get_packed_refs)73 def allkeys(self):74 for ref in Refs.objects.filter(repo=self._repo).only('ref').iterator():75 yield ref.ref76 def read_loose_ref(self, name):77 qs = Refs.objects.only('value')78 if not get_autocommit(using=qs._db):79 qs = qs.select_for_update()80 try:81 ref = qs.get(repo=self._repo, ref=name)82 except Refs.DoesNotExist:83 return None84 else:85 return ref.value86 def set_symbolic_ref(self, name, other):87 self._update_ref(name, SYMREF + other)88 def set_if_equals(self, name, old_ref, new_ref):89 if old_ref is not None and self.read_loose_ref(name) != old_ref:90 return False91 realnames, _ = self.follow(name)92 for realname in realnames:93 self._check_refname(realname)94 self._update_ref(realname, new_ref)95 return True96 def add_if_new(self, name, ref):97 if self.read_loose_ref(name):98 return False99 self._update_ref(name, ref)100 return True101 def remove_if_equals(self, name, old_ref):102 if old_ref is not None and self.read_loose_ref(name) != old_ref:103 return False104 self._remove_ref(name)105 return True106 def _update_ref(self, name, value):107 Refs.objects.update_or_create(repo=self._repo, ref=name, defaults={108 'value': value,109 })110 def _remove_ref(self, name):111 Refs.objects.filter(repo=self._repo, ref=name).delete()112class MysqlRepo(BaseRepo):113 """Repo that stores refs, objects, and named files in MySql.114 MySql repos are always bare: they have no working tree and no index, since115 those have a stronger dependency on the filesystem.116 """117 def __init__(self, name):118 self._name = name119 BaseRepo.__init__(self, MysqlObjectStore(name),120 MysqlRefsContainer(name))121 self.bare = True122 open_index = get_unbound_function(MemoryRepo.open_index)123 def head(self):124 """Return the SHA1 pointed at by HEAD."""125 return self.refs['refs/heads/master']126 @classmethod127 def init_bare(cls, name):128 """Create a new bare repository."""129 return cls(name)130 @classmethod131 def open(cls, name):132 """Open an existing repository."""133 return cls(name)134 @classmethod135 def repo_exists(cls, name):136 """Check if a repository exists."""...
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!!