Beispiel #1
0
    def add_script(
        self,
        script_body: StrOrByteString,
        family: int,
        genus: int,
        species: int,
        script_number: int
    ) -> Response:
        """
        Attempt to add a script to the scriptorium.

        The script may be a bytestring or a str, but it must be the bare
        body rather than a script headed by scrp or terminated by endm.

        Doesn't perform any syntax checking. The Response object can be
        checked for signs of errors. How errors are indicated may vary
        per platform.

        :param script_body: the body of the script
        :param family: family classifier
        :param genus: genus classifier
        :param species: species classifier
        :param script_number: script identifier
        :return:
        """
        request_data = coerce_to_bytearray(script_body)
        # prepend the script header
        request_data[:0] = generate_scrp_header(
            family, genus, species, script_number)

        return self.raw_request(request_data)
Beispiel #2
0
    def add_script(self, script_body: StrOrByteString, family: int, genus: int,
                   species: int, script_number: int) -> Response:
        """
        Attempt to add a script to the scriptorium.

        The script may be a bytestring or a str, but it must be the bare
        body rather than a script headed by scrp or terminated by endm.

        Doesn't perform any syntax checking. If there is any content in
        the data or text fields of the response, there was a problem with
        the injection.

        :param script_body: the body of the script
        :param family: family classifier
        :param genus: genus classifier
        :param species: species classifier
        :param script_number: script identifier
        :return:
        """
        data = bytearray()

        data.extend(generate_scrp_header(family, genus, species,
                                         script_number))
        data.extend(coerce_to_bytearray(script_body))
        data.extend(b"\nendm")  # lc2e requires endm on injected scripts

        return self.raw_request(data)
Beispiel #3
0
    def execute_caos(self, request_body: StrOrByteString) -> Response:
        """
        Attempt to run a piece of CAOS
        :param request_body:
        :return:
        """
        request_body = coerce_to_bytearray(request_body)

        return self.raw_request(b"execute\n" + request_body)
Beispiel #4
0
    def execute_caos(self, caos_to_execute: StrOrByteString) -> Response:
        """
        Run a piece of CAOS without storing it, returning the result.

        If it is a string, it will be converted to bytes before execution.

        The response object will contain a string of any output created
        during the request.

        If you want to add scripts to the scriptorium, you are looking for
        add_script instead.

        :param caos_to_execute: valid CAOS to attempt running.
        :return:
        """
        caos_bytearray = coerce_to_bytearray(caos_to_execute)
        return self.raw_request(caos_bytearray)
Beispiel #5
0
def test_coercing_to_bytearray_returns_bytearray_unchanged():
    """The function returns a bytearray unchanged"""
    original = bytearray(b"test data")
    returned = coerce_to_bytearray(original)

    assert returned is original
Beispiel #6
0
    def test_coercing_str_returns_bytearray(self):
        """coerce_to_bytearray returns bytearray if passed string"""
        original = "test value"
        returned = coerce_to_bytearray(original)

        assert isinstance(returned, bytearray)
Beispiel #7
0
    def test_coercing_str_returns_correct_bytearray(self):
        """coerce_to_bytearray returns appropriate str conversion"""
        original = "test value"
        returned = coerce_to_bytearray(original)

        assert returned == bytearray(b"test value")
Beispiel #8
0
    def test_coercing_bytes_returns_a_bytearray(self):
        """coerce_to_bytearray returns bytearray when passed bytes"""
        original = b"test"
        returned = coerce_to_bytearray(original)

        assert isinstance(returned, bytearray)
Beispiel #9
0
    def test_coercing_bytes_returns_equal_bytearray(self):
        """coerce_to_bytearray returns value equal to passed bytes"""
        original = b"test"
        returned = coerce_to_bytearray(original)

        assert returned == original