Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def test_key_unknown(self):
with self.assertRaises(PyppeteerError):
await self.page.keyboard.press('NotARealKey')
with self.assertRaises(PyppeteerError):
await self.page.keyboard.press('Ñ‘')
with self.assertRaises(PyppeteerError):
await self.page.keyboard.press('😊')
async def test_key_unknown(self):
with self.assertRaises(PyppeteerError):
await self.page.keyboard.press('NotARealKey')
with self.assertRaises(PyppeteerError):
await self.page.keyboard.press('Ñ‘')
with self.assertRaises(PyppeteerError):
await self.page.keyboard.press('😊')
if response.getcode() != 200:
raise PyppeteerError(
'Unable to close target "{}"'.format(target_id)
)
start = time.time()
while time.time() - start < _CLOSE_TARGET_TIMEOUT:
ids = [target['targetId'] for target in self.targets()]
if target_id not in ids:
return
time.sleep(_CLOSE_TARGET_POLL_INTERVAL)
raise PyppeteerError(
'Unable to close target "{}" after {} seconds'.format(
target_id, _CLOSE_TARGET_TIMEOUT
)
"""Exceptions for pyppeteer package."""
import asyncio
class PyppeteerError(Exception): # noqa: D204
"""Base exception for pyppeteer."""
pass
class BrowserError(PyppeteerError): # noqa: D204
"""Exception raised from browser."""
pass
class ElementHandleError(PyppeteerError): # noqa: D204
"""ElementHandle related exception."""
pass
class NetworkError(PyppeteerError): # noqa: D204
"""Network/Protocol related exception."""
pass
class PageError(PyppeteerError): # noqa: D204
"""Page/Frame related exception."""
pass
class TimeoutError(asyncio.TimeoutError): # noqa: D204
"""Timeout Error class."""
def _keyDescriptionForString(self, keyString: str) -> Dict: # noqa: C901
shift = self._modifiers & 8
description = {
'key': '',
'keyCode': 0,
'code': '',
'text': '',
'location': 0,
}
definition: Dict = keyDefinitions.get(keyString) # type: ignore
if not definition:
raise PyppeteerError(f'Unknown key: {keyString}')
if 'key' in definition:
description['key'] = definition['key']
if shift and definition.get('shiftKey'):
description['key'] = definition['shiftKey']
if 'keyCode' in definition:
description['keyCode'] = definition['keyCode']
if shift and definition.get('shiftKeyCode'):
description['keyCode'] = definition['shiftKeyCode']
if 'code' in definition:
description['code'] = definition['code']
if 'location' in definition:
description['location'] = definition['location']
class BrowserError(PyppeteerError): # noqa: D204
"""Exception raised from browser."""
pass
class ElementHandleError(PyppeteerError): # noqa: D204
"""ElementHandle related exception."""
pass
class NetworkError(PyppeteerError): # noqa: D204
"""Network/Protocol related exception."""
pass
class PageError(PyppeteerError): # noqa: D204
"""Page/Frame related exception."""
pass
class TimeoutError(asyncio.TimeoutError): # noqa: D204
"""Timeout Error class."""
pass
class PyppeteerError(Exception): # noqa: D204
"""Base exception for pyppeteer."""
pass
class BrowserError(PyppeteerError): # noqa: D204
"""Exception raised from browser."""
pass
class ElementHandleError(PyppeteerError): # noqa: D204
"""ElementHandle related exception."""
pass
class NetworkError(PyppeteerError): # noqa: D204
"""Network/Protocol related exception."""
pass
class PageError(PyppeteerError): # noqa: D204
"""Page/Frame related exception."""
pass
class TimeoutError(asyncio.TimeoutError): # noqa: D204
"""Timeout Error class."""
pass
try:
chrome_url = get_chrome_url()
except:
logger.exception("Failed to get chrome URL")
job.status_message = "Failed to get chrome URL"
job.status = job.FAILED
job.save()
return
try:
result = asyncio.get_event_loop().run_until_complete(
execute_job(extractor_cls, chrome_url, job)
)
except (errors.PyppeteerError, asyncio.TimeoutError):
logger.exception("Pyppeteer failed, attempt %s of 3" % (i + 1))
time.sleep(5)
else:
break
else:
job.status_message = "Failed to get puppeteer to get url"
job.status = job.FAILED
job.save()
return
media_path = str(job.pk)
target_path = os.path.join(settings.MEDIA_ROOT, media_path)
if not os.path.isdir(target_path):
os.makedirs(target_path)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Exceptions for pyppeteer package."""
import asyncio
class PyppeteerError(Exception): # noqa: D204
"""Base exception for pyppeteer."""
pass
class BrowserError(PyppeteerError): # noqa: D204
"""Exception raised from browser."""
pass
class ElementHandleError(PyppeteerError): # noqa: D204
"""ElementHandle related exception."""
pass
class NetworkError(PyppeteerError): # noqa: D204
"""Network/Protocol related exception."""
pass
class PageError(PyppeteerError): # noqa: D204
"""Page/Frame related exception."""
if html:
proxies = provider.parse(html)
for p in proxies:
validator_queue.put(p)
# logger.debug('Put new proxy ip into queue: {}'.format(p.__str__()))
logger.info(
' {}: feed {} potential proxies into the validator queue'.format(provider_name, len(proxies))
)
except (KeyboardInterrupt, InterruptedError, SystemExit):
worker.stop()
logger.info('worker_process exited.')
break
except pyppeteer.errors.PyppeteerError as e:
logger.debug("""pyppeteer.errors.PyppeteerError detected: %s\n
'Please make sure you have installed all the dependencies for chromium correctly""", e)