linotp.lib.reply module

create responses

linotp.lib.reply.create_html(data, width=0, alt=None, list_id='challenge_data')

_create_html - create the qr image data embeded in html tag

Parameters
  • data (string) – input data that will be munched into the qrcode

  • width (int) – image width in pixel

Returns

<img/> taged data

Return type

string

linotp.lib.reply.create_img(data, width=0, alt=None, img_id='challenge_qrcode')

_create_img - create the qr image data

Parameters
  • data (string) – input data that will be munched into the qrcode

  • width (int) – image width in pixel

Returns

<img/> taged data

Return type

string

linotp.lib.reply.create_img_src(data)

_create_img - create the qr image data

Parameters
  • data (string) – input data that will be munched into the qrcode

  • width (int) – image width in pixel

Returns

<img/> taged data

Return type

string

linotp.lib.reply.create_png(data, alt=None)
linotp.lib.reply.json2xml(json_obj, line_padding='')
linotp.lib.reply.sendCSVIterator(obj, headers=True)
linotp.lib.reply.sendCSVResult(response, obj, flat_lines=False, filename='linotp-tokendata.csv')

returns a CSV document of the input data (like in /admin/show)

Parameters
  • response – The pylons response object

  • obj (JSON object) – The data, that gets serialized as CSV

  • flat_lines

    If True the object only contains a list of the

    dict { ‘cell’: …, ‘id’: … }

    as in all the flexigrid functions.

‘type flat_lines: boolean

linotp.lib.reply.sendError(_response, exception, id=1, context=None)

sendError - return a HTML or JSON error result document

Default LinOTP behaviour in case of error is to try to always send a ‘200 OK’ HTTP response that contains an error code and description in the body (JSON data). Some clients prefer a different HTTP status code, because it allows response filtering without parsing the body. If the client sends ‘httperror=<INT>’ in the request this will be honoured (in case of error) and that HTTP status will be set. If ‘httperror’ is set without a value (or an invalid value) status 500 will be used. If you would like this to happen only in some error conditions but not all you can set ‘linotp.errors’ in the LinOTP Config. Then the HTTP status defined by ‘httperror’ will ONLY be sent when the error that occurs in LinOTP matches one of the errors defined in ‘linotp.errors’. In other cases ‘200 OK’ with error code and description in the body will be returned. If ‘linotp.errors’ is unset all errors will cause responses with HTTP status ‘httperror’. For example:

Setup 1:
  • The client sends httperror=777 in the request

  • linotp.errors=233,567

Case 1.1: An exception is raised in LinOTP that has errId 233.
  • LinOTP will return a response with HTTP status 777.

Case 1.2: An exception is raised with errId 555
  • LinOTP will return a response with HTTP status 200.

Setup 2:
  • The client sends httperror (empty) in the request

  • linotp.errors=233,567

Case 2.1: An exception is raised in LinOTP that has errId 233.
  • LinOTP will return a response with HTTP status 500.

Case 2.2: An exception is raised with errId 555
  • LinOTP will return a response with HTTP status 200.

Setup 3:
  • The client sends httperror (empty) in the request

  • linotp.errors is not set

Case 3.1: An exception is raised in LinOTP that has errId 233.
  • LinOTP will return a response with HTTP status 500.

Case 3.2: An exception is raised with errId 555
  • LinOTP will return a response with HTTP status 500.

Setup 4:
  • NO httperror in request

  • linotp.errors=233,567 (or is unset, does not matter)

Case 4.1: An exception is raised in LinOTP that has errId 233.
  • LinOTP will return a response with HTTP status 200.

Case 4.2: An exception is raised with errId 555
  • LinOTP will return a response with HTTP status 200.

remark for ‘context’ parameter:

the ‘context’ is especially required to catch errors from the _before_ methods. The return of a _before_ must be of type response and must have the attribute response._exception set, to stop further processing, which otherwise will have ugly results!!

Parameters
  • response (response object) – the pylon response object

  • exception (exception) – should be a linotp exception (s. linotp.lib.error.py)

  • id (int) – id value, for future versions

  • context (string) – default is None or ‘before’

Returns

json rendered sting result

Return type

string

linotp.lib.reply.sendQRImageResult(response, data, param=None, id=1, typ='html')
method

sendQRImageResult

arguments

response - the pylon response object param - the paramters of the request id - html - print qrcode wrapped by html or not

linotp.lib.reply.sendResult(response, obj, id=1, opt=None, status=True)

sendResult - return an json result document

Parameters
  • response (response object) – the pylons response object

  • obj (dict or list or string/unicode) – simple result object like dict, sting or list

  • id (int) – id value, for future versions

  • opt (None or simple type like dict, list or string/unicode) – optional parameter, which allows to provide more detail

Returns

json rendered sting result

Return type

string

linotp.lib.reply.sendResultIterator(obj, id=1, opt=None, rp=None, page=None, request_context_copy=None)
sendResultIterator - return an json result document in a streamed mode

which requires a request context to be avaliable

Parameters
  • obj – iterator of generator object like dict, string or list

  • id – id value, for future versions

  • opt – optional parameter, which allows to provide more detail

  • rp – results per page

  • page – number of page

Returns

generator of response data (yield)

linotp.lib.reply.sendXMLError(_response, exception, id=1)
linotp.lib.reply.sendXMLResult(_response, obj, id=1, opt=None)

send the result as an xml format