How to use reject method in Playwright Internal

Best JavaScript code snippet using playwright-internal

router.py

Source:router.py Github

copy

Full Screen

1# Copyright 2012 OpenStack Foundation.2# All Rights Reserved.3#4# Licensed under the Apache License, Version 2.0 (the "License"); you may5# not use this file except in compliance with the License. You may obtain6# a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the13# License for the specific language governing permissions and limitations14# under the License.15from glance.api.v2 import image_actions16from glance.api.v2 import image_data17from glance.api.v2 import image_members18from glance.api.v2 import image_tags19from glance.api.v2 import images20from glance.api.v2 import metadef_namespaces21from glance.api.v2 import metadef_objects22from glance.api.v2 import metadef_properties23from glance.api.v2 import metadef_resource_types24from glance.api.v2 import metadef_tags25from glance.api.v2 import schemas26from glance.api.v2 import tasks27from glance.common import wsgi28class API(wsgi.Router):29 """WSGI router for Glance v2 API requests."""30 def __init__(self, mapper):31 custom_image_properties = images.load_custom_properties()32 reject_method_resource = wsgi.Resource(wsgi.RejectMethodController())33 schemas_resource = schemas.create_resource(custom_image_properties)34 mapper.connect('/schemas/image',35 controller=schemas_resource,36 action='image',37 conditions={'method': ['GET']})38 mapper.connect('/schemas/image',39 controller=reject_method_resource,40 action='reject',41 allowed_methods='GET',42 conditions={'method': ['POST', 'PUT', 'DELETE',43 'PATCH', 'HEAD']})44 mapper.connect('/schemas/images',45 controller=schemas_resource,46 action='images',47 conditions={'method': ['GET']})48 mapper.connect('/schemas/images',49 controller=reject_method_resource,50 action='reject',51 allowed_methods='GET',52 conditions={'method': ['POST', 'PUT', 'DELETE',53 'PATCH', 'HEAD']})54 mapper.connect('/schemas/member',55 controller=schemas_resource,56 action='member',57 conditions={'method': ['GET']})58 mapper.connect('/schemas/member',59 controller=reject_method_resource,60 action='reject',61 allowed_methods='GET',62 conditions={'method': ['POST', 'PUT', 'DELETE',63 'PATCH', 'HEAD']})64 mapper.connect('/schemas/members',65 controller=schemas_resource,66 action='members',67 conditions={'method': ['GET']})68 mapper.connect('/schemas/members',69 controller=reject_method_resource,70 action='reject',71 allowed_methods='GET',72 conditions={'method': ['POST', 'PUT', 'DELETE',73 'PATCH', 'HEAD']})74 mapper.connect('/schemas/task',75 controller=schemas_resource,76 action='task',77 conditions={'method': ['GET']})78 mapper.connect('/schemas/task',79 controller=reject_method_resource,80 action='reject',81 allowed_methods='GET',82 conditions={'method': ['POST', 'PUT', 'DELETE',83 'PATCH', 'HEAD']})84 mapper.connect('/schemas/tasks',85 controller=schemas_resource,86 action='tasks',87 conditions={'method': ['GET']})88 mapper.connect('/schemas/tasks',89 controller=reject_method_resource,90 action='reject',91 allowed_methods='GET',92 conditions={'method': ['POST', 'PUT', 'DELETE',93 'PATCH', 'HEAD']})94 mapper.connect('/schemas/metadefs/namespace',95 controller=schemas_resource,96 action='metadef_namespace',97 conditions={'method': ['GET']})98 mapper.connect('/schemas/metadefs/namespace',99 controller=reject_method_resource,100 action='reject',101 allowed_methods='GET',102 conditions={'method': ['POST', 'PUT', 'DELETE',103 'PATCH', 'HEAD']})104 mapper.connect('/schemas/metadefs/namespaces',105 controller=schemas_resource,106 action='metadef_namespaces',107 conditions={'method': ['GET']})108 mapper.connect('/schemas/metadefs/namespaces',109 controller=reject_method_resource,110 action='reject',111 allowed_methods='GET',112 conditions={'method': ['POST', 'PUT', 'DELETE',113 'PATCH', 'HEAD']})114 mapper.connect('/schemas/metadefs/resource_type',115 controller=schemas_resource,116 action='metadef_resource_type',117 conditions={'method': ['GET']})118 mapper.connect('/schemas/metadefs/resource_type',119 controller=reject_method_resource,120 action='reject',121 allowed_methods='GET',122 conditions={'method': ['POST', 'PUT', 'DELETE',123 'PATCH', 'HEAD']})124 mapper.connect('/schemas/metadefs/resource_types',125 controller=schemas_resource,126 action='metadef_resource_types',127 conditions={'method': ['GET']})128 mapper.connect('/schemas/metadefs/resource_types',129 controller=reject_method_resource,130 action='reject',131 allowed_methods='GET',132 conditions={'method': ['POST', 'PUT', 'DELETE',133 'PATCH', 'HEAD']})134 mapper.connect('/schemas/metadefs/property',135 controller=schemas_resource,136 action='metadef_property',137 conditions={'method': ['GET']})138 mapper.connect('/schemas/metadefs/property',139 controller=reject_method_resource,140 action='reject',141 allowed_methods='GET',142 conditions={'method': ['POST', 'PUT', 'DELETE',143 'PATCH', 'HEAD']})144 mapper.connect('/schemas/metadefs/properties',145 controller=schemas_resource,146 action='metadef_properties',147 conditions={'method': ['GET']})148 mapper.connect('/schemas/metadefs/properties',149 controller=reject_method_resource,150 action='reject',151 allowed_methods='GET',152 conditions={'method': ['POST', 'PUT', 'DELETE',153 'PATCH', 'HEAD']})154 mapper.connect('/schemas/metadefs/object',155 controller=schemas_resource,156 action='metadef_object',157 conditions={'method': ['GET']})158 mapper.connect('/schemas/metadefs/object',159 controller=reject_method_resource,160 action='reject',161 allowed_methods='GET',162 conditions={'method': ['POST', 'PUT', 'DELETE',163 'PATCH', 'HEAD']})164 mapper.connect('/schemas/metadefs/objects',165 controller=schemas_resource,166 action='metadef_objects',167 conditions={'method': ['GET']})168 mapper.connect('/schemas/metadefs/objects',169 controller=reject_method_resource,170 action='reject',171 allowed_methods='GET',172 conditions={'method': ['POST', 'PUT', 'DELETE',173 'PATCH', 'HEAD']})174 mapper.connect('/schemas/metadefs/tag',175 controller=schemas_resource,176 action='metadef_tag',177 conditions={'method': ['GET']})178 mapper.connect('/schemas/metadefs/tag',179 controller=reject_method_resource,180 action='reject',181 allowed_methods='GET',182 conditions={'method': ['POST', 'PUT', 'DELETE',183 'PATCH', 'HEAD']})184 mapper.connect('/schemas/metadefs/tags',185 controller=schemas_resource,186 action='metadef_tags',187 conditions={'method': ['GET']})188 mapper.connect('/schemas/metadefs/tags',189 controller=reject_method_resource,190 action='reject',191 allowed_methods='GET',192 conditions={'method': ['POST', 'PUT', 'DELETE',193 'PATCH', 'HEAD']})194 # Metadef resource types195 metadef_resource_types_resource = (196 metadef_resource_types.create_resource())197 mapper.connect('/metadefs/resource_types',198 controller=metadef_resource_types_resource,199 action='index',200 conditions={'method': ['GET']})201 mapper.connect('/metadefs/resource_types',202 controller=reject_method_resource,203 action='reject',204 allowed_methods='GET',205 conditions={'method': ['POST', 'PUT', 'DELETE',206 'PATCH', 'HEAD']})207 mapper.connect('/metadefs/namespaces/{namespace}/resource_types',208 controller=metadef_resource_types_resource,209 action='show',210 conditions={'method': ['GET']})211 mapper.connect('/metadefs/namespaces/{namespace}/resource_types',212 controller=metadef_resource_types_resource,213 action='create',214 conditions={'method': ['POST']})215 mapper.connect('/metadefs/namespaces/{namespace}/resource_types',216 controller=reject_method_resource,217 action='reject',218 allowed_methods='GET, POST',219 conditions={'method': ['PUT', 'DELETE',220 'PATCH', 'HEAD']})221 mapper.connect('/metadefs/namespaces/{namespace}/resource_types/'222 '{resource_type}',223 controller=metadef_resource_types_resource,224 action='delete',225 conditions={'method': ['DELETE']})226 mapper.connect('/metadefs/namespaces/{namespace}/resource_types/'227 '{resource_type}',228 controller=reject_method_resource,229 action='reject',230 allowed_methods='DELETE',231 conditions={'method': ['GET', 'POST', 'PUT',232 'PATCH', 'HEAD']})233 # Metadef Namespaces234 metadef_namespace_resource = metadef_namespaces.create_resource()235 mapper.connect('/metadefs/namespaces',236 controller=metadef_namespace_resource,237 action='index',238 conditions={'method': ['GET']})239 mapper.connect('/metadefs/namespaces',240 controller=metadef_namespace_resource,241 action='create',242 conditions={'method': ['POST']})243 mapper.connect('/metadefs/namespaces',244 controller=reject_method_resource,245 action='reject',246 allowed_methods='GET, POST',247 conditions={'method': ['PUT', 'DELETE',248 'PATCH', 'HEAD']})249 mapper.connect('/metadefs/namespaces/{namespace}',250 controller=metadef_namespace_resource,251 action='show',252 conditions={'method': ['GET']})253 mapper.connect('/metadefs/namespaces/{namespace}',254 controller=metadef_namespace_resource,255 action='update',256 conditions={'method': ['PUT']})257 mapper.connect('/metadefs/namespaces/{namespace}',258 controller=metadef_namespace_resource,259 action='delete',260 conditions={'method': ['DELETE']})261 mapper.connect('/metadefs/namespaces/{namespace}',262 controller=reject_method_resource,263 action='reject',264 allowed_methods='GET, PUT, DELETE',265 conditions={'method': ['POST', 'PATCH', 'HEAD']})266 # Metadef namespace properties267 metadef_properties_resource = metadef_properties.create_resource()268 mapper.connect('/metadefs/namespaces/{namespace}/properties',269 controller=metadef_properties_resource,270 action='index',271 conditions={'method': ['GET']})272 mapper.connect('/metadefs/namespaces/{namespace}/properties',273 controller=metadef_properties_resource,274 action='create',275 conditions={'method': ['POST']})276 mapper.connect('/metadefs/namespaces/{namespace}/properties',277 controller=metadef_namespace_resource,278 action='delete_properties',279 conditions={'method': ['DELETE']})280 mapper.connect('/metadefs/namespaces/{namespace}/properties',281 controller=reject_method_resource,282 action='reject',283 allowed_methods='GET, POST, DELETE',284 conditions={'method': ['PUT', 'PATCH', 'HEAD']})285 mapper.connect('/metadefs/namespaces/{namespace}/properties/{'286 'property_name}',287 controller=metadef_properties_resource,288 action='show',289 conditions={'method': ['GET']})290 mapper.connect('/metadefs/namespaces/{namespace}/properties/{'291 'property_name}',292 controller=metadef_properties_resource,293 action='update',294 conditions={'method': ['PUT']})295 mapper.connect('/metadefs/namespaces/{namespace}/properties/{'296 'property_name}',297 controller=metadef_properties_resource,298 action='delete',299 conditions={'method': ['DELETE']})300 mapper.connect('/metadefs/namespaces/{namespace}/properties/{'301 'property_name}',302 controller=reject_method_resource,303 action='reject',304 allowed_methods='GET, PUT, DELETE',305 conditions={'method': ['POST', 'PATCH', 'HEAD']})306 # Metadef objects307 metadef_objects_resource = metadef_objects.create_resource()308 mapper.connect('/metadefs/namespaces/{namespace}/objects',309 controller=metadef_objects_resource,310 action='index',311 conditions={'method': ['GET']})312 mapper.connect('/metadefs/namespaces/{namespace}/objects',313 controller=metadef_objects_resource,314 action='create',315 conditions={'method': ['POST']})316 mapper.connect('/metadefs/namespaces/{namespace}/objects',317 controller=metadef_namespace_resource,318 action='delete_objects',319 conditions={'method': ['DELETE']})320 mapper.connect('/metadefs/namespaces/{namespace}/objects',321 controller=reject_method_resource,322 action='reject',323 allowed_methods='GET, POST, DELETE',324 conditions={'method': ['PUT', 'PATCH', 'HEAD']})325 mapper.connect('/metadefs/namespaces/{namespace}/objects/{'326 'object_name}',327 controller=metadef_objects_resource,328 action='show',329 conditions={'method': ['GET']})330 mapper.connect('/metadefs/namespaces/{namespace}/objects/{'331 'object_name}',332 controller=metadef_objects_resource,333 action='update',334 conditions={'method': ['PUT']})335 mapper.connect('/metadefs/namespaces/{namespace}/objects/{'336 'object_name}',337 controller=metadef_objects_resource,338 action='delete',339 conditions={'method': ['DELETE']})340 mapper.connect('/metadefs/namespaces/{namespace}/objects/{'341 'object_name}',342 controller=reject_method_resource,343 action='reject',344 allowed_methods='GET, PUT, DELETE',345 conditions={'method': ['POST', 'PATCH', 'HEAD']})346 # Metadef tags347 metadef_tags_resource = metadef_tags.create_resource()348 mapper.connect('/metadefs/namespaces/{namespace}/tags',349 controller=metadef_tags_resource,350 action='index',351 conditions={'method': ['GET']})352 mapper.connect('/metadefs/namespaces/{namespace}/tags',353 controller=metadef_tags_resource,354 action='create_tags',355 conditions={'method': ['POST']})356 mapper.connect('/metadefs/namespaces/{namespace}/tags',357 controller=metadef_namespace_resource,358 action='delete_tags',359 conditions={'method': ['DELETE']})360 mapper.connect('/metadefs/namespaces/{namespace}/tags',361 controller=reject_method_resource,362 action='reject',363 allowed_methods='GET, POST, DELETE',364 conditions={'method': ['PUT', 'PATCH', 'HEAD']})365 mapper.connect('/metadefs/namespaces/{namespace}/tags/{tag_name}',366 controller=metadef_tags_resource,367 action='show',368 conditions={'method': ['GET']})369 mapper.connect('/metadefs/namespaces/{namespace}/tags/{tag_name}',370 controller=metadef_tags_resource,371 action='create',372 conditions={'method': ['POST']})373 mapper.connect('/metadefs/namespaces/{namespace}/tags/{tag_name}',374 controller=metadef_tags_resource,375 action='update',376 conditions={'method': ['PUT']})377 mapper.connect('/metadefs/namespaces/{namespace}/tags/{tag_name}',378 controller=metadef_tags_resource,379 action='delete',380 conditions={'method': ['DELETE']})381 mapper.connect('/metadefs/namespaces/{namespace}/tags/{tag_name}',382 controller=reject_method_resource,383 action='reject',384 allowed_methods='GET, POST, PUT, DELETE',385 conditions={'method': ['PATCH', 'HEAD']})386 images_resource = images.create_resource(custom_image_properties)387 mapper.connect('/images',388 controller=images_resource,389 action='index',390 conditions={'method': ['GET']})391 mapper.connect('/images',392 controller=images_resource,393 action='create',394 conditions={'method': ['POST']})395 mapper.connect('/images',396 controller=reject_method_resource,397 action='reject',398 allowed_methods='GET, POST',399 conditions={'method': ['PUT', 'DELETE', 'PATCH',400 'HEAD']})401 mapper.connect('/images/{image_id}',402 controller=images_resource,403 action='update',404 conditions={'method': ['PATCH']})405 mapper.connect('/images/{image_id}',406 controller=images_resource,407 action='show',408 conditions={'method': ['GET']})409 mapper.connect('/images/{image_id}',410 controller=images_resource,411 action='delete',412 conditions={'method': ['DELETE']})413 mapper.connect('/images/{image_id}',414 controller=reject_method_resource,415 action='reject',416 allowed_methods='GET, PATCH, DELETE',417 conditions={'method': ['POST', 'PUT', 'HEAD']})418 image_actions_resource = image_actions.create_resource()419 mapper.connect('/images/{image_id}/actions/deactivate',420 controller=image_actions_resource,421 action='deactivate',422 conditions={'method': ['POST']})423 mapper.connect('/images/{image_id}/actions/reactivate',424 controller=image_actions_resource,425 action='reactivate',426 conditions={'method': ['POST']})427 mapper.connect('/images/{image_id}/actions/deactivate',428 controller=reject_method_resource,429 action='reject',430 allowed_methods='POST',431 conditions={'method': ['GET', 'PUT', 'DELETE', 'PATCH',432 'HEAD']})433 mapper.connect('/images/{image_id}/actions/reactivate',434 controller=reject_method_resource,435 action='reject',436 allowed_methods='POST',437 conditions={'method': ['GET', 'PUT', 'DELETE', 'PATCH',438 'HEAD']})439 image_data_resource = image_data.create_resource()440 mapper.connect('/images/{image_id}/file',441 controller=image_data_resource,442 action='download',443 conditions={'method': ['GET']})444 mapper.connect('/images/{image_id}/file',445 controller=image_data_resource,446 action='upload',447 conditions={'method': ['PUT']})448 mapper.connect('/images/{image_id}/file',449 controller=reject_method_resource,450 action='reject',451 allowed_methods='GET, PUT',452 conditions={'method': ['POST', 'DELETE', 'PATCH',453 'HEAD']})454 image_tags_resource = image_tags.create_resource()455 mapper.connect('/images/{image_id}/tags/{tag_value}',456 controller=image_tags_resource,457 action='update',458 conditions={'method': ['PUT']})459 mapper.connect('/images/{image_id}/tags/{tag_value}',460 controller=image_tags_resource,461 action='delete',462 conditions={'method': ['DELETE']})463 mapper.connect('/images/{image_id}/tags/{tag_value}',464 controller=reject_method_resource,465 action='reject',466 allowed_methods='PUT, DELETE',467 conditions={'method': ['GET', 'POST', 'PATCH',468 'HEAD']})469 image_members_resource = image_members.create_resource()470 mapper.connect('/images/{image_id}/members',471 controller=image_members_resource,472 action='index',473 conditions={'method': ['GET']})474 mapper.connect('/images/{image_id}/members',475 controller=image_members_resource,476 action='create',477 conditions={'method': ['POST']})478 mapper.connect('/images/{image_id}/members',479 controller=reject_method_resource,480 action='reject',481 allowed_methods='GET, POST',482 conditions={'method': ['PUT', 'DELETE', 'PATCH',483 'HEAD']})484 mapper.connect('/images/{image_id}/members/{member_id}',485 controller=image_members_resource,486 action='show',487 conditions={'method': ['GET']})488 mapper.connect('/images/{image_id}/members/{member_id}',489 controller=image_members_resource,490 action='update',491 conditions={'method': ['PUT']})492 mapper.connect('/images/{image_id}/members/{member_id}',493 controller=image_members_resource,494 action='delete',495 conditions={'method': ['DELETE']})496 mapper.connect('/images/{image_id}/members/{member_id}',497 controller=reject_method_resource,498 action='reject',499 allowed_methods='GET, PUT, DELETE',500 conditions={'method': ['POST', 'PATCH', 'HEAD']})501 tasks_resource = tasks.create_resource()502 mapper.connect('/tasks',503 controller=tasks_resource,504 action='create',505 conditions={'method': ['POST']})506 mapper.connect('/tasks',507 controller=tasks_resource,508 action='index',509 conditions={'method': ['GET']})510 mapper.connect('/tasks',511 controller=reject_method_resource,512 action='reject',513 allowed_methods='GET, POST',514 conditions={'method': ['PUT', 'DELETE', 'PATCH',515 'HEAD']})516 mapper.connect('/tasks/{task_id}',517 controller=tasks_resource,518 action='get',519 conditions={'method': ['GET']})520 mapper.connect('/tasks/{task_id}',521 controller=tasks_resource,522 action='delete',523 conditions={'method': ['DELETE']})524 mapper.connect('/tasks/{task_id}',525 controller=reject_method_resource,526 action='reject',527 allowed_methods='GET, DELETE',528 conditions={'method': ['POST', 'PUT', 'PATCH',529 'HEAD']})...

