File: example_embedder.py

package info (click to toggle)
orange3 3.40.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,908 kB
  • sloc: python: 162,745; ansic: 622; makefile: 322; sh: 93; cpp: 77
file content (16 lines) | stat: -rw-r--r-- 636 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from Orange.data import RowInstance
from Orange.misc.server_embedder import ServerEmbedderCommunicator


class ExampleServerEmbedder(ServerEmbedderCommunicator):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.content_type = 'image/jpeg'

    async def _encode_data_instance(self, data_instance: RowInstance) -> bytes:
        """
        This is just an implementation for test purposes. We just return
        a sample bytes which is id encoded to bytes.
        """
        number = int(data_instance.id)
        return number.to_bytes((number.bit_length() + 7) // 8, byteorder='big')