Exemplo n.º 1
0
    def generateEncoded(self) -> str:
        """
        Generated base 64 encoded report.
        Basically calls generate and encodes resuslt as base64
        """
        data = self.generate()
        if self.encoded:
            return encoders.encodeAsStr(data, 'base64').replace('\n', '')

        return typing.cast(str, data)
Exemplo n.º 2
0
    def encrypt(self, value: typing.Union[str, bytes]) -> str:
        if isinstance(value, str):
            value = value.encode('utf-8')

        return encoders.encodeAsStr(
            self._rsa.public_key().encrypt(
                value,
                padding.OAEP(mgf=padding.MGF1(algorithm=hashes.SHA256()),
                             algorithm=hashes.SHA256(),
                             label=None)), 'base64')
Exemplo n.º 3
0
def errorView(request: 'HttpRequest', errorCode: int) -> HttpResponseRedirect:
    errorCode = int(errorCode)
    code = (errorCode >> 8) & 0xFF
    errorCode = errorCode & 0xFF

    errStr = errorString(errorCode)
    if code != 0:
        errStr += ' (code {0:04X})'.format(code)

    errStr = encoders.encodeAsStr(str(errStr), 'base64').replace('\n', '')

    logger.debug('Redirection to error view with %s', errStr)
    return HttpResponseRedirect(reverse('page.error', kwargs={'err': errStr}))
Exemplo n.º 4
0
    def __insert(self, instance: DelayedTask, delay: int, tag: str) -> None:
        now = getSqlDatetime()
        exec_time = now + timedelta(seconds=delay)
        cls = instance.__class__
        instanceDump = encoders.encodeAsStr(pickle.dumps(instance), 'base64')
        typeName = str(cls.__module__ + '.' + cls.__name__)

        logger.debug('Inserting delayed task %s with %s bytes (%s)', typeName,
                     len(instanceDump), exec_time)

        DBDelayedTask.objects.create(
            type=typeName,
            instance=instanceDump,  # @UndefinedVariable
            insert_date=now,
            execution_delay=delay,
            execution_time=exec_time,
            tag=tag)
Exemplo n.º 5
0
    def saveData(self,
                 skey: typing.Union[str, bytes],
                 data: typing.Any,
                 attr1: typing.Optional[str] = None) -> None:
        # If None is to be saved, remove
        if not data:
            self.remove(skey)
            return

        key = self.__getKey(skey)
        if isinstance(data, str):
            data = data.encode('utf-8')
        data = encoders.encodeAsStr(data, 'base64')
        attr1 = attr1 or ''
        try:
            DBStorage.objects.create(owner=self._owner,
                                     key=key,
                                     data=data,
                                     attr1=attr1)  # @UndefinedVariable
        except Exception:
            with transaction.atomic():
                DBStorage.objects.filter(key=key).select_for_update().update(
                    owner=self._owner, data=data,
                    attr1=attr1)  # @UndefinedVariable
Exemplo n.º 6
0
 def icon64(cls: typing.Type['Module']) -> typing.Union[str]:
     return encoders.encodeAsStr(cls.icon(), 'base64')