ulif.openoffice.pyunoserver – The PyUNO server

A server that waits for requests for conversion of documents.

Important code fragments are from regular Python documentation.

class ulif.openoffice.pyunoserver.ThreadedTCPRequestHandler(request, client_address, server)

A handler for the ThreadedTCPServer.

It implements the protocol, the PyUNO server actually works with.

handle()

The protocol:

The request:

REQUEST          ::=  CONVERT_CMD | FIND_CMD | TEST_CMD
CONVERT_CMD      ::=  CMD PATH
CMD              ::=  "CONVERT_PDF<NL>" | "CONVERT_HTML<NL>"
FIND_CMD         ::=  "FIND<NL>"
TEST_CMD         ::=  "TEST<NL>"
PATH             ::=  "PATH=" PATH_TO_DOCUMENT
PATH_TO_DOCUMENT ::=  <file-path>

Response:

RESPONSE       ::=  OK_RESULT | ERR_RESULT | VERSION_RESULT
OK_RESULT      ::=  "OK " STATUS PATH_TO_RESULT
ERR_RESULT     ::=  "ERR " STATUS ERR_MSG
STATUS         ::=  <integer-number>
PATH_TO_RESULT ::=  <file-path>
ERR_MSG        ::=  <textblock>
VERSION_RESULT ::=  "OK 0 " <server-version>

with:

<NL>
NewLine character
<file-path>
a valid path to a local file
<integer-number>
an integer number
<server-version>
a string like 0.1dev
<text>
a string, possibly containing several lines.

Examples:

Request:

CONVERT_PDF
PATH=/home/foo/bar.odt

Response:

OK 0 /tmp/asdqwe.pdf

Request:

CONVERT_HTML
PATH=/home/foo/bar.docx

Response:

OK 0 /tmp/sdfwqer

Request:

FIND
PATH=/home/foo/bar.docx
REGEX=regex

Response:

OK 0 [{'page':1},{'page':33}]

Request:

TEST

Response:

ERR -1 Could not reach OpenOffice.org server on port 2002
Please make sure to start oooctl.
prepareCacheResults(src_path, result_path, extension)

Move results to a secure destination.

If the result is HTML we try to untar the result file.

prepareCaching(src_path, result_path, extension)

Before we can feed the cachemanager, we tar HTML results.

prepareSource(src_path, extension)

We move the source to a secure location.

This way we prevent results from being polluted by already existing files not belonging to the result.

class ulif.openoffice.pyunoserver.ThreadedTCPServer(server_address, RequestHandlerClass)

An asynchronous TCP server.

cache_manager

The cache manager instance used by any server isntance.

do_stop

Marker to check while serving for stop-requests.

logger

A logger instance.

server_bind()

Bind server to socket.

We use SO_REUSEADDR to ensure, that we can reuse the port on restarts immediately. Otherwise we would be blocked by TIME_WAIT for several seconds or minutes.

ulif.openoffice.pyunoserver.run(host, port, python_binary, uno_lib_dir, cache_dir, logger)

Start an instance of ThreadedTCPServer.

Previous topic

ulif.openoffice.pyunoctl – A Server to communicate with OO.o

Next topic

ulif.openoffice.restserver – A RESTful PyUNO server

This Page