How to use _fetch_realm_info method in selenium-respectful

Best Python code snippet using selenium-respectful_python

respectful_requester.py

Source:respectful_requester.py Github

copy

Full Screen

...86 for realm in realms:87 self.unregister_realm(realm)88 return True89 def realm_max_requests(self, realm):90 realm_info = self._fetch_realm_info(realm)91 return int(realm_info["max_requests".encode("utf-8")].decode("utf-8"))92 def realm_timespan(self, realm):93 realm_info = self._fetch_realm_info(realm)94 return int(realm_info["timespan".encode("utf-8")].decode("utf-8"))95 @classmethod96 def configure(cls, **kwargs):97 if "redis" in kwargs:98 if type(kwargs["redis"]) != dict:99 raise RequestsRespectfulConfigError("'redis' key must be a dict")100 expected_redis_keys = ["host", "port", "password", "database"]101 missing_redis_keys = list()102 for expected_redis_key in expected_redis_keys:103 if expected_redis_key not in kwargs["redis"]:104 missing_redis_keys.append(expected_redis_key)105 if len(missing_redis_keys):106 raise RequestsRespectfulConfigError(107 "'%s' %s missing from the 'redis' configuration key"108 % (109 ", ".join(missing_redis_keys),110 "is" if len(missing_redis_keys) == 1 else "are",111 )112 )113 config["redis"] = kwargs["redis"]114 global redis115 redis = StrictRedis(116 host=config["redis"]["host"],117 port=config["redis"]["port"],118 password=config["redis"]["password"],119 db=config["redis"]["database"],120 )121 if "safety_threshold" in kwargs:122 if (123 type(kwargs["safety_threshold"]) != int124 or kwargs["safety_threshold"] < 0125 ):126 raise RequestsRespectfulConfigError(127 "'safety_threshold' key must be a positive integer"128 )129 config["safety_threshold"] = kwargs["safety_threshold"]130 if "requests_module_name" in kwargs:131 if type(kwargs["requests_module_name"]) != str:132 raise RequestsRespectfulConfigError(133 "'requests_module_name' key must be string"134 )135 config["requests_module_name"] = kwargs["requests_module_name"]136 return config137 @classmethod138 def configure_default(cls):139 for key in config:140 config[key] = default_config[key]141 return config142 def _perform_request(self, request_func, realms=None):143 self._validate_request_func(request_func)144 rate_limited_realms = list()145 for realm in realms:146 if not self._can_perform_request(realm):147 rate_limited_realms.append(realm)148 if not len(rate_limited_realms):149 for realm in realms:150 request_uuid = str(uuid.uuid4())151 self.redis.setex(152 name="%s:REQUEST:%s:%s" % (self.redis_prefix, realm, request_uuid),153 time=self.realm_timespan(realm),154 value=request_uuid,155 )156 return request_func()157 else:158 raise RequestsRespectfulRateLimitedError(159 "Currently rate-limited on Realm(s): %s"160 % ", ".join(rate_limited_realms)161 )162 def _realm_redis_key(self, realm):163 return "%s:REALMS:%s" % (self.redis_prefix, realm)164 def _fetch_realm_info(self, realm):165 redis_key = self._realm_redis_key(realm)166 return self.redis.hgetall(redis_key)167 def _requests_in_timespan(self, realm):168 return len(169 self.redis.scan(170 cursor=0,171 match="%s:REQUEST:%s:*" % (self.redis_prefix, realm),172 count=self._redis_keys_in_db() + 100,173 )[1]174 )175 def _redis_keys_in_db(self):176 return self.redis.info().get("db%d" % config["redis"]["database"]).get("keys")177 def _can_perform_request(self, realm):178 return self._requests_in_timespan(realm) < (...

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 selenium-respectful 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