Public
Snippet $206 authored by Cédric Le Ninivin

onlyoffice-converter.py

Edited
onlyoffice-converter.py
from xmlrpclib import ServerProxy, Transport, SafeTransport
import ssl
from base64 import b64encode, b64decode

def cloudooopublic_convert(self, data, source_format, destination_format, zip=False, refresh=False, conversion_kw=None):
  # with certificate check
  self.Base_prepareCorsResponse(RESPONSE=self.REQUEST.RESPONSE)
  proxy = ServerProxy("https://cloudooo.erp5.net/", allow_none=True)
  return b64decode(proxy.convertFile(b64encode(data.read()), source_format, destination_format, zip, refresh, conversion_kw or {}))

def cloudooopublic_convert_nocheck(self, data, source_format, destination_format, zip=False, refresh=False, conversion_kw=None):
  # without certificate check
  self.Base_prepareCorsResponse(RESPONSE=self.REQUEST.RESPONSE)
  ssl_context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
  ssl_context.verify_mode = ssl.CERT_NONE
  proxy = ServerProxy("http://cloudooo.erp5.net/", allow_none=True, transport=SafeTransport(context=ssl_context))  # note that we use "http" instead of "https"
  return b64decode(proxy.convertFile(b64encode(data.read()), source_format, destination_format, zip, refresh, conversion_kw or {}))