Best Python code snippet using selenium-respectful_python
realms.py
Source:realms.py
...35 """36 sig_support_changed.connect(RealmBaseModel.cache_delete_most_voted_objects)37 signals.post_save.connect(ReferenceRealm.build_sitetree, sender=Reference)38 signals.post_delete.connect(ReferenceRealm.build_sitetree, sender=Reference)39def register_realms(*classes):40 """РегиÑÑÑиÑÑÐµÑ Ð¾Ð±Ð»Ð°ÑÑи (ÑÑÑноÑÑи), коÑоÑÑе Ð´Ð¾Ð»Ð¶Ð½Ñ Ð±ÑÑÑ Ð´Ð¾ÑÑÑÐ¿Ð½Ñ Ð½Ð° ÑайÑе.41 :param classes:42 :return:43 """44 for cls in classes:45 REALMS_REGISTRY[cls.get_names()[0]] = cls46 cls.init()47def get_realms_models():48 """ÐозвÑаÑÐ°ÐµÑ ÑпиÑок моделей вÑеÑ
облаÑÑей ÑайÑа.49 :rtype: list50 """51 return [r.model for r in get_realms().values()]52def get_realms():53 """ÐозвÑаÑÐ°ÐµÑ ÑловаÑÑ Ð·Ð°ÑегиÑÑÑиÑованнÑÑ
облаÑÑей ÑайÑа,54 индекÑиÑованнÑй именами облаÑÑей.55 :return:56 """57 return REALMS_REGISTRY58def get_realm(name):59 """ÐеÑнÑÑ Ð¾Ð±ÑÐµÑ Ð¾Ð±Ð»Ð°ÑÑи по ÐµÑ Ð¸Ð¼ÐµÐ½Ð¸, либо None.60 :param str name:61 :return:62 """63 realms = get_realms()64 realm = None65 try:66 realm = realms[name]67 except KeyError:68 pass69 return realm70def get_sitemaps():71 """ÐозвÑаÑÐ°ÐµÑ ÑловаÑÑ Ñ sitemap-диÑекÑивами Ð´Ð»Ñ Ð¿Ð¾Ð¸ÑковÑÑ
ÑиÑÑем.72 :return:73 """74 sitemaps = {}75 for realm in get_realms().values():76 if realm.sitemap_enabled:77 sitemaps[realm.name_plural] = realm.get_sitemap()78 return sitemaps79def get_realms_urls():80 """ÐозвÑаÑÐ°ÐµÑ url-ÑÐ°Ð±Ð»Ð¾Ð½Ñ Ð²ÑеÑ
заÑегиÑÑÑиÑованнÑÑ
облаÑÑей ÑайÑа.81 :return:82 """83 url_patterns = []84 for realm in get_realms().values():85 url_patterns += realm.get_urls()86 sitemaps = get_sitemaps()87 if sitemaps:88 url_patterns += [89 url(r'^sitemap\.xml$', sitemap, {'sitemaps': sitemaps})]90 return url_patterns91def get_sitetree_root_item(children=None):92 """ÐозвÑаÑÐ°ÐµÑ ÐºÐ¾Ñневой ÑÐ»ÐµÐ¼ÐµÐ½Ñ Ð´Ð¸Ð½Ð°Ð¼Ð¸ÑеÑкого дÑева ÑайÑа.93 :param tuple|generator children: ÐоÑеÑние динамиÑеÑкие ÑлеменÑÑ.94 """95 return item(96 'ÐÑо Python', '/', alias='topmenu', url_as_pattern=False,97 description='Ð¡Ð°Ð¹Ñ Ð¿Ñо ÐиÑон. РазлиÑнÑе маÑеÑÐ¸Ð°Ð»Ñ Ð¿Ð¾ ÑзÑÐºÑ Ð¿ÑогÑаммиÑÐ¾Ð²Ð°Ð½Ð¸Ñ Python: '98 'книги, видео, ÑпÑавоÑник, ÑообÑеÑÑва, ÑобÑÑиÑ, обÑÑÐ¶Ð´ÐµÐ½Ð¸Ñ Ð¸ многое дÑÑгое.',99 children=children)100def build_sitetree():101 """СÑÑÐ¾Ð¸Ñ Ð´Ñево ÑайÑа, иÑÑ
Ð¾Ð´Ñ Ð¸Ð· доÑÑÑпнÑÑ
облаÑÑей ÑайÑа.102 :return:103 """104 # ÐоÑакаем Ð¿Ð¾Ð²ÐµÐ´ÐµÐ½Ð¸Ñ Django 1.7 пÑи загÑÑзке пÑиложений.105 from sitetree.sitetreeapp import register_dynamic_trees, compose_dynamic_tree106 register_dynamic_trees(107 compose_dynamic_tree((108 tree('main', 'ÐÑновное деÑево', (109 get_sitetree_root_item((realm.get_sitetree_items() for realm in get_realms().values())),110 item('ÐÑ
од', 'login', access_guest=True, in_menu=False, in_breadcrumbs=False),111 item('', '/', alias='personal', url_as_pattern=False, access_loggedin=True, in_menu=False,112 in_sitetree=False, children=(113 item('ÐÑоÑилÑ', 'users:details request.user.id', access_loggedin=True, in_breadcrumbs=True,114 in_sitetree=False),115 item('ÐаÑÑÑойки', 'users:edit request.user.id', access_loggedin=True, in_breadcrumbs=True,116 in_sitetree=False),117 item('ÐÑÑ
од', 'logout', access_loggedin=True, in_breadcrumbs=False, in_sitetree=False),118 )),119 )),120 tree('about', 'РпÑоекÑе', (121 item('ЧÑо Ñакое Python', '/promo/',122 description='ÐÑаÑкие ÑÐ²ÐµÐ´ÐµÐ½Ð¸Ñ Ð¾ возможноÑÑÑÑ
и облаÑÑÑÑ
пÑÐ¸Ð¼ÐµÐ½ÐµÐ½Ð¸Ñ ÑзÑка пÑогÑаммиÑÐ¾Ð²Ð°Ð½Ð¸Ñ Python.',123 url_as_pattern=False),124 item('РпÑоекÑе', '/about/',125 description='ÐнÑоÑмаÑÐ¸Ñ Ð¾ пÑоекÑе. Ð Ñом, как, кем и Ð´Ð»Ñ Ñего ÑазÑабаÑÑваеÑÑÑ Ð´Ð°Ð½Ð½Ñй ÑайÑ.',126 url_as_pattern=False),127 item('ÐаÑÑа ÑайÑа', '/sitemap/', description='СпиÑок Ñазделов на ÑайÑе оÑоÑмленнÑй в виде каÑÑÑ ÑайÑа.',128 url_as_pattern=False),129 item('ÐоиÑк по ÑайÑÑ', '/search/site/',130 description='ÐлобалÑнÑй поиÑк по маÑеÑиалам, ÑаÑположеннÑм на ÑайÑе.',131 url_as_pattern=False),132 item('РезÑлÑÑаÑÑ Ð¿Ð¾Ð¸Ñка «{{ search_term }}»', '/search/', url_as_pattern=False, in_menu=False,133 in_sitetree=False),134 ))135 )),136 reset_cache=True137 )138 ReferenceRealm.build_sitetree()139class BookRealm(RealmBase):140 """141 ÐблаÑÑÑ Ñ ÐºÐ½Ð¸Ð³Ð°Ð¼Ð¸.142 """143 txt_form_add = 'ÐобавиÑÑ ÐºÐ½Ð¸Ð³Ñ'144 txt_form_edit = 'ÐзмениÑÑ ÐºÐ½Ð¸Ð³Ñ'145 view_listing_description = 'Ðниги по пÑогÑаммиÑÐ¾Ð²Ð°Ð½Ð¸Ñ Ð²Ð¾Ð¾Ð±Ñе и на ÑзÑке Python в ÑаÑÑноÑÑи.'146 view_listing_keywords = 'книги по пиÑонÑ, лиÑеÑаÑÑÑа по python'147 model = Book148 form = BookForm149 icon = 'book'150class VideoRealm(RealmBase):151 """152 ÐблаÑÑÑ Ñ Ð²Ð¸Ð´ÐµÐ¾.153 """154 txt_form_add = 'ÐобавиÑÑ Ð²Ð¸Ð´ÐµÐ¾'155 txt_form_edit = 'ÐзмениÑÑ Ð²Ð¸Ð´ÐµÐ¾'156 view_listing_description = 'Ðидео-запиÑи лекÑий, кÑÑÑов, докладов, ÑвÑзаннÑе Ñ ÑзÑком пÑогÑаммиÑÐ¾Ð²Ð°Ð½Ð¸Ñ Python.'157 view_listing_keywords = 'видео по пиÑонÑ, Ð´Ð¾ÐºÐ»Ð°Ð´Ñ Ð¿Ð¾ python'158 model = Video159 form = VideoForm160 icon = 'film'161class EventRealm(RealmBase):162 """163 ÐблаÑÑÑ Ñ ÑобÑÑиÑми.164 """165 view_listing_description = 'СобÑÑиÑ, коÑоÑÑе могÑÑ Ð·Ð°Ð¸Ð½ÑеÑеÑоваÑÑ Ð¿Ð¸ÑониÑÑов: вÑÑÑеÑи, конÑеÑенÑии, ÑпÑинÑÑ, и пÑ.'166 view_listing_keywords = 'конÑеÑенÑии по пиÑонÑ, вÑÑÑеÑи ÑообÑеÑÑв python'167 txt_form_add = 'ÐобавиÑÑ ÑобÑÑие'168 txt_form_edit = 'ÐзмениÑÑ ÑобÑÑие'169 model = Event170 form = EventForm171 icon = 'calendar'172class VacancyRealm(RealmBase):173 """174 ÐблаÑÑÑ Ñ Ð²Ð°ÐºÐ°Ð½ÑиÑми.175 """176 allowed_views = ('listing',)177 name_plural = 'vacancies'178 show_on_main = False179 view_listing_description = 'СпиÑок ваканÑий, Ñак или инаÑе ÑвÑзаннÑÑ
Ñ ÑзÑком пÑогÑаммиÑÐ¾Ð²Ð°Ð½Ð¸Ñ Python.'180 view_listing_keywords = 'ваканÑии python, ÑабоÑа пиÑон'181 view_listing_base_class = VacancyListingView182 model = Vacancy183 icon = 'briefcase'184 sitemap_enabled = False185class ReferenceRealm(RealmBase):186 """187 ÐблаÑÑÑ Ñо ÑпÑавоÑниками.188 """189 allowed_views = ('listing', 'details', 'add', 'edit')190 syndication_enabled = False191 txt_form_add = 'ÐополниÑÑ ÑпÑавоÑник'192 txt_form_edit = 'РедакÑиÑоваÑÑ ÑÑаÑÑÑ'193 view_listing_description = 'СпÑавоÑнÑе и обÑÑаÑÑие маÑеÑÐ¸Ð°Ð»Ñ Ð¿Ð¾ ÑзÑÐºÑ Ð¿ÑогÑаммиÑÐ¾Ð²Ð°Ð½Ð¸Ñ Python.'194 view_listing_keywords = 'ÑпÑавоÑник пиÑон, ÑÑководÑÑво python'195 view_listing_base_class = ReferenceListingView196 view_details_base_class = ReferenceDetailsView197 model = Reference198 form = ReferenceForm199 icon = 'search'200 @classmethod201 def build_sitetree(cls, **kwargs):202 """СÑÑÐ¾Ð¸Ñ Ð´Ð¸Ð½Ð°Ð¼Ð¸ÑеÑкое деÑево ÑпÑавоÑника под именем `references`."""203 root_id = object()204 root_item = get_sitetree_root_item()205 temp_ref_items = {root_id: root_item}206 ref_items = list(cls.model.get_actual().select_related('parent').only(207 'id', 'parent_id', 'parent__title', 'slug', 'status'208 ).order_by('parent_id', 'title', 'id'))209 def get_tree_item(ref_item):210 item_id = getattr(ref_item, 'id', root_id)211 tree_item = temp_ref_items.get(item_id)212 if not tree_item:213 tree_item = item(ref_item.title, ref_item.get_absolute_url(), url_as_pattern=False)214 temp_ref_items[item_id] = tree_item215 return tree_item216 for ref_item in ref_items:217 parent = get_tree_item(ref_item.parent)218 child = get_tree_item(ref_item)219 child.parent = parent220 parent.dynamic_children.append(child)221 from sitetree.sitetreeapp import register_dynamic_trees, compose_dynamic_tree222 register_dynamic_trees(compose_dynamic_tree([tree('references', items=[root_item])]), reset_cache=True)223class ArticleRealm(RealmBase):224 """225 ÐблаÑÑÑ Ñо ÑÑаÑÑÑми.226 """227 txt_form_add = 'ÐобавиÑÑ ÑÑаÑÑÑ'228 txt_form_edit = 'РедакÑиÑоваÑÑ ÑÑаÑÑÑ'229 view_listing_description = 'СÑаÑÑи и замеÑки, ÑвÑзаннÑе Ñ Ð¿ÑогÑаммиÑованием Python и не ÑолÑко.'230 view_listing_keywords = 'ÑÑаÑÑи о пиÑоне, маÑеÑÐ¸Ð°Ð»Ñ Ð¿Ð¾ python'231 model = Article232 form = ArticleForm233 icon = 'file-o'234class PlaceRealm(RealmBase):235 """236 ÐблаÑÑÑ Ñ Ð³ÐµÐ¾Ð³ÑаÑиÑеÑкими обÑекÑами (меÑÑами).237 """238 view_listing_description = 'ÐеÑÑа, Ñак или инаÑе ÑвÑзаннÑе Ñ ÑзÑком пÑогÑаммиÑÐ¾Ð²Ð°Ð½Ð¸Ñ Python.'239 view_listing_keywords = 'python в гоÑоде, где пÑогÑаммиÑÑÑÑ Ð½Ð° пиÑоне'240 view_listing_base_class = PlaceListingView241 view_details_base_class = PlaceDetailsView242 model = Place243 form = VideoForm244 icon = 'globe'245 sitemap_changefreq = 'weekly'246 allowed_views = ('listing', 'details')247 show_on_main = False248 show_on_top = False249class DiscussionRealm(RealmBase):250 """251 ÐблаÑÑÑ Ð¾Ð±ÑÑждений.252 """253 txt_form_add = 'СоздаÑÑ Ð¾Ð±ÑÑждение'254 txt_form_edit = 'РедакÑиÑоваÑÑ Ð¾Ð±ÑÑждение'255 view_listing_description = 'ÐбÑÑÐ¶Ð´ÐµÐ½Ð¸Ñ Ð²Ð¾Ð¿ÑоÑов, ÑвÑзаннÑÑ
Ñ Ð¿ÑогÑаммиÑованием на ÐиÑоне.'256 view_listing_keywords = 'вопÑоÑÑ Ð¿Ð¾ пиÑонÑ, обÑÑÐ¶Ð´ÐµÐ½Ð¸Ñ python'257 model = Discussion258 form = DiscussionForm259 icon = 'comments-o'260 show_on_top = False261class UserRealm(RealmBase):262 """263 ÐблаÑÑÑ Ñ Ð¿Ð¾Ð»ÑзоваÑелÑми ÑайÑа.264 """265 txt_form_edit = 'ÐзмениÑÑ Ð½Ð°ÑÑÑойки'266 view_listing_description = 'СпиÑок полÑзоваÑелей ÑайÑа.'267 view_listing_keywords = 'пиÑониÑÑÑ, ÑазÑабоÑÑики python, полÑзоваÑели ÑайÑа'268 view_details_base_class = UserDetailsView269 view_edit_base_class = UserEditView270 model = User271 form = UserForm272 icon = 'users'273 sitemap_date_field = 'date_joined'274 sitemap_changefreq = 'weekly'275 allowed_views = ('listing', 'details', 'edit')276 show_on_main = False277 show_on_top = False278 syndication_enabled = False279 @classmethod280 def get_sitetree_details_item(cls):281 return item('{{ user.get_display_name }}', 'users:details user.id', in_menu=False, in_sitetree=False)282class CategoryRealm(RealmBase):283 """284 ÐблаÑÑÑ Ñ ÐºÐ°ÑегоÑиÑми.285 """286 view_listing_description = 'ÐаÑÑа каÑегоÑий маÑеÑиалов по ÑзÑÐºÑ Ð¿ÑогÑаммиÑÐ¾Ð²Ð°Ð½Ð¸Ñ Python доÑÑÑпнÑÑ
на ÑайÑе.'287 view_listing_keywords = 'маÑеÑÐ¸Ð°Ð»Ñ Ð¿Ð¾ пиÑонÑ, python по каÑегоÑиÑм'288 model = get_category_model()289 icon = 'tag'290 name = 'category'291 name_plural = 'categories'292 allowed_views = ('listing', 'details')293 ready_for_digest = False294 sitemap_enabled = False295 show_on_main = False296 show_on_top = False297 view_listing_title = 'ÐÑÑеводиÑелÑ'298 view_listing_base_class = CategoryListingView299 view_details_base_class = CategoryListingView300 SYNDICATION_NAMESPACE = 'category_feeds'301 @classmethod302 def get_sitetree_details_item(cls):303 return item(304 'ÐаÑегоÑÐ¸Ñ Â«{{ category.parent.title }} â {{ category.title }}»', 'categories:details category.id',305 in_menu=False, in_sitetree=False)306 @classmethod307 def init(cls):308 # ÐклÑÑаем пÑоÑлÑÑивание Ñигналов, необÑ
одимое Ð´Ð»Ñ ÑÑнкÑиониÑÐ¾Ð²Ð°Ñ Ð¾Ð±Ð»Ð°ÑÑи.309 tie_model = get_tie_model()310 # url-ÑиндикаÑии бÑдÑÑ Ð¾Ð±Ð½Ð¾Ð²Ð»ÐµÐ½Ñ Ð² ÑлÑÑае добавлениÑ/ÑÐ´Ð°Ð»ÐµÐ½Ð¸Ñ ÑвÑзи ÑÑÑноÑÑи Ñ ÐºÐ°ÑегоÑией.311 signals.post_save.connect(cls.update_syndication_urls, sender=tie_model)312 signals.post_delete.connect(cls.update_syndication_urls, sender=tie_model)313 @classmethod314 def get_urls(cls):315 urls = super().get_urls()316 urls += CategoryRealm.get_syndication_urls()317 return urls318 @classmethod319 def get_syndication_url(cls):320 return 'feed/'321 @classmethod322 def update_syndication_urls(cls, **kwargs):323 """ÐбновлÑÐµÑ url-ÑÐ°Ð±Ð»Ð¾Ð½Ñ ÑиндикаÑии, заменÑÑ ÑÑаÑÑе новÑми."""324 target_namespace = cls.SYNDICATION_NAMESPACE325 linked_category_id_str = 'category_%s' % kwargs['instance'].category_id326 pattern_idx = -1327 resolver = get_resolver(None)328 urlpatterns = getattr(resolver.urlconf_module, 'urlpatterns', resolver.urlconf_module)329 for idx, pattern in enumerate(urlpatterns):330 if getattr(pattern, 'namespace', '') == target_namespace:331 pattern_idx = idx332 if linked_category_id_str in pattern.reverse_dict.keys():333 # ÐаÑегоÑÐ¸Ñ Ð±Ñла извеÑÑна и Ñанее, пеÑепÑивÑзка URL не ÑÑебÑеÑÑÑ.334 return335 break336 if pattern_idx > -1:337 del urlpatterns[pattern_idx]338 urlpatterns += cls.get_syndication_urls()339 @classmethod340 def get_syndication_urls(cls):341 """ÐозвÑаÑÐ°ÐµÑ url-ÑÐ°Ð±Ð»Ð¾Ð½Ñ Ñ Ð¿ÑивÑзаннÑми ÑгенеÑиÑованнÑми пÑедÑÑавлениÑми342 Ð´Ð»Ñ Ð¿Ð¾Ñоков ÑиндикаÑии (RSS) Ñ Ð¿ÐµÑеÑиÑлением новÑÑ
маÑеÑиалов в каÑегоÑиÑÑ
.343 :return:344 """345 feeds = []346 tie_model = get_tie_model()347 categories = tie_model.get_linked_objects(by_category=True)348 def get_in_category(category_id):349 """ÐозвÑаÑÐ°ÐµÑ Ð¾Ð±ÑекÑÑ Ð¸Ð· ÑазнÑÑ
облаÑÑей в Ñказанной каÑегоÑии."""350 linked = tie_model.get_linked_objects(filter_kwargs={'category_id': category_id}, id_only=True)351 result = []352 for model, ids in linked.items():353 result.extend(model.get_actual().filter(id__in=ids)[:SYNDICATION_ITEMS_LIMIT])354 result = sorted(result, key=attrgetter('time_published'), reverse=True)355 return result[:SYNDICATION_ITEMS_LIMIT]356 for category in categories.keys():357 title = category.title358 category_id = category.id359 feed = RealmBase._get_syndication_feed(360 title=title,361 description='ÐаÑеÑÐ¸Ð°Ð»Ñ Ð² каÑегоÑии «%s». %s' % (title, category.note),362 func_link=lambda self: reverse(CategoryRealm.get_details_urlname(), args=[self.category_id]),363 func_items=lambda self: get_in_category(self.category_id),364 cls_name='Category%s' % category_id365 )366 feed.category_id = category_id367 feeds.append(368 url(r'^%s/%s/$' % (category_id, SYNDICATION_URL_MARKER), feed, name='category_%s' % category_id))369 _, realm_name_plural = CategoryRealm.get_names()370 return [url(r'^%s/' % realm_name_plural, (feeds, realm_name_plural, cls.SYNDICATION_NAMESPACE))]371class CommunityRealm(RealmBase):372 """373 ÐблаÑÑÑ Ñ ÑообÑеÑÑвами.374 """375 txt_form_add = 'ÐобавиÑÑ ÑообÑеÑÑво'376 txt_form_edit = 'РедакÑиÑоваÑÑ ÑообÑеÑÑво'377 view_listing_description = 'СообÑеÑÑва лÑдей инÑеÑеÑÑÑÑиÑ
ÑÑ Ð¸ занимаÑÑиÑ
ÑÑ Ð¿ÑогÑаммиÑованием на ÐиÑоне.'378 view_listing_keywords = 'ÑообÑеÑÑва пиÑониÑÑов, пÑогÑаммиÑÑÑ python'379 name = 'community'380 name_plural = 'communities'381 model = Community382 form = CommunityForm383 icon = 'building-o'384 show_on_main = False385 show_on_top = False386class VersionRealm(RealmBase):387 """388 ÐблаÑÑÑ Ñ Ð²ÐµÑÑиÑми.389 """390 txt_form_add = 'ÐобавиÑÑ Ð²ÐµÑÑиÑ'391 txt_form_edit = 'РедакÑиÑоваÑÑ Ð²ÐµÑÑиÑ'392 view_listing_description = 'ÐÑÑедÑие и бÑдÑÑие вÑпÑÑки Python.'393 view_listing_keywords = 'веÑÑии python, вÑпÑÑки ÐиÑона'394 allowed_views = ('listing', 'details', 'add', 'edit')395 view_details_base_class = VersionDetailsView396 name = 'version'397 name_plural = 'versions'398 model = Version399 form = VersionForm400 icon = 'code-fork'401 syndication_enabled = False402 show_on_top = False403class PepRealm(RealmBase):404 """405 ÐблаÑÑÑ Ñ Ð¿ÑедложениÑми по ÑлÑÑÑениÑ.406 """407 view_listing_description = 'ÐÑÐµÐ´Ð»Ð¾Ð¶ÐµÐ½Ð¸Ñ Ð¿Ð¾ ÑлÑÑÑÐµÐ½Ð¸Ñ ÐиÑона (PEP).'408 view_listing_keywords = 'python pep, пÑÐµÐ»Ð¾Ð¶ÐµÐ½Ð¸Ñ Ð¿Ð¾ ÑлÑÑÑениÑ, пепÑ, пеп'409 allowed_views = ('listing', 'details')410 name = 'pep'411 name_plural = 'peps'412 model = PEP413 icon = 'bell'414 show_on_top = False415class PersonRealm(RealmBase):416 """ÐблаÑÑÑ Ð¿ÐµÑÑон."""417 view_listing_description = 'ÐеÑÑонÑ, Ñем или инÑм обÑазом ÑвÑзаннÑе Ñ ÑзÑком Python.'418 view_listing_keywords = 'пеÑÑÐ¾Ð½Ñ python, пиÑониÑÑÑ, ÑазÑабоÑÑики python'419 allowed_views = ('listing', 'details')420 view_details_base_class = PersonDetailsView421 name = 'person'422 name_plural = 'persons'423 model = Person424 icon = 'user'425 show_on_main = False426 show_on_top = False427 syndication_enabled = False428 ready_for_digest = False429register_realms(430 CategoryRealm,431 ArticleRealm,432 ReferenceRealm,433 VideoRealm,434 BookRealm,435 VacancyRealm,436 EventRealm,437 PlaceRealm,438 DiscussionRealm,439 CommunityRealm,440 VersionRealm,441 PepRealm,442 PersonRealm,443 UserRealm,...
respectful_requester.py
Source:respectful_requester.py
...64 redis_key, {"max_requests": max_requests, "timespan": timespan}65 )66 self.redis.sadd("%s:REALMS" % self.redis_prefix, realm)67 return True68 def register_realms(self, realm_tuples):69 for realm_tuple in realm_tuples:70 self.register_realm(*realm_tuple)71 return True72 def update_realm(self, realm, **kwargs):73 redis_key = self._realm_redis_key(realm)74 updatable_keys = ["max_requests", "timespan"]75 for updatable_key in updatable_keys:76 if updatable_key in kwargs and type(kwargs[updatable_key]) == int:77 self.redis.hset(redis_key, updatable_key, kwargs[updatable_key])78 return True79 def unregister_realm(self, realm):80 self.redis.delete(self._realm_redis_key(realm))81 self.redis.srem("%s:REALMS" % self.redis_prefix, realm)82 request_keys = self.redis.keys("%s:REQUEST:%s:*" % (self.redis_prefix, realm))83 [self.redis.delete(k) for k in request_keys]84 return True85 def unregister_realms(self, realms):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")...
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!!