Full Screen

Full Screen

test_parsers.py

Source:test_parsers.py Github

copy

Full Screen

1# Copyright 2019 James Brown2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14#15# flake8: noqa: E50116import pytest17from torpy.parsers import HSDescriptorParser, IntroPointParser, RouterDescriptorParser18@pytest.fixture19def hs_example():20 return """rendezvous-service-descriptor aj7trvc2tuggkzsffrbla3qogs2plltf21version 222permanent-key23-----BEGIN RSA PUBLIC KEY-----24MIGJAoGBALdj5MFZtlrjI54ousrBzA3fSyfn0NC32OBhl61BLgO67vPBiIiFFzo925YIqa4h3jZQrxdI3MeK4xTLQ6HhnQXvcM+ZR57o5zTR7fpqra89i75rwUjW5wqc9O263roxzt1UWbJBtbzOT9FYxGSIczsYdG6MQRg9BK/2v391Oz9NbDb1AgMBAAE=27-----END RSA PUBLIC KEY-----28secret-id-part jrhhuswdnmpplrlflxc4buquuzijljkr29publication-time 2019-03-20 06:00:0030protocol-versions 2,331introduction-points32-----BEGIN MESSAGE-----33aW50cm9kdWN0aW9uLXBvaW50IGt4eGlxenU2YnI0cGg1ZmgybzN1eHh3ZnNjaGpy34a282CmlwLWFkZHJlc3MgMjE3LjIzLjcuMTAzCm9uaW9uLXBvcnQgOTAwMQpvbmlv35bi1rZXkKLS0tLS1CRUdJTiBSU0EgUFVCTElDIEtFWS0tLS0tCk1JR0pBb0dCQU9E36dG9TajZreUh6WHN4enhwVDgvOGFpV2hCcmVMdGFMbjZybGJhRjUwRnVQWkY5azVG37ZGhnMDAKNjFWbHc1djUzVHlWTFJST042Mkt5TlJZT1o5NWd1V2FEajBDVDBMbCtE38Qzh5OU5ORk83Zk02SG1hR1pkYTlnYwpxYkRtK2JET1JTSHVmd2FzWTNSVHlEVW5H39TWFpSXpxeDJna0l4dEI1TituTkk4eERDVFlEQWdNQkFBRT0KLS0tLS1FTkQgUlNB40IFBVQkxJQyBLRVktLS0tLQpzZXJ2aWNlLWtleQotLS0tLUJFR0lOIFJTQSBQVUJM41SUMgS0VZLS0tLS0KTUlHSkFvR0JBTGNHRGZzcVBObzNKcFpIMjVMcnd4bDNGeWZt42VExKUGdtRUh5KzcvcUJ0eVlBTEp1cC9McGRxcQpRcjkraTBpcFdLcWs3cG5TUi9w43aFo4S3pnR1lnVGJWUDZyV2NGQXZvWEhQWXVmc1d6OVp2SGY3N0drYVZZSTJSCkVq44TEtaL1FMRG9rYVFKOFpHeWNpUnJ3ZHlRdHMyTUxZc00rRUQ3bmhHZzdtR2N2eWZC45SWZBZ01CQUFFPQotLS0tLUVORCBSU0EgUFVCTElDIEtFWS0tLS0tCmludHJvZHVj46dGlvbi1wb2ludCB5bjN4NG9scTdsYm1ic3ptanlsZ29ybmhvemliZ2V5ZQppcC1h47ZGRyZXNzIDk0LjIzLjE1MC44MQpvbmlvbi1wb3J0IDQ0Mwpvbmlvbi1rZXkKLS0t48LS1CRUdJTiBSU0EgUFVCTElDIEtFWS0tLS0tCk1JR0pBb0dCQU94ajNzT2syb3g349dzU5aXdhejl6WHc2UktvdjJXYUh6TWVvbjBiWlVVQXVHcWlKT01ONEt3RkQKMlNS50LzBrSUY1UjIyV3I4a2x0cXQxbWlTY0tvWk9KU2MrYXVVVjR6TXl2NmE5bnl2cXJt51amhDYWJqSlFoQ0M4VQpoT3ZrL2N3K1MvZHZnQXFGTkdnTzNHV0RrSnI3bC9BTXh552alhVa1FKYnVjb1JiWGkwbU56QWdNQkFBRT0KLS0tLS1FTkQgUlNBIFBVQkxJQyBL53RVktLS0tLQpzZXJ2aWNlLWtleQotLS0tLUJFR0lOIFJTQSBQVUJMSUMgS0VZLS0t54LS0KTUlHSkFvR0JBTVJDYWJHdWI3Mk1xSndqMHJXRnArZW5xSzRzMVBEeGZUVDUx55Zmcwdkd0bStxM1E0azFtUm1tVApiNkc3OTNNOVV6WnN4dVNKbDRSOVJyZEJaM1pt56OGRmMDU2cEUvSmJ0Q2NWVnlPb0daZlVsWHhXaDM0c2RZdU4xCkZGb1Iva0JlLzBF57aWtBSWI5eGsyS001SjlKMGEyc1A0UTNhL2NGOWJkNjhpMWlaSmIySWhBZ01CQUFF58PQotLS0tLUVORCBSU0EgUFVCTElDIEtFWS0tLS0tCmludHJvZHVjdGlvbi1wb2lu59dCBoemo1aGY0NXdiN3AyNDNnbWhldGppbzYyZmFzcG51ZQppcC1hZGRyZXNzIDIx60Ny43OS4xNzkuMTc3Cm9uaW9uLXBvcnQgOTAwMQpvbmlvbi1rZXkKLS0tLS1CRUdJ61TiBSU0EgUFVCTElDIEtFWS0tLS0tCk1JR0pBb0dCQU5xY2R0YTQvOUFFYzkyMjJx62YUVnVTNSQ1E0ZEVGTnlDSDNDbTVTNGFDa2dxbHp0VmJPSlBlVmQKVjJaTjk4dW8x63OGlXa3JySENiZUdTWTVqdkkvdTFlUzFydTNNTkM1NTBhNDE3RHdFUGlaUWJxMitO64N1dGYisxbwpOa2x2TkllZTZGMDllb2FYMExuVGJjR1RheGJLaHF0cWh4cGJvYTVJ65RUV0L05CajRmNE05QWdNQkFBRT0KLS0tLS1FTkQgUlNBIFBVQkxJQyBLRVktLS0t66LQpzZXJ2aWNlLWtleQotLS0tLUJFR0lOIFJTQSBQVUJMSUMgS0VZLS0tLS0KTUlH67SkFvR0JBTzZzbjNzekJXVGxjQVAvV1lIQ2ZzVmVnSDBPNmNlcHlWRVllOW82YzQ468cGh6VDBoZzFnWmJMdApOS3lqM2xWR1RaYVFxY3Jvak16bzhlbkEwR2VyeGsrWVpF69THV3eDRCYmIraUk5d1gvbmJib3ptejhLZjhNdnVGCmNkakFDalEwV3liVXBtcWdk70TXBpVHc4SFNSbWh0SWlsQXE1L1VnYzNTaVRQbHlqWVYxN1BBZ01CQUFFPQotLS0t71LUVORCBSU0EgUFVCTElDIEtFWS0tLS0tCgo=72-----END MESSAGE-----73signature74-----BEGIN SIGNATURE-----75XkVVwRd1reFUb0KqdtYUWcLUCQduq7GnGJ8IpNYbsI4x8LadiRi9gxABv8E4OjYQ765CiP6qso+SMieOP7PEQK67+VMnrUaPUsldDjYdSkWCTNSPgbaXOasSFxJ0pZeQXx77NwjHDSI4mD57pkSzvPgd+t/hrA3AFAWZu49eUw4BYwc=78-----END SIGNATURE-----79"""80hs_example2 = """HTTP/1.0 200 OK81Date: Wed, 20 Mar 2019 21:17:16 GMT82Content-Type: text/plain83X-Your-Address-Is: 104.192.88.9784Content-Encoding: identity85Content-Length: 325386Pragma: no-cache87rendezvous-service-descriptor expocwozpjpjce7kfcdyu3et25aswqdf88version 289permanent-key90-----BEGIN RSA PUBLIC KEY-----91MIGJAoGBALdj5MFZtlrjI54ousrBzA3fSyfn0NC32OBhl61BLgO67vPBiIiFFzo992YIqa4h3jZQrxdI3MeK4xTLQ6HhnQXvcM+ZR57o5zTR7fpqra89i75rwUjW5wqc9O933roxzt1UWbJBtbzOT9FYxGSIczsYdG6MQRg9BK/2v391Oz9NbDb1AgMBAAE=94-----END RSA PUBLIC KEY-----95secret-id-part 2o5f46v3wjaoysjde3z2tjkax5unwp4z96publication-time 2019-03-20 21:00:0097protocol-versions 2,398introduction-points99-----BEGIN MESSAGE-----100aW50cm9kdWN0aW9uLXBvaW50IHlzbmJvNWlxemt0Zmh3dGhlNjdxNGI3M3A1bGti101NGU1CmlwLWFkZHJlc3MgMTM2LjI0My43MC4xOTgKb25pb24tcG9ydCA5MDAxCm9u102aW9uLWtleQotLS0tLUJFR0lOIFJTQSBQVUJMSUMgS0VZLS0tLS0KTUlHSkFvR0JB103T01uajFoQUR4dDcrT0xqVnJxRnFWdGFaQ1kranNqdlk1OTNDMktYdnVJT3dTcXVB104SUZHamVLQgpnM2dEVjZRckZyN0ZKSGZjOTZiTkVRa2I2RmhUQkFydVB2OTJYQ3Aw105TVdsTzBhS2ZWNTZLckgrZXg0ZWRRUmxXClUzY2l3c3IrMStVclcwOS9ob0twb29K106WGhaSUZJRjg3d1RvYlFxbVM4LzFnMzBQR2tHWGhBZ01CQUFFPQotLS0tLUVORCBS107U0EgUFVCTElDIEtFWS0tLS0tCnNlcnZpY2Uta2V5Ci0tLS0tQkVHSU4gUlNBIFBV108QkxJQyBLRVktLS0tLQpNSUdKQW9HQkFOUERQZkFSTS9BbXRQYUJCZDMyY3FvWVZN109Vit4WkY5djI0aVY0cTZxODRTaEM0Z3YzMFI4cjZHCldJbjErZUJSYWUyZXkzVlVn110S21BYmU2TzJ0SUNmN3Q2QzY0REFBZFVVcVljc1Vka2pmQy8yQ1IwaXpjaExuK1gK111NWdHSU0rbmpseGppRVFEZHZWaDljWjlzV0RtUzdhYmkvbXNkMmRjZFhXV3QwSkRy112WlJ4dEFnTUJBQUU9Ci0tLS0tRU5EIFJTQSBQVUJMSUMgS0VZLS0tLS0KaW50cm9k113dWN0aW9uLXBvaW50IGZrNjR5d3JnazNnNmR4M2FjY2psempxbW9yZTdwd2t3Cmlw114LWFkZHJlc3MgNzguMTI5LjIwOC4xODQKb25pb24tcG9ydCA0NDMKb25pb24ta2V5115Ci0tLS0tQkVHSU4gUlNBIFBVQkxJQyBLRVktLS0tLQpNSUdKQW9HQkFKZCtyeVFu116RHl3eGRUeTZKNXlQbGJmVmFFWWxNenF0WEZhZTVtSkJGdDdCRHhXQjRDZ1lFOG9I117Ckd4ZTg4UXpjTFUvd0FEZmVSaDVMaVpweWdhY0J6M1VRY04yYklGWm9Bc3hmMU5W118R3NLR2xrV3RSTWl0ZmMyWjkKcW8yMVpHdUNMUTZDb3RTeG5sUXVJNWxaR1ZkQ3kx119WGt0d2lzK2VGL2RiRWNra3dwS3FoRkFnTUJBQUU9Ci0tLS0tRU5EIFJTQSBQVUJM120SUMgS0VZLS0tLS0Kc2121"""122def test_hs_parser(hs_example):123 res = HSDescriptorParser.parse(hs_example)124 print(res)125@pytest.fixture126def ip_example():127 return """introduction-point ysnbo5iqzktfhwthe67q4b73p5lkb4e5128ip-address 136.243.70.198129onion-port 9001130onion-key131-----BEGIN RSA PUBLIC KEY-----132MIGJAoGBAOMnj1hADxt7+OLjVrqFqVtaZCY+jsjvY593C2KXvuIOwSquAIFGjeKB133g3gDV6QrFr7FJHfc96bNEQkb6FhTBAruPv92XCp0MWlO0aKfV56KrH+ex4edQRlW134U3ciwsr+1+UrW09/hoKpooJXhZIFIF87wTobQqmS8/1g30PGkGXhAgMBAAE=135-----END RSA PUBLIC KEY-----136service-key137-----BEGIN RSA PUBLIC KEY-----138MIGJAoGBANPDPfARM/AmtPaBBd32cqoYVMV+xZF9v24iV4q6q84ShC4gv30R8r6G139WIn1+eBRae2ey3VUgKmAbe6O2tICf7t6C64DAAdUUqYcsUdkjfC/2CR0izchLn+X1405gGIM+njlxjiEQDdvVh9cZ9sWDmS7abi/msd2dcdXWWt0JDrZRxtAgMBAAE=141-----END RSA PUBLIC KEY-----142introduction-point fk64ywrgk3g6dx3accjlzjqmore7pwkw143ip-address 78.129.208.184144onion-port 443145onion-key146-----BEGIN RSA PUBLIC KEY-----147MIGJAoGBAJd+ryQnDywxdTy6J5yPlbfVaEYlMzqtXFae5mJBFt7BDxWB4CgYE8oH148Gxe88QzcLU/wADfeRh5LiZpygacBz3UQcN2bIFZoAsxf1NVGsKGlkWtRMitfc2Z9149qo21ZGuCLQ6CotSxnlQuI5lZGVdCy1Xktwis+eF/dbEckkwpKqhFAgMBAAE=150-----END RSA PUBLIC KEY-----151service-key152-----BEGIN RSA PUBLIC KEY-----153MIGJAoGBANw4LrTMxv1lXQp2XgKXUklE/KgdHB3bSQ+f8FzIIEat+ndVvTuq4ILp154PngUxqTS8ulc0ZMJ+kLezLBzYupVZy+c4Lhc9SCROTtz93yoO45NPtcszKaNO1+K155kf95gp5BHvuC51OD4UGJOgaQzusRjrbfDc2KB2D5g+scok86qgShAgMBAAE=156-----END RSA PUBLIC KEY-----157introduction-point 3ugi53c4uqbkt6sepdyqymneid3r62ef158ip-address 195.201.9.37159onion-port 143160onion-key161-----BEGIN RSA PUBLIC KEY-----162MIGJAoGBAJwz6KYUdMpK4/g5LurMLE53kWNU5oUzdXZTHc7/zNcdYKejAYwADVqM163d+jJjlNfi5XEUAZmTVFP2VwAGBza86hlfApg01kvLA9ptDOsgtrGhc8kYT6nQYX+164gVvSRyXDMNOMlZRA9ALA8wmhmFM/3T5BvjpsV90xum56qnWp0lvnAgMBAAE=165-----END RSA PUBLIC KEY-----166service-key167-----BEGIN RSA PUBLIC KEY-----168MIGJAoGBAN44XsgtoiYfSGUSmiudOPJQo96Mhd/dcuzQbYzhK1X6F7FvmMcJWhLK169LO/0dedGvqikKwEuNjhkGawwqYudL3sZ6AUyxY9wgfzznfWYbLFMx9KpZzh76n6c170sObvfg6Gt0HmZIh+nJdhF1n8u/xYZZ4TyL8jGg+eyG/aJ1jIfnoPAgMBAAE=171-----END RSA PUBLIC KEY-----172"""173def test_ip_parser(ip_example):174 res = IntroPointParser.parse(ip_example)175 print(res)176@pytest.fixture177def rd_example():178 return """router Nyx 51.15.252.1 9001 0 9030179identity-ed25519180-----BEGIN ED25519 CERT-----181AQQABph4ATKUIStvlLeIF/2rGBv6k+/8sK05mjCtRjeXH5lJBfECAQAgBACuN8aH182zaPSQqkRZi9nU79oNKT/e1pSsBw8u0YeHF6SfVUDl/yIU9i53fU9eF5bKB41b7Pn183r7xCUwOJnEXwQLoZ5wr5oFQKMNzsgEzUwj20K0NGQ3djZCEtt8vjiqflTQw=184-----END ED25519 CERT-----185master-key-ed25519 rjfGh82j0kKpEWYvZ1O/aDSk/3taUrAcPLtGHhxekn0186platform Tor 0.3.5.8 on Linux187proto Cons=1-2 Desc=1-2 DirCache=1-2 HSDir=1-2 HSIntro=3-4 HSRend=1-2 Link=1-5 LinkAuth=1,3 Microdesc=1-2 Relay=1-2188published 2019-03-31 11:43:32189fingerprint 8532 DE42 43E4 949E 4EA8 6E88 CDCA 6821 582F 1A13190uptime 2840486191bandwidth 1073741824 1073741824 24702282192extra-info-digest FFDAB70266F42AE8938EC1C0E6DC1A275DD903FE bCEVMfYHbSxL6Th0iJj0Wo8HZrzLnyqDvlheyO1JzNE193onion-key194-----BEGIN RSA PUBLIC KEY-----195MIGJAoGBALlYKkE6C0RMPe6YbUtlP5Ucu90Kj8GnsYD0Hwbh7tqL/QkXFSPRnoA81968fGdp/jlNhQt/Asfbsqq9H+7FLQ6r8rZG1/ndMO8g+khobBvddFxr0JBn5BvZO8h197MJAbg8K/DVSnfxIaJrhxN/VWUjEmH9vwpmyuNYIXZKRHfqszn1G1AgMBAAE=198-----END RSA PUBLIC KEY-----199signing-key200-----BEGIN RSA PUBLIC KEY-----201MIGJAoGBAMRcnxPGmSTWelnSD6FVET7L88E2xf3vd17cB2JDTWdw0gIGM7aL4WVL202P8xuVqshwmlqXGiExtruqZUVWD8M1pAQwNoILCpqJJ5U1LZyqmRoNlkRjcCKuaJw203RiSsmJCvkCZzcJ3PBiJbhMxqKyweGWSqsB2bRNpSb8aZLIIOZnzXAgMBAAE=204-----END RSA PUBLIC KEY-----205onion-key-crosscert206-----BEGIN CROSSCERT-----207HiWs9Bo11xyyJs+i/8AdpNDoQkdNVoTuvMFNnDamYceEUTWaoxDazk3OIFkiIHqe208wPI0AKF5+vTUWHfRBB4AuBYgoLMxAAPNtbSgKnI9c+5pKwsWeHJs89F0jTIulNYs209Es1T9HQq+HGWRH8M0Dbv6o/W5MKLppvqRIhbXXRrR+I=210-----END CROSSCERT-----211ntor-onion-key-crosscert 1212-----BEGIN ED25519 CERT-----213AQoABpjcAa43xofNo9JCqRFmL2dTv2g0pP97WlKwHDy7Rh4cXpJ9APezxMtt8tMB214tpDMZnC+Hq9pK62Yu6Na3H+T0+fdme8CmhXa9pQ8NgCpeW7Es9oNXaCev8BcMol/2156AFJ3vFidAI=216-----END ED25519 CERT-----217family $13E8EB1D9FD7470AA87A47DC93538E88340A0903 $157106182B9F33663CAEDCD883D302316331DE5E $2C5FDD910AE3E21C0B6F9DD4BF397F570C8358FA $3844DFD3446832A3C8A137EEA616D4EEB370C788 $42E0FB190D20522C6C8C71E42B71DA33AC7A780E $4DDBC57BA2A63F0439FD41D92BFF8E141CC61213 $54FA84FF74B0C2BAC45CEADB4BF9C9CAEF72020F $67469C0671BF8D4BECB11F006AD541E9BC54EBCB $69D22FAEE5D4E18A098D5DEF68EAEE8D24F53CCA $70A81E423F94A9BF58D2FF432BBF59FA73426DB6 $8154154C636EC317C7165FD839F34F79963376C1 $88C3708A9D71ECEC1910B63C3FAA5BF60CD7E199 $8C34A154997812D1396BC462A42DA0A59B55952D $AEA760EE120B630262C70C1C11D4158BBF12C602 $B5EDD091D81655C2EBADB38065A868AA20259AC3 $B756D7123D759EAB62CB6A09148AD65AC216F3E3 $C79517FFC1327B0D4E86218A34C8E2570F338CF9 $C8850DE0EBC07481808F32F2BAA76CA65CB659FB $CE946DFEC40A1BFC3665A4727F54354F57297497218hidden-service-dir219contact abuse [AT] torworld.org - BTC 34yFiqwbcUA5MYSvUcpjqARvhoTwMFjmPs220ntor-onion-key owtGGV469gdDNIWfnIlIHgR7CvM0Ak5VwLiZCtBgtzc=221reject 0.0.0.0/8:*222reject 169.254.0.0/16:*223reject 127.0.0.0/8:*224reject 192.168.0.0/16:*225reject 10.0.0.0/8:*226reject 172.16.0.0/12:*227reject 51.15.252.1:*228reject 5.157.0.0/18:*229reject 5.188.216.0/24:*230reject 31.11.43.0/24:*231reject 37.139.49.0/24:*232reject 37.9.42.0/24:*233reject 37.9.53.0/24:*234reject 46.148.112.0/24:*235reject 46.148.120.0/24:*236reject 46.148.127.0/24:*237reject 46.161.56.0/24:*238reject 46.161.57.0/24:*239reject 46.161.58.0/24:*240reject 46.161.59.0/24:*241reject 46.161.60.0/24:*242reject 46.161.61.0/24:*243reject 46.161.62.0/24:*244reject 46.161.63.0/24:*245reject 46.243.140.0/24:*246reject 46.243.142.0/24:*247reject 46.243.173.0/24:*248reject 46.29.248.0/21:*249reject 46.8.255.0/24:*250reject 47.104.0.0/13:*251reject 49.12.0.0/16:*252reject 49.13.0.0/16:*253reject 79.110.22.0/24:*254reject 79.133.107.0/24:*255reject 81.94.43.0/24:*256reject 83.217.11.0/24:*257reject 84.19.170.240/28:*258reject 85.121.39.0/24:*259reject 85.93.5.0/24:*260reject 91.200.12.0/22:*261reject 91.200.164.0/24:*262reject 91.200.81.0/24:*263reject 91.200.82.0/24:*264reject 91.200.83.0/24:*265reject 91.207.4.0/22:*266reject 91.209.12.0/24:*267reject 91.212.124.0/24:*268reject 91.213.126.0/24:*269reject 91.216.3.0/24:*270reject 91.217.10.0/23:*271reject 91.220.101.0/24:*272reject 91.220.163.0/24:*273reject 91.220.62.0/24:*274reject 91.224.160.0/23:*275reject 91.225.216.0/22:*276reject 91.226.92.0/22:*277reject 91.230.252.0/23:*278reject 91.235.2.0/24:*279reject 91.236.74.0/23:*280reject 91.238.82.0/24:*281reject 91.243.90.0/24:*282reject 91.243.91.0/24:*283reject 91.243.93.0/24:*284reject 93.179.88.0/24:*285reject 95.181.176.0/24:*286reject 95.181.177.0/24:*287reject 95.181.182.0/24:*288reject 95.181.183.0/24:*289reject 95.181.216.0/24:*290reject 95.181.217.0/24:*291reject 95.181.219.0/24:*292reject 95.182.79.0/24:*293reject 95.85.80.0/24:*294reject 95.85.81.0/24:*295reject 103.215.80.0/22:*296reject 103.63.0.0/22:*297reject 113.212.64.0/19:*298reject 141.101.132.0/24:*299reject 141.101.201.0/24:*300reject 141.136.27.0/24:*301reject 146.185.200.0/24:*302reject 146.185.201.0/24:*303reject 146.185.202.0/24:*304reject 146.185.203.0/24:*305reject 146.185.204.0/24:*306reject 146.185.205.0/24:*307reject 146.185.206.0/24:*308reject 150.129.40.0/22:*309reject 151.237.176.0/20:*310reject 159.174.0.0/16:*311reject 172.80.0.0/17:*312reject 176.53.112.0/20:*313reject 176.97.116.0/22:*314reject 178.159.97.0/24:*315reject 178.16.80.0/20:*316reject 178.57.65.0/24:*317reject 178.57.66.0/24:*318reject 178.57.67.0/24:*319reject 178.57.68.0/24:*320reject 179.61.200.0/23:*321reject 181.214.37.0/24:*322reject 181.215.39.0/24:*323reject 185.101.68.0/24:*324reject 185.101.71.0/24:*325reject 185.103.252.0/23:*326reject 185.106.104.0/23:*327reject 185.106.92.0/24:*328reject 185.106.94.0/24:*329reject 185.112.102.0/24:*330reject 185.115.140.0/24:*331reject 185.127.24.0/22:*332reject 185.129.148.0/23:*333reject 185.137.219.0/24:*334reject 185.14.192.0/24:*335reject 185.14.193.0/24:*336reject 185.14.195.0/24:*337reject 185.146.168.0/22:*338reject 185.154.20.0/22:*339reject 185.159.36.0/22:*340reject 185.169.228.0/22:*341reject 185.2.32.0/24:*342reject 185.71.0.0/22:*343reject 188.247.135.0/24:*344reject 188.247.230.0/24:*345reject 188.247.232.0/24:*346reject 188.68.0.0/24:*347reject 188.68.1.0/24:*348reject 188.68.3.0/24:*349reject 188.72.126.0/24:*350reject 188.72.127.0/24:*351reject 188.72.96.0/24:*352reject 191.101.24.0/24:*353reject 191.101.54.0/23:*354reject 191.96.170.0/24:*355reject 191.96.174.0/24:*356reject 193.105.171.0/24:*357reject 193.138.244.0/22:*358reject 193.93.192.0/24:*359reject 193.93.195.0/24:*360reject 194.29.185.0/24:*361reject 195.182.57.0/24:*362reject 195.190.13.0/24:*363reject 195.191.56.0/23:*364reject 195.225.176.0/22:*365reject 204.225.16.0/20:*366reject 212.92.127.0/24:*367reject 46.8.44.0/23:*368reject 46.98.64.0/18:*369reject 68.119.232.0/21:*370reject 68.215.0.0/16:*371reject 69.244.0.0/14:*372reject 70.111.0.0/16:*373reject 70.126.0.0/15:*374reject 112.78.2.0/24:*375reject 193.9.28.0/24:*376reject 195.20.40.0/21:*377reject 5.8.37.0/24:*378reject 5.101.218.0/24:*379reject 5.101.221.0/24:*380reject 79.110.17.0/24:*381reject 79.110.18.0/24:*382reject 79.110.19.0/24:*383reject 79.110.25.0/24:*384reject 93.179.89.0/24:*385reject 93.179.90.0/24:*386reject 93.179.91.0/24:*387reject 185.46.84.0/22:*388reject 185.50.250.0/24:*389reject 185.50.251.0/24:*390reject 193.9.158.0/24:*391reject 5.196.26.96:*392reject 23.235.209.11:*393reject 23.92.87.202:*394reject 27.254.151.81:*395reject 27.254.152.29:*396reject 27.254.40.113:*397reject 27.254.41.206:*398reject 27.254.44.105:*399reject 27.254.61.110:*400reject 27.254.85.27:*401reject 27.254.85.49:*402reject 36.39.155.98:*403reject 36.66.209.21:*404reject 36.72.228.22:*405reject 36.76.176.64:*406reject 37.203.213.110:*407reject 46.26.129.203:*408reject 46.34.160.34:*409reject 50.118.100.49:*410reject 54.37.96.109:*411reject 58.195.1.4:*412reject 59.157.4.2:*413reject 60.13.186.5:*414reject 60.241.184.209:*415reject 62.75.132.67:*416reject 63.249.152.74:*417reject 64.127.71.73:*418reject 64.182.6.61:*419reject 64.85.233.8:*420reject 66.117.5.245:*421reject 66.70.134.137:*422reject 66.70.190.236:*423reject 68.65.122.86:*424reject 74.124.194.43:*425reject 77.104.143.180:*426reject 77.227.184.45:*427reject 77.228.191.183:*428reject 78.108.82.18:*429reject 78.108.83.153:*430reject 78.108.87.155:*431reject 78.108.89.85:*432reject 78.108.93.91:*433reject 78.108.95.116:*434reject 78.108.95.207:*435reject 78.138.104.167:*436reject 78.138.88.232:*437reject 79.170.44.115:*438reject 79.187.34.150:*439reject 79.188.45.226:*440reject 80.48.160.146:*441reject 80.52.222.10:*442reject 80.65.93.241:*443reject 83.0.245.234:*444reject 83.1.195.232:*445reject 83.17.220.66:*446reject 83.212.110.172:*447reject 83.212.112.80:*448reject 83.212.117.233:*449reject 83.212.120.81:*450reject 83.220.128.111:*451reject 83.220.144.107:*452reject 83.220.144.30:*453reject 84.19.190.8:*454reject 84.19.191.164:*455reject 85.117.35.21:*456reject 85.25.185.254:*457reject 86.104.134.144:*458reject 87.118.102.19:*459reject 87.118.90.136:*460reject 87.119.194.135:*461reject 87.236.210.110:*462reject 87.236.210.124:*463reject 87.237.198.245:*464reject 87.246.143.242:*465reject 87.254.167.37:*466reject 89.232.63.147:*467reject 91.108.176.118:*468reject 91.121.78.51:*469reject 91.201.202.12:*470reject 91.208.144.164:*471reject 92.36.213.75:*472reject 93.153.195.181:*473reject 93.170.128.136:*474reject 93.170.130.147:*475reject 93.170.131.108:*476reject 93.171.202.191:*477reject 93.65.43.220:*478reject 94.103.36.55:*479reject 95.169.184.25:*480reject 95.169.184.7:*481reject 95.169.190.104:*482reject 95.62.197.90:*483reject 96.31.35.51:*484reject 103.19.89.118:*485reject 103.230.84.239:*486reject 103.26.41.71:*487reject 103.4.52.150:*488reject 103.53.172.20:*489reject 103.53.172.96:*490reject 103.59.164.125:*491reject 103.7.56.119:*492reject 103.7.59.135:*493reject 103.221.222.65:*494reject 104.244.120.12:*495reject 104.247.76.199:*496reject 109.127.8.242:*497reject 109.127.8.246:*498reject 109.199.98.63:*499reject 109.229.210.250:*500reject 109.229.36.65:*501reject 109.237.111.168:*502reject 109.248.200.23:*503reject 110.138.108.142:*504reject 110.164.126.64:*505reject 110.164.205.225:*506reject 111.67.15.173:*507reject 111.67.16.254:*508reject 113.29.230.24:*509reject 115.146.59.207:*510reject 120.63.157.195:*511reject 120.63.175.225:*512reject 124.110.195.160:*513reject 128.210.157.251:*514reject 130.206.78.158:*515reject 137.74.6.95:*516reject 138.100.137.61:*517reject 143.225.116.108:*518reject 147.156.165.26:*519reject 148.163.100.151:*520reject 150.244.121.149:*521reject 151.97.190.239:*522reject 151.97.80.16:*523reject 154.66.197.59:*524reject 158.110.80.108:*525reject 158.69.255.67:*526reject 161.67.132.25:*527reject 162.223.94.56:*528reject 162.255.119.249:*529reject 172.81.119.140:*530reject 177.4.23.159:*531reject 177.70.107.137:*532reject 177.70.122.13:*533reject 177.70.122.193:*534reject 177.70.123.117:*535reject 177.70.123.128:*536reject 177.70.123.8:*537reject 177.70.123.90:*538reject 177.70.98.122:*539reject 177.70.98.242:*540reject 178.210.173.46:*541reject 178.250.241.22:*542reject 178.250.243.146:*543reject 178.250.245.138:*544reject 178.250.246.89:*545reject 178.32.255.132:*546reject 178.32.52.15:*547reject 180.182.234.200:*548reject 180.241.47.130:*549reject 180.250.210.23:*550reject 180.250.28.38:*551reject 181.136.26.124:*552reject 185.15.185.201:*553reject 185.15.185.209:*554reject 185.19.92.70:*555reject 185.59.28.14:*556reject 185.61.152.30:*557reject 185.242.179.15:*558reject 185.242.179.16:*559reject 186.202.153.34:*560reject 186.64.122.105:*561reject 187.141.112.98:*562reject 187.141.12.161:*563reject 187.174.252.247:*564reject 188.218.158.126:*565reject 188.219.154.228:*566reject 188.240.2.93:*567reject 188.241.140.212:*568reject 188.241.140.222:*569reject 188.241.140.224:*570reject 188.84.140.44:*571reject 188.85.248.131:*572reject 190.128.122.234:*573reject 190.128.29.1:*574reject 190.15.192.25:*575reject 190.183.59.133:*576reject 190.7.28.147:*577reject 191.252.104.136:*578reject 191.252.128.181:*579reject 191.252.130.32:*580reject 191.252.132.201:*581reject 191.252.134.38:*582reject 191.252.135.80:*583reject 191.252.136.74:*584reject 191.252.140.148:*585reject 191.252.140.199:*586reject 191.252.140.212:*587reject 191.252.141.145:*588reject 191.252.142.98:*589reject 191.252.143.96:*590reject 191.252.2.161:*591reject 192.100.170.12:*592reject 192.64.11.244:*593reject 192.64.9.116:*594reject 192.99.37.46:*595reject 193.146.210.69:*596reject 193.218.145.184:*597reject 193.218.145.32:*598reject 193.218.145.50:*599reject 194.144.188.70:*600reject 195.117.119.187:*601reject 195.205.24.101:*602reject 198.50.173.86:*603reject 198.54.126.39:*604reject 199.187.129.193:*605reject 199.201.121.169:*606reject 199.201.121.185:*607reject 199.246.2.104:*608reject 199.7.234.100:*609reject 200.0.24.42:*610reject 200.116.206.58:*611reject 201.149.83.183:*612reject 201.232.32.124:*613reject 202.115.63.125:*614reject 202.144.144.195:*615reject 202.150.213.85:*616reject 202.150.213.93:*617reject 202.28.32.110:*618reject 202.28.32.20:*619reject 202.29.22.38:*620reject 202.29.230.198:*621reject 202.67.13.107:*622reject 203.170.192.150:*623reject 203.170.192.240:*624reject 203.170.193.23:*625reject 203.24.188.166:*626reject 208.83.210.109:*627reject 208.93.233.58:*628reject 209.99.40.225:*629reject 209.164.84.70:*630reject 209.182.193.155:*631reject 209.182.199.168:*632reject 209.182.208.165:*633reject 209.182.213.90:*634reject 209.191.185.67:*635reject 210.37.11.238:*636reject 210.4.76.221:*637reject 210.46.85.150:*638reject 210.83.80.26:*639reject 212.252.45.46:*640reject 212.44.64.202:*641reject 212.72.132.138:*642reject 213.147.67.20:*643reject 213.185.88.41:*644reject 213.185.88.60:*645reject 213.205.38.29:*646reject 213.25.134.75:*647reject 216.176.100.240:*648reject 216.215.112.149:*649reject 216.59.16.171:*650reject 222.124.202.178:*651reject 222.124.206.41:*652reject 222.29.197.232:*653reject 46.173.218.123:*654reject 91.219.29.41:*655reject 195.208.1.101:*656reject 5.79.71.205:*657reject 5.79.71.225:*658reject 46.244.21.4:*659reject 50.21.181.152:*660reject 50.63.202.35:*661reject 52.5.245.208:*662reject 64.71.166.50:*663reject 67.215.255.139:*664reject 74.200.48.169:*665reject 74.208.153.9:*666reject 74.208.164.166:*667reject 74.208.64.191:*668reject 85.17.31.122:*669reject 85.17.31.82:*670reject 87.106.149.145:*671reject 87.106.149.153:*672reject 87.106.18.112:*673reject 87.106.18.141:*674reject 87.106.190.153:*675reject 87.106.20.192:*676reject 87.106.24.200:*677reject 87.106.253.18:*678reject 87.106.26.9:*679reject 95.211.230.75:*680reject 104.244.14.252:*681reject 109.70.26.37:*682reject 144.217.74.156:*683reject 146.148.124.166:*684reject 148.81.111.111:*685reject 151.80.148.103:*686reject 176.58.104.168:*687reject 178.162.203.202:*688reject 178.162.203.211:*689reject 178.162.203.226:*690reject 178.162.217.107:*691reject 184.105.192.2:*692reject 192.0.72.20:*693reject 192.0.72.21:*694reject 192.169.69.25:*695reject 192.42.116.41:*696reject 192.42.119.41:*697reject 193.166.255.170:*698reject 193.166.255.171:*699reject 204.11.56.48:*700reject 208.91.197.46:*701reject 212.227.20.93:*702reject 213.165.83.176:*703reject 216.218.135.114:*704reject 216.218.185.162:*705reject 216.218.208.114:*706reject 216.66.15.109:*707reject 72.55.186.0/24:*708reject 174.142.230.0/24:*709reject 184.107.100.0/24:*710reject 184.107.101.0/24:*711reject 184.107.116.0/24:*712reject 108.163.147.0/24:*713reject 198.72.104.0/24:*714reject 67.205.125.0/24:*715reject 67.205.105.0/24:*716reject 184.107.95.0/24:*717reject 5.145.168.0/21:*718reject 37.235.53.0/24:*719reject 37.252.96.0/24:*720reject 77.81.112.0/22:*721reject 77.81.116.0/22:*722reject 91.192.108.0/22:*723reject 93.93.64.0/21:*724reject 151.236.23.0/24:*725reject 158.255.238.0/24:*726reject 185.49.192.0/22:*727reject 185.50.196.0/22:*728reject 185.66.175.0/24:*729reject 185.76.77.0/24:*730reject 185.86.210.0/24:*731reject 185.104.152.0/24:*732reject 185.129.249.0/24:*733reject 192.71.213.0/24:*734reject 195.78.228.0/22:*735reject 23.217.172.41:*736reject 23.217.173.70:*737reject 23.217.161.62:*738reject 23.217.161.153:*739reject 23.235.33.144:*740accept *:20-21741accept *:43742accept *:53743accept *:80744accept *:110745accept *:143746accept *:220747accept *:443748accept *:873749accept *:989-990750accept *:991751accept *:992752accept *:993753accept *:995754accept *:1194755accept *:1293756accept *:3690757accept *:4321758accept *:5222-5223759accept *:5228760accept *:9418761accept *:11371762accept *:64738763reject *:*764tunnelled-dir-server765router-sig-ed25519 JWCYm75YxNMFHgUUI4cJyRgDGwcIedVSYIQERCdJFlRMjxPS9LOvcUzuv4rBZQLC3RAA80j7D5udcfeW0R0SDw766router-signature767-----BEGIN SIGNATURE-----768SLhtm94eITNNjle4PRclrt7uW/PswS5ByuQfQJ50m5tD+ENoZQx02HNWhD2Ovw8D769LEAPxV9sbjt8fzJ/EIzdl8vh+Nz2SIPJFBU1dkRkWSVE+Is0JPRqNKlzpVpWfW8h770zKOoQK1MV0YfYNhvLoSV9li7ed1GJrw9kmWOUgoRV3s=771-----END SIGNATURE-----772"""773def test_rd_parser(rd_example):774 res = RouterDescriptorParser.parse(rd_example)775 print(res)776@pytest.fixture777def rd_example2():778 return """router FalkensteinTor02 5.9.43.211 9001 0 0779identity-ed25519780-----BEGIN ED25519 CERT-----781AQQABsdtAbJp6YkI/WzQR8BP/30zhjSwogIlmyv6R/H5ru6ZgRhmAQAgBAATlA+2782LrLjDwoljVbbgDmbudSPI8ZcxiLR0qDaIBslLAjhjMMY5E+Joq39z+uytdAxKLSl783LtjMg4X3WRb3jGy+8gVbiYgpbCjvSnfQbEHmm8C6VxHWoMQShsT4LwPJiQs=784-----END ED25519 CERT-----785master-key-ed25519 E5QPti6y4w8KJY1W24A5m7nUjyPGXMYi0dKg2iAbJSw786or-address [2a01:4f8:161:32c7::2]:9001787platform Tor 0.4.5.0-alpha-dev on Linux788proto Cons=1-2 Desc=1-2 DirCache=1-2 FlowCtrl=1 HSDir=1-2 HSIntro=3-5 HSRend=1-2 Link=1-5 LinkAuth=1,3 Microdesc=1-2 Padding=2 Relay=1-3789published 2020-08-20 09:56:35790fingerprint 0512 FE6B E9CC A0ED 1331 52E6 4010 B2FB A141 EB10791uptime 64805792bandwidth 31457280 73400320 33471488793extra-info-digest F631D985A46F850C46FE2355947D36CA45DBE335 M/2vGW74uurcpt0e+7/EJqOV4LpoJRYAZ+G7I9f58L4794onion-key795-----BEGIN RSA PUBLIC KEY-----796MIGJAoGBAMC8N8BeGYY6vt/QO1QFd0puJpEZq83iISrgGL1KAKleTGbqLpv7WBH0797SKIDFpleHiElq74yC6yXZf9cDCfXzctpVWa1zPI/ISCJaxFEbDLMLTgaRy7PGA9d798Sxze6wrlo+eXmLc9qSrJLyNScMpVRjL748YXxypbL+2RbHCfB7o1AgMBAAE=799-----END RSA PUBLIC KEY-----800signing-key801-----BEGIN RSA PUBLIC KEY-----802MIGJAoGBAL+bi9Kfe8dhwaaq8c5kcAXbCHUyvfx9gVBCuDj7jAOQKy16zBfuUh7q803614bwRiD4sFC4QFq+j43EjJgXeReAH9sDeWJxP3Q9muEuCcqfmf+OAlYjruXEYrT804LEO6q2Hd22nJ9WaxEHgvSCvECTNmODUdgP0DJpkKcwks3VM4wamZAgMBAAE=805-----END RSA PUBLIC KEY-----806onion-key-crosscert807-----BEGIN CROSSCERT-----808Jq35dkFnNz2asXwJfQR57FRySoaluo1FEhFe5l349iLKy1Nd9U2YAYErg9845GRp809BD1OYpqMYvtgxOvNz6ltsbfz6eHaOxJhnXumLyv59cDtLAQ+Piicar9EbPmBCQsp810c0K9YfijqJ8y4EbEGpCW01nTglqKr+527wD+Hbb346g=811-----END CROSSCERT-----812ntor-onion-key-crosscert 1813-----BEGIN ED25519 CERT-----814AQoABsh6AROUD7YusuMPCiWNVtuAOZu51I8jxlzGItHSoNogGyUsAI8evueV8KZm815nXoT6qtg208Dbmh19z0jPm745LXgElQ8U/CTLOSVGW1fMkVs0zPjyvpSVrTjH5fz816LRcQgJ/X6gM=817-----END ED25519 CERT-----818family $0512FE6BE9CCA0ED133152E64010B2FBA141EB10 $08F06A0DDAFABF9A26FCB2E392A1435F9E048216 $0A7208B8903DD3FF5CDFA218A3823AF498CE69CE $128FC6D8FBF753121C5662FEE309CCD47B64BA6B $599A708756048993A1029B2775EEF8C9E40BB640 $695D811B130673C2DE8DCFC5A9E742790BD25066 $7185B69E3267E71D0E4CBE30209677205DEA5E67 $8E5F4EE45E0631A60E59CAA42E1464FD7120459D $B70BD334FFEE23E653B75219AE12CF0236BCFCBB $B76A047C20D3E4F9B5A64428298DA55A90D62472 $D7230F4F13324A28C308AF94E2385D0A7F1B05F9 $DEF8C760A79FEF2358E03AE5A1950086ABEB953E $F0F13714732C347312426EC2B8D5C4940EAA45BA $F5C3DA7642BB037E0D279359AE88CD7FC03A98A0819hidden-service-dir820contact <tor AT afo MINUS tm DOT org>821ntor-onion-key xbqQBTwgBWJxkxBrHuHsKp5WyZ4yof09zsnGZMXB+Rk822reject *:*823tunnelled-dir-server824router-sig-ed25519 Hk2KgDHyw7OAo8g79eo7mEHK/k3UszFAH1Fkole70BIdUDOvA/8oHwSA2aO+Rp1i6v0I/LlKr0u8/pqDzGd7Bg825router-signature826-----BEGIN SIGNATURE-----827UmJeAncV38dJBgsKSVxw14cRdo/YTu3owAa+YJOWkWsNl03UATGeNAWQGc2ZwhI3828nk4ha7uQ254z5uDyWT5vD7QbPREcFbWvif7EWRqqBi0kdwSClYzMI/+4dFh+dz3v829jvfDaEld8KBz3UxumcxRnswmDzC9zsS3Bq/LxQ7LrR4=830-----END SIGNATURE-----831"""832def test_rd_parser2(rd_example2):833 res = RouterDescriptorParser.parse(rd_example2)...

