aboutsummaryrefslogtreecommitdiffhomepage
path: root/libs/cloudscraper/interpreters/v8.py
blob: 5d00fb40e466b2e841bb711e7a8c99b37a542693 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from __future__ import absolute_import

import sys

try:
    import v8eval
except ImportError:
    sys.tracebacklimit = 0
    raise RuntimeError('Please install the python module v8eval either via pip or download it from https://github.com/sony/v8eval')

from . import JavaScriptInterpreter
from .encapsulated import template

# ------------------------------------------------------------------------------- #


class ChallengeInterpreter(JavaScriptInterpreter):

    def __init__(self):
        super(ChallengeInterpreter, self).__init__('v8')

    # ------------------------------------------------------------------------------- #

    def eval(self, body, domain):
        try:
            return v8eval.V8().eval(template(body, domain))
        except (TypeError, v8eval.V8Error):
            RuntimeError('We encountered an error running the V8 Engine.')


# ------------------------------------------------------------------------------- #

ChallengeInterpreter()