Full Screen

Full Screen

Model_test_1.py

Source:Model_test_1.py Github

copy

Full Screen

...186 reject_train = reject_data[feature_used]187 predict_reject_prob = pipeline_model.predict_proba(reject_train)[:,1]188 return predict_reject_prob,reject_train189# 拒绝样本与原始样本合并190def raw_combine_reject(train_data,reject_train_combine_label,feature_used):191 train_combine_reject_1 = pd.concat([train_data[feature_used+['user_type']],reject_train_combine_label\192 [feature_used+['user_type']]]).reset_index(drop=True)193 X_train_reject = train_combine_reject_1[feature_used]194 y_train_reject = train_combine_reject_1['user_type']195 return X_train_reject,y_train_reject196# 拒绝样本单轮次测试197@timecount()198def reject_main_train(reject_train,train_data,predict_reject_prob,model_list,\199 feature_used,model_auc_raw,bad,good,diff=0): 200 reject_evalutaion_detail = {}201 pipeline_model_userful = []202 reject_train_userful = []203 for ratio in [0.3,0.5,1,2]:204 for n_sample in [1000,2000,3000,4000]: 205 print('开始 %s_%s'%(ratio,n_sample))206 # 选取拒绝标签207 reject_train_combine_label = reject_data_masked(reject_train,\208 predict_reject_prob,n_sample,ratio,bad,good)209 # 合并数据训练集210 X_train_reject_1,y_train_reject_1 = raw_combine_reject(train_data,\211 reject_train_combine_label,feature_used)212 213 # 拒绝样本训练214 pipeline_model_reject_1 = fuse_model_train(X_train_reject_1,y_train_reject_1,\215 model_list,category_feature,numeric_feature,classifier_type='train')216 # 拒绝样本评估217 evaluation_result = model_fuse_evaluation(pipeline_model_reject_1,train_data,\218 valid_data,test_data,feature_used)219 reject_evalutaion_detail[str(ratio)+'_'+str(n_sample)] = evaluation_result220 if evaluation_result[1] - model_auc_raw >= diff:221 print('reject auc:',evaluation_result[1],'raw_auc:',model_auc_raw)222 print(y_train_reject_1.value_counts())223 pipeline_model_userful.append(pipeline_model_reject_1)224 reject_train_userful.append(reject_train_combine_label)...

Full Screen

Full Screen

policy.py

Source:policy.py Github

copy

Full Screen

1"""2Unit tests for the stem.exit_policy.ExitPolicy class.3"""4import pickle5import unittest6try:7 # added in python 3.38 from unittest.mock import Mock, patch9except ImportError:10 from mock import Mock, patch11from stem.exit_policy import (12 DEFAULT_POLICY_RULES,13 get_config_policy,14 ExitPolicy,15 MicroExitPolicy,16 ExitPolicyRule,17)18class TestExitPolicy(unittest.TestCase):19 def test_example(self):20 # tests the ExitPolicy and MicroExitPolicy pydoc examples21 policy = ExitPolicy('accept *:80', 'accept *:443', 'reject *:*')22 self.assertEqual('accept *:80, accept *:443, reject *:*', str(policy))23 self.assertEqual('accept 80, 443', policy.summary())24 self.assertTrue(policy.can_exit_to('75.119.206.243', 80))25 policy = MicroExitPolicy('accept 80,443')26 self.assertTrue(policy.can_exit_to('75.119.206.243', 80))27 def test_constructor(self):28 # The ExitPolicy constructor takes a series of string or ExitPolicyRule29 # entries. Extra whitespace is ignored to make csvs easier to handle.30 expected_policy = ExitPolicy(31 ExitPolicyRule('accept *:80'),32 ExitPolicyRule('accept *:443'),33 ExitPolicyRule('reject *:*'),34 )35 policy = ExitPolicy('accept *:80', 'accept *:443', 'reject *:*')36 self.assertEqual(expected_policy, policy)37 policy = ExitPolicy(*'accept *:80, accept *:443, reject *:*'.split(','))38 self.assertEqual(expected_policy, policy)39 # checks that we truncate after getting a catch-all policy40 policy = ExitPolicy(*'accept *:80, accept *:443, reject *:*, accept *:20-50'.split(','))41 self.assertEqual(expected_policy, policy)42 # checks that we compress redundant policies43 policy = ExitPolicy(*'reject *:80, reject *:443, reject *:*'.split(','))44 self.assertEqual(ExitPolicy('reject *:*'), policy)45 def test_can_exit_to(self):46 # Basic sanity test for our can_exit_to() method. Most of the interesting47 # use cases (ip masks, wildcards, etc) are covered by the ExitPolicyRule48 # tests.49 policy = ExitPolicy('accept *:80', 'accept *:443', 'reject *:*')50 for index in range(1, 100):51 ip_addr = '%i.%i.%i.%i' % (index / 2, index / 2, index / 2, index / 2)52 expected_result = index in (80, 443)53 self.assertEqual(expected_result, policy.can_exit_to(ip_addr, index))54 self.assertEqual(expected_result, policy.can_exit_to(port = index))55 def test_can_exit_to_strictness(self):56 # Check our 'strict' argument.57 policy = ExitPolicy('reject 1.0.0.0/8:80', 'accept *:*')58 self.assertEqual(False, policy.can_exit_to(None, 80, strict = True)) # can't exit to *all* instances of port 8059 self.assertEqual(True, policy.can_exit_to(None, 80, strict = False)) # can exit to *an* instance of port 8060 policy = ExitPolicy('accept 1.0.0.0/8:80', 'reject *:*')61 self.assertEqual(False, policy.can_exit_to(None, 80, strict = True)) # can't exit to *all* instances of port 8062 self.assertEqual(True, policy.can_exit_to(None, 80, strict = False)) # can exit to *an* instance of port 8063 def test_is_exiting_allowed(self):64 test_inputs = {65 (): True,66 ('accept *:*', ): True,67 ('reject *:*', ): False,68 ('accept *:80', 'reject *:*'): True,69 ('reject *:80', 'accept *:80', 'reject *:*'): False,70 ('reject *:50-90', 'accept *:80', 'reject *:*'): False,71 ('reject *:2-65535', 'accept *:80-65535', 'reject *:*'): False,72 ('reject *:2-65535', 'accept 127.0.0.0:1', 'reject *:*'): True,73 ('reject 127.0.0.1:*', 'accept *:80', 'reject *:*'): True,74 }75 for rules, expected_result in test_inputs.items():76 policy = ExitPolicy(*rules)77 self.assertEqual(expected_result, policy.is_exiting_allowed())78 def test_summary_examples(self):79 # checks the summary() method's pydoc examples80 policy = ExitPolicy('accept *:80', 'accept *:443', 'reject *:*')81 self.assertEqual('accept 80, 443', policy.summary())82 policy = ExitPolicy('accept *:443', 'reject *:1-1024', 'accept *:*')83 self.assertEqual('reject 1-442, 444-1024', policy.summary())84 def test_summary_large_ranges(self):85 # checks the summary() method when the policy includes very large port ranges86 policy = ExitPolicy('reject *:80-65535', 'accept *:1-65533', 'reject *:*')87 self.assertEqual('accept 1-79', policy.summary())88 def test_without_port(self):89 policy = get_config_policy('accept 216.58.193.78, reject *')90 self.assertEqual([ExitPolicyRule('accept 216.58.193.78:*'), ExitPolicyRule('reject *:*')], list(policy))91 policy = get_config_policy('reject6 [2a00:1450:4001:081e:0000:0000:0000:200e]')92 self.assertEqual([ExitPolicyRule('reject [2a00:1450:4001:081e:0000:0000:0000:200e]:*')], list(policy))93 def test_non_private_non_default_policy(self):94 policy = get_config_policy('reject *:80-65535, accept *:1-65533, reject *:*')95 for rule in policy:96 self.assertFalse(rule.is_private())97 self.assertFalse(rule.is_default())98 self.assertFalse(policy.has_private())99 self.assertFalse(policy.has_default())100 self.assertEqual(policy, policy.strip_private())101 self.assertEqual(policy, policy.strip_default())102 def test_all_private_policy(self):103 for port in ('*', '80', '1-1024'):104 private_policy = get_config_policy('reject private:%s' % port, '12.34.56.78')105 for rule in private_policy:106 self.assertTrue(rule.is_private())107 self.assertEqual(ExitPolicy(), private_policy.strip_private())108 # though not commonly done, technically private policies can be accept rules too109 private_policy = get_config_policy('accept private:*')110 self.assertEqual(ExitPolicy(), private_policy.strip_private())111 @patch('socket.gethostname', Mock(side_effect = IOError('no address')))112 def test_all_private_policy_without_network(self):113 for rule in get_config_policy('reject private:80, accept *:80'):114 # all rules except the ending accept are part of the private policy115 self.assertEqual(str(rule) != 'accept *:80', rule.is_private())116 def test_all_default_policy(self):117 policy = ExitPolicy(*DEFAULT_POLICY_RULES)118 for rule in policy:119 self.assertTrue(rule.is_default())120 self.assertTrue(policy.has_default())121 self.assertEqual(ExitPolicy(), policy.strip_default())122 def test_mixed_private_policy(self):123 policy = get_config_policy('accept *:80, reject private:1-65533, accept *:*')124 for rule in policy:125 self.assertTrue(rule.is_accept != rule.is_private()) # only reject rules are the private ones126 self.assertEqual(get_config_policy('accept *:80, accept *:*'), policy.strip_private())127 def test_mixed_default_policy(self):128 policy = ExitPolicy('accept *:80', 'accept 127.0.0.1:1-65533', *DEFAULT_POLICY_RULES)129 for rule in policy:130 # only accept-all and reject rules are the default ones131 self.assertTrue(rule.is_accept != rule.is_default() or (rule.is_accept and rule.is_address_wildcard() and rule.is_port_wildcard()))132 self.assertEqual(get_config_policy('accept *:80, accept 127.0.0.1:1-65533'), policy.strip_default())133 def test_get_config_policy_with_ipv6(self):134 # ensure our constructor accepts addresses both with and without brackets135 self.assertTrue(get_config_policy('reject private:80', 'fe80:0000:0000:0000:0202:b3ff:fe1e:8329').is_exiting_allowed())136 self.assertTrue(get_config_policy('reject private:80', '[fe80:0000:0000:0000:0202:b3ff:fe1e:8329]').is_exiting_allowed())137 def test_str(self):138 # sanity test for our __str__ method139 policy = ExitPolicy(' accept *:80\n', '\taccept *:443')140 self.assertEqual('accept *:80, accept *:443', str(policy))141 policy = ExitPolicy('reject 0.0.0.0/255.255.255.0:*', 'accept *:*')142 self.assertEqual('reject 0.0.0.0/24:*, accept *:*', str(policy))143 def test_iter(self):144 # sanity test for our __iter__ method145 rules = [146 ExitPolicyRule('accept *:80'),147 ExitPolicyRule('accept *:443'),148 ExitPolicyRule('reject *:*'),149 ]150 self.assertEqual(rules, list(ExitPolicy(*rules)))151 self.assertEqual(rules, list(ExitPolicy('accept *:80', 'accept *:443', 'reject *:*')))152 def test_microdescriptor_parsing(self):153 # mapping between inputs and if they should succeed or not154 test_inputs = {155 'accept 80': True,156 'accept 80,443': True,157 '': False,158 'accept': False,159 'accept ': False,160 'accept\t80,443': False,161 'accept 80, 443': False,162 'accept 80,\t443': False,163 '80,443': False,164 'accept 80,-443': False,165 'accept 80,+443': False,166 'accept 80,66666': False,167 'reject 80,foo': False,168 'bar 80,443': False,169 }170 for policy_arg, expect_success in test_inputs.items():171 try:172 policy = MicroExitPolicy(policy_arg)173 if expect_success:174 self.assertEqual(policy_arg, str(policy))175 else:176 self.fail()177 except ValueError:178 if expect_success:179 self.fail()180 def test_microdescriptor_attributes(self):181 # checks that its is_accept attribute is properly set182 # single port183 policy = MicroExitPolicy('accept 443')184 self.assertTrue(policy.is_accept)185 # multiple ports186 policy = MicroExitPolicy('accept 80,443')187 self.assertTrue(policy.is_accept)188 # port range189 policy = MicroExitPolicy('reject 1-1024')190 self.assertFalse(policy.is_accept)191 def test_microdescriptor_can_exit_to(self):192 test_inputs = {193 'accept 443': {442: False, 443: True, 444: False},194 'reject 443': {442: True, 443: False, 444: True},195 'accept 80,443': {80: True, 443: True, 10: False},196 'reject 1-1024': {1: False, 1024: False, 1025: True},197 }198 for policy_arg, attr in test_inputs.items():199 policy = MicroExitPolicy(policy_arg)200 for port, expected_value in attr.items():201 self.assertEqual(expected_value, policy.can_exit_to(port = port))202 # address argument should be ignored203 policy = MicroExitPolicy('accept 80,443')204 self.assertFalse(policy.can_exit_to('127.0.0.1', 79))205 self.assertTrue(policy.can_exit_to('127.0.0.1', 80))206 def test_get_config_policy(self):207 test_inputs = {208 '': ExitPolicy(),209 'reject *': ExitPolicy('reject *:*'),210 'reject *:*': ExitPolicy('reject *:*'),211 'reject private': ExitPolicy(212 'reject 0.0.0.0/8:*',213 'reject 169.254.0.0/16:*',214 'reject 127.0.0.0/8:*',215 'reject 192.168.0.0/16:*',216 'reject 10.0.0.0/8:*',217 'reject 172.16.0.0/12:*',218 'reject 12.34.56.78:*',219 ),220 'accept *:80, reject *': ExitPolicy(221 'accept *:80',222 'reject *:*',223 ),224 ' accept *:80, reject * ': ExitPolicy(225 'accept *:80',226 'reject *:*',227 ),228 }229 for test_input, expected in test_inputs.items():230 self.assertEqual(expected, get_config_policy(test_input, '12.34.56.78'))231 test_inputs = (232 'blarg',233 'accept *:*:*',234 'acceptt *:80',235 'accept 257.0.0.1:80',236 'accept *:999999',237 )238 for test_input in test_inputs:239 self.assertRaises(ValueError, get_config_policy, test_input)240 def test_pickleability(self):241 """242 Checks that we can unpickle ExitPolicy instances.243 """244 policy = ExitPolicy('accept *:80', 'accept *:443', 'reject *:*')245 self.assertTrue(policy.can_exit_to('74.125.28.106', 80))246 encoded_policy = pickle.dumps(policy)247 restored_policy = pickle.loads(encoded_policy)248 self.assertEqual(policy, restored_policy)249 self.assertTrue(restored_policy.is_exiting_allowed())...

Full Screen

Full Screen

feature_dersig.py

Source:feature_dersig.py Github

copy

Full Screen

1#!/usr/bin/env python32# Copyright (c) 2015-2018 The Bitcoin Core developers3# Distributed under the MIT software license, see the accompanying4# file COPYING or http://www.opensource.org/licenses/mit-license.php.5"""Test BIP66 (DER SIG).6Test that the DERSIG soft-fork activates at (regtest) height 1251.7"""8from test_framework.blocktools import create_coinbase, create_block, create_transaction9from test_framework.messages import msg_block10from test_framework.mininode import mininode_lock, P2PInterface11from test_framework.script import CScript12from test_framework.test_framework import BitcoinTestFramework13from test_framework.util import assert_equal, bytes_to_hex_str, wait_until14DERSIG_HEIGHT = 125115# Reject codes that we might receive in this test16REJECT_INVALID = 1617REJECT_OBSOLETE = 1718REJECT_NONSTANDARD = 6419# A canonical signature consists of:20# <30> <total len> <02> <len R> <R> <02> <len S> <S> <hashtype>21def unDERify(tx):22 """23 Make the signature in vin 0 of a tx non-DER-compliant,24 by adding padding after the S-value.25 """26 scriptSig = CScript(tx.vin[0].scriptSig)27 newscript = []28 for i in scriptSig:29 if (len(newscript) == 0):30 newscript.append(i[0:-1] + b'\0' + i[-1:])31 else:32 newscript.append(i)33 tx.vin[0].scriptSig = CScript(newscript)34class BIP66Test(BitcoinTestFramework):35 def set_test_params(self):36 self.num_nodes = 137 self.extra_args = [['-whitelist=127.0.0.1']]38 self.setup_clean_chain = True39 def skip_test_if_missing_module(self):40 self.skip_if_no_wallet()41 def run_test(self):42 self.nodes[0].add_p2p_connection(P2PInterface())43 self.log.info("Mining %d blocks", DERSIG_HEIGHT - 2)44 self.coinbase_txids = [self.nodes[0].getblock(b)['tx'][0] for b in self.nodes[0].generate(DERSIG_HEIGHT - 2)]45 self.nodeaddress = self.nodes[0].getnewaddress()46 self.log.info("Test that a transaction with non-DER signature can still appear in a block")47 spendtx = create_transaction(self.nodes[0], self.coinbase_txids[0],48 self.nodeaddress, amount=1.0)49 unDERify(spendtx)50 spendtx.rehash()51 tip = self.nodes[0].getbestblockhash()52 block_time = self.nodes[0].getblockheader(tip)['mediantime'] + 153 block = create_block(int(tip, 16), create_coinbase(DERSIG_HEIGHT - 1), block_time)54 block.nVersion = 255 block.vtx.append(spendtx)56 block.hashMerkleRoot = block.calc_merkle_root()57 block.rehash()58 block.solve()59 self.nodes[0].p2p.send_and_ping(msg_block(block))60 assert_equal(self.nodes[0].getbestblockhash(), block.hash)61 self.log.info("Test that blocks must now be at least version 3")62 tip = block.sha25663 block_time += 164 block = create_block(tip, create_coinbase(DERSIG_HEIGHT), block_time)65 block.nVersion = 266 block.rehash()67 block.solve()68 self.nodes[0].p2p.send_and_ping(msg_block(block))69 assert_equal(int(self.nodes[0].getbestblockhash(), 16), tip)70 wait_until(lambda: "reject" in self.nodes[0].p2p.last_message.keys(), lock=mininode_lock)71 with mininode_lock:72 assert_equal(self.nodes[0].p2p.last_message["reject"].code, REJECT_OBSOLETE)73 assert_equal(self.nodes[0].p2p.last_message["reject"].reason, b'bad-version(0x00000002)')74 assert_equal(self.nodes[0].p2p.last_message["reject"].data, block.sha256)75 del self.nodes[0].p2p.last_message["reject"]76 self.log.info("Test that transactions with non-DER signatures cannot appear in a block")77 block.nVersion = 378 spendtx = create_transaction(self.nodes[0], self.coinbase_txids[1],79 self.nodeaddress, amount=1.0)80 unDERify(spendtx)81 spendtx.rehash()82 # First we show that this tx is valid except for DERSIG by getting it83 # rejected from the mempool for exactly that reason.84 assert_equal(85 [{'txid': spendtx.hash, 'allowed': False, 'reject-reason': '64: non-mandatory-script-verify-flag (Non-canonical DER signature)'}],86 self.nodes[0].testmempoolaccept(rawtxs=[bytes_to_hex_str(spendtx.serialize())], allowhighfees=True)87 )88 # Now we verify that a block with this transaction is also invalid.89 block.vtx.append(spendtx)90 block.hashMerkleRoot = block.calc_merkle_root()91 block.rehash()92 block.solve()93 self.nodes[0].p2p.send_and_ping(msg_block(block))94 assert_equal(int(self.nodes[0].getbestblockhash(), 16), tip)95 wait_until(lambda: "reject" in self.nodes[0].p2p.last_message.keys(), lock=mininode_lock)96 with mininode_lock:97 # We can receive different reject messages depending on whether98 # bitcoind is running with multiple script check threads. If script99 # check threads are not in use, then transaction script validation100 # happens sequentially, and bitcoind produces more specific reject101 # reasons.102 assert self.nodes[0].p2p.last_message["reject"].code in [REJECT_INVALID, REJECT_NONSTANDARD]103 assert_equal(self.nodes[0].p2p.last_message["reject"].data, block.sha256)104 if self.nodes[0].p2p.last_message["reject"].code == REJECT_INVALID:105 # Generic rejection when a block is invalid106 assert_equal(self.nodes[0].p2p.last_message["reject"].reason, b'block-validation-failed')107 else:108 assert b'Non-canonical DER signature' in self.nodes[0].p2p.last_message["reject"].reason109 self.log.info("Test that a version 3 block with a DERSIG-compliant transaction is accepted")110 block.vtx[1] = create_transaction(self.nodes[0], self.coinbase_txids[1], self.nodeaddress, amount=1.0)111 block.hashMerkleRoot = block.calc_merkle_root()112 block.rehash()113 block.solve()114 self.nodes[0].p2p.send_and_ping(msg_block(block))115 assert_equal(int(self.nodes[0].getbestblockhash(), 16), block.sha256)116if __name__ == '__main__':...

Full Screen

Full Screen

util.py

Source:util.py Github

copy

Full Screen

1import math2import matplotlib.pyplot as plt3def getMax(smooth_probability,h_max,j):4 max_label0 = -15 max_label1 = -16 for i in range(h_max,j+1):7 # print("cutcutcut",smooth_probability[i][0],smooth_probability[i][1])8 if smooth_probability[i][0] > max_label0:9 max_label0 = smooth_probability[i][0]10 if smooth_probability[i][1] > max_label1:11 max_label1 = smooth_probability[i][1]12 return max_label0,max_label113def posteriorHandling(probability,fbankEndFrame):14 15 confidence = []16 for i in range(len(fbankEndFrame)):17 if i == 0:18 fbank_probability = probability[0:fbankEndFrame[0]]19 else:20 fbank_probability = probability[fbankEndFrame[i - 1]:fbankEndFrame[i]]21 22 #print("fbank_pro",fbank_probability)23 smooth_probability = []24 for j in range(len(fbank_probability)):25 sum_label0 = 026 sum_label1 = 027 sum_label2 = 028 w_smooth = 3029 h_smooth = max(0,(j - w_smooth + 1))30 division = j - h_smooth + 131 for temp in range(h_smooth,j+1):32 sum_label0 += fbank_probability[temp][0]33 sum_label1 += fbank_probability[temp][1]34 sum_label2 += fbank_probability[temp][2]35 smooth_probability.append([sum_label0/division,sum_label1/division,sum_label2/division])36 37 #print("smooth",smooth_probability)38 frame_confidence = []39 confidence_temp = 040 for j in range(len(fbank_probability)):41 w_max = 10042 h_max = max(0,(j - w_max + 1))43 max_label0,max_label1 = getMax(smooth_probability,h_max,j)44 confidence_temp = (max_label0 * max_label1)45 frame_confidence.append(confidence_temp)46 confidence.append(math.sqrt(max(frame_confidence)))47 #print("fbank_pro",fbank_probability)48 #print("smooth",smooth_probability)49 #print("frame_confi",frame_confidence)50 #print("confi",confidence)51 #print("smoooth_pro",smooth_probability)52 return confidence53def plot(false_alarm_rate_list, false_reject_rate_list):54 plt.figure(figsize=(8, 4))55 plt.plot(false_alarm_rate_list, false_reject_rate_list)56 plt.xlabel('false_alarm_rate')57 plt.ylabel('false_reject_rate')58 plt.title('ROC')59 plt.savefig("new.png")60 plt.show()61def get_label_list():62 l=[]63 f = open("/home/disk2/internship_anytime/aslp_hotword_data/aslp_wake_up_word_data/test.scp", "r")64 temp = f.read()65 test_list = temp.split('\n')66 for example in test_list:67 if example.split('/').count("positive"):68 l.append(1)69 else :70 l.append(0)71 f.close()72# print(l)73 return l74def do_eval(confidence):75 label=get_label_list()76 threshold_part = 1000077 false_alarm_rate_list=[]78 false_reject_rate_list=[]79 for i in range(1,threshold_part):80 threshold=float(i)/threshold_part81 true_alarm = true_reject = false_reject = false_alarm = 082 for j in range(len(confidence)):83 if confidence[j]<threshold:84 if label[j]==0:85 true_reject+=186 else:87 false_reject+=188 else :89 if label[j]==0:90 false_alarm+=191 else :92 true_alarm+=193 if false_reject + true_reject == 0 or false_alarm + true_alarm == 0:94 continue95 false_alarm_rate = float(false_alarm) / (false_alarm + true_alarm)96 false_reject_rate = float(false_reject) / (false_reject + true_reject)97 false_alarm_rate_list.append(false_alarm_rate)98 false_reject_rate_list.append(false_reject_rate)99 plot(false_alarm_rate_list, false_reject_rate_list)100 print(false_alarm_rate_list[0::100])...

Full Screen

Full Screen

admin.py

Source:admin.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2#3# Djangoplicity4# Copyright 2007-2008 ESA/Hubble5#6# Authors:7# Lars Holm Nielsen <lnielsen@eso.org>8# Luis Clara Gomes <lcgomes@eso.org>9"""10"""11from djangoplicity.contrib import admin as dpadmin12from djangoplicity.archives.contrib.satchmo.freeorder.models import FreeOrder13from django.utils.translation import ugettext_lazy as _14class FreeOrderAdmin( dpadmin.DjangoplicityModelAdmin ):15 list_display = ( 'name', 'email', 'country', 'accepted', 'submitted', 'reviewed', 'discount_code' )16 list_filter = ( 'accepted', 'country')17 search_fields = ( 'name', 'email', 'justification', 'discount_code' )18 fieldsets = (19 ( 'Application', {'fields': ( 'name', 'email', 'country', 'justification'), } ),20 ( 'Review', {'fields': ( 'accepted', 'reject_reason', 'reviewed' ), } ),21 ( 'Discount Code', {'fields': ('discount_code', ), }),22 )23 ordering = ('-submitted', )24 readonly_fields = ['reviewed', 'discount_code']25 actions = ['action_accept', 'action_reject_noreason', 'action_reject_nostock', 'action_reject_unqualified', 'action_update_accepted']26 def action_update_accepted( self, request, objects ):27 for obj in objects:28 if obj.accepted:29 obj.rebuild_free_products()30 self.message_user( request, _( "Selected free order applications were updated" ) )31 action_update_accepted.short_description = _("Update accepted free order applications")32 def action_accept( self, request, objects ):33 for obj in objects:34 obj.accepted = True35 obj.save()36 self.message_user( request, _( "Selected free order applications were accepted" ) )37 action_accept.short_description = _("Accept selected free order applications")38 def action_reject_noreason( self, request, objects ):39 for obj in objects:40 obj.accepted = False41 obj.save()42 self.message_user( request, _( "Selected free order applications were rejected (no reason)" ) )43 action_reject_noreason.short_description = _("Reject selected free order applications (no reason)")44 def action_reject_nostock( self, request, objects ):45 for obj in objects:46 obj.accepted = False47 obj.reject_reason = 'NOSTOCK'48 obj.save()49 self.message_user( request, _( "Selected free order applications were rejected (no stock)" ) )50 action_reject_nostock.short_description = _("Reject selected free order applications (no stock)")51 def action_reject_unqualified( self, request, objects ):52 for obj in objects:53 obj.accepted = False54 obj.reject_reason = 'UNQUALIFIED'55 obj.save()56 self.message_user( request, _( "Selected free order applications were rejected (unqualified)" ) )57 action_reject_unqualified.short_description = _("Reject selected free order applications (unqualified)")58 def action_reject_insufficient( self, request, objects ):59 for obj in objects:60 obj.accepted = False61 obj.reject_reason = 'INSUFFICIENT'62 obj.save()63 self.message_user( request, _( "Selected free order applications were rejected (insufficient)" ) )64 action_reject_unqualified.short_description = _("Reject selected free order applications (insufficient)")65def register_with_admin( admin_site ):...

Full Screen

Full Screen

AnnotationPlanTemplate.py

Source:AnnotationPlanTemplate.py Github

copy

Full Screen

1__author__ = 'ha'2PLANS_ONE_FINDING = {3 "accepted_code": [[(0,"accept")]],4 "rejected_code": [[(0,"reject")]],5 "accepted_qa1":[6 [(0, "accept"), (0, "accept")],7 [(0, "reject"), (0, "accept")]8 ],9 "rejected_qa1":[10 [(0, "accept"), (0, "reject")],11 [(0, "reject"), (0, "reject")]12 ],13 "accepted_qa2":[14 [(0, "accept"), (0, "accept"), (0, "accept")],15 [(0, "accept"), (0, "reject"), (0, "accept")],16 [(0, "reject"), (0, "accept"), (0, "accept")],17 [(0, "reject"), (0, "reject"), (0, "accept")]18 ],19 "rejected_qa2":[20 [(0, "accept"), (0, "accept"), (0, "reject")],21 [(0, "accept"), (0, "reject"), (0, "reject")],22 [(0, "reject"), (0, "reject"), (0, "reject")],23 [(0, "reject"), (0, "accept"), (0, "reject")]24 ],25 "accepted_qa3":[26 [(0, "accept"), (0, "accept"), (0, "accept"), (0, "accept")],27 [(0, "accept"), (0, "accept"), (0, "reject"), (0, "accept")],28 [(0, "accept"), (0, "reject"), (0, "accept"), (0, "accept")],29 [(0, "accept"), (0, "reject"), (0, "reject"), (0, "accept")],30 [(0, "reject"), (0, "accept"), (0, "accept"), (0, "accept")],31 [(0, "reject"), (0, "reject"), (0, "accept"), (0, "accept")],32 [(0, "reject"), (0, "reject"), (0, "reject"), (0, "accept")]33 ],34 "rejected_qa3":[35 [(0, "accept"), (0, "accept"), (0, "accept"), (0, "reject")],36 [(0, "accept"), (0, "accept"), (0, "reject"), (0, "reject")],37 [(0, "accept"), (0, "reject"), (0, "accept"), (0, "reject")],38 [(0, "accept"), (0, "reject"), (0, "reject"), (0, "reject")],39 [(0, "reject"), (0, "accept"), (0, "accept"), (0, "reject")],40 [(0, "reject"), (0, "reject"), (0, "accept"), (0, "reject")],41 [(0, "reject"), (0, "reject"), (0, "reject"), (0, "reject")]42 ],43}44plans = []45for k,v in zip(PLANS_ONE_FINDING.keys(), PLANS_ONE_FINDING.values()):46 plan = {"state": k}47 for steps in v:48 plan["steps"] = steps49 plans.append(plan)50PLANS_OPPS_WITH_ONE_FINDING = plans51PLANS_TWO_FINDINGS = {52 "accepted_code": [[(0,"accept")]],53 "rejected_code": [[(0, "reject") , (1, "reject")]],54 "rejected_moreFindings_code": [[(0,"reject")]],55 "accepted_qa1": [56 [(0, "accept") , (0, "accept")],57 [(0, "reject"), (1, "reject"), (1, "accept")],58 [(0, "reject"), (1, "accept"), (1, "accept")],59 ],60 "rejected_qa1": [61 [(0, "accept") , (1, "reject"), (1, "reject")],62 ],63 "rejected_moreFindings_qa1": [[(0,"accept"), (0, "reject")]],64 "accepted_qa2":[65 [(0, "accept"), (0, "accept"), (0, "accept")],66 [(0, "accept"), (0, "reject"), (1, "accept"), (1, "accept"), (1, "accept")]67 ],68}69PLANS_TWO_FINDINGS = {}70plans = []71for k,v in zip(PLANS_TWO_FINDINGS.keys(), PLANS_TWO_FINDINGS.values()):72 plan = {"state": k}73 for steps in v:74 plan["steps"] = steps75 plans.append(plan)...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch({ headless: false });4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.waitForSelector('input[type="text"]');7 await page.fill('input[type="text"]', 'hello world');8 await page.waitForSelector('input[type="submit"]');9 await page.click('input[type="submit"]');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.screenshot({ path: `example.png` });7 await browser.close();8})();9const playwright = require('playwright');10(async () => {11 for (const browserType of ['chromium', 'firefox', 'webkit']) {12 const browser = await playwright[browserType].launch();13 const context = await browser.newContext();14 const page = await context.newPage();15 await page.screenshot({ path: `example-${browserType}.png` });16 await browser.close();17 }18})();19const { chromium, firefox, webkit } = require('playwright');20(async () => {21 const browser = await chromium.launch();22})();23(async () => {24 const browser = await firefox.launch();25})();26(async () => {27 const browser = await webkit.launch();28})();29const playwright = require('playwright');30(async () => {31 const browser = await playwright.chromium.launch();32})();33const playwright = require('playwright');34(async () => {35 const browser = await playwright['chromium'].launch();36})();37const playwright = require('playwright');38(async () => {39 const browser = await playwright['chromium'].launch();40})();41const playwright = require('playwright');42(async () => {43 const browser = await playwright['chromium'].launch();44})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.route('**/*', route => {7 route.fulfill({8 });9 });10 await page.screenshot({ path: 'example.png' });11 await browser.close();12})();13const { chromium } = require('playwright');14(async () => {15 const browser = await chromium.launch();16 const context = await browser.newContext();17 const page = await context.newPage();18 await page.route('**/*', route => {19 route.fulfill({20 });21 });22 await page.screenshot({ path: 'example.png' });23 await browser.close();24})();25const { chromium } = require('playwright');26(async () => {27 const browser = await chromium.launch();28 const context = await browser.newContext();29 const page = await context.newPage();30 await page.route('**/*', route => {31 route.fulfill({32 });33 });34 await page.screenshot({ path: 'example.png' });35 await browser.close();36})();37const { chromium } = require('playwright');38(async () => {39 const browser = await chromium.launch();40 const context = await browser.newContext();41 const page = await context.newPage();42 await page.route('**/*', route => {43 route.fulfill({44 });45 });46 await page.screenshot({ path: 'example.png' });47 await browser.close();48})();49const { chromium } = require('playwright');50(async () => {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch({headless: false});4 const page = await browser.newPage();5 await page.route("**/*", route => route.fulfill({status: 200, body: "Hello World"}));6 await browser.close();7})();8const { chromium } = require('playwright');9(async () => {10 const browser = await chromium.launch({headless: false});11 const page = await browser.newPage();12 await page.route("**/*", route => route.fulfill({status: 200, body: "Hello World"}));13 await browser.close();14})();15const { chromium } = require('playwright');16(async () => {17 const browser = await chromium.launch({headless: false});18 const page = await browser.newPage();19 await page.route("**/*", route => route.fulfill({status: 200, body: "Hello World"}));20 await browser.close();21})();22const { chromium } = require('playwright');23(async () => {24 const browser = await chromium.launch({headless: false});25 const page = await browser.newPage();26 await page.route("**/*", route => route.fulfill({status: 200, body: "Hello World"}));27 await browser.close();28})();29const { chromium } = require('playwright');30(async () => {31 const browser = await chromium.launch({headless: false});32 const page = await browser.newPage();33 await page.route("**/*", route => route.fulfill({status: 200, body: "Hello World"}));34 await browser.close();35})();36const { chromium } = require('playwright');37(async () => {38 const browser = await chromium.launch({headless: false});39 const page = await browser.newPage();40 await page.route("**/*", route => route.f

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch({ headless: false });4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.click('text=Try it');7 const [popup] = await Promise.all([8 page.waitForEvent('popup'),9 page.click('text=Try it'),10 ]);11 await popup.waitForLoadState();12 await popup.close();13 await page.close();14 await context.close();15 await browser.close();16})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { test } = require('@playwright/test');2test('reject', async ({ page }) => {3 const error = await page.evaluate(() => {4 return Promise.reject(new Error('error message'));5 }).catch(e => e);6 console.log(error.message);7});8const { test } = require('@playwright/test');9test('reject', async ({ page }) => {10 const error = await page.evaluate(() => {11 return Promise.reject(new Error('error message'));12 }).then(() => null, e => e);13 console.log(error.message);14});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { test } = require('@playwright/test');2test('Test', async ({ page }) => {3 await page.click('button');4 await page.waitForSelector('text=Hello World!');5 await page.click('button');6 await page.waitForSelector('text=Hello World!');7});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { reject } = require('playwright-internal');2(async () => {3 try {4 const { page, browser } = await reject(new Error('Something went wrong'));5 } catch (e) {6 console.log(e);7 }8 await browser.close();9})();10 at Object.<anonymous> (/home/username/Desktop/PlaywrightInternal/test.js:6:30)11 at Module._compile (internal/modules/cjs/loader.js:1137:30)12 at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)13 at Module.load (internal/modules/cjs/loader.js:985:32)14 at Function.Module._load (internal/modules/cjs/loader.js:878:14)15 at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)16reject(reason)17const { reject } = require('playwright-internal');18(async () => {19 const { page, browser } = await reject(new Error('Something went wrong'));20 await browser.close();21})();22 at Object.<anonymous> (/home/username/Desktop/PlaywrightInternal/test.js:5:30)23 at Module._compile (internal/modules/cjs/loader.js:1137:30)24 at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)25 at Module.load (internal/modules/cjs/loader.js:985:32)26 at Function.Module._load (internal/modules/cjs/loader.js:878:14)27 at Function.executeUserEntryPoint [as runMain] (internal/modules

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal 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