Ejemplo n.º 1
0
def WhoIsRequest(request):
    #
    # BACnet コマンド操作用インスタンス取得
    #
    app = request.registry.bacnetd.application
    bacnet = BACnetSimpleClient(app)

    #
    # Timeout の 取得
    #
    timeout = 10
    if 'timeout' in request.GET and request.GET['timeout'].isdigit():
        timeout = int(request.GET['timeout'])

    #
    # WhoIsRequest の 送信
    #
    bacnet.WhoIsRequest()

    #
    # WhoIsRequest を 投げてから最初の IAmRequestを受け取るまで待つ
    #
    try:
        device_id = app.responseQueue.get(timeout=timeout)
        return HTTPOk(json_body={'device_id': device_id})
    except Exception:
        #
        # タイムアウトを通知
        #
        return HTTPRequestTimeout()
Ejemplo n.º 2
0
    def get_forbidden_view(self, request):
        """ Fire a 401 when authentication needed. """

        # FIXME - this doesn't distinguish between unauthenticated and
        # unauthorized.  Should it?
        if request.headers.get('auth_tkt'):
            return HTTPRequestTimeout()

        #print ("Access Forbidden")
        response = HTTPUnauthorized()
        response.headers.extend(self.bap.forget(request))
        return response
Ejemplo n.º 3
0
def locale_negotiator(request):
    try:
        lang = request.params.get('lang')
    except UnicodeDecodeError:  # pragma: no cover
        raise HTTPBadRequest(
            'Could not parse URL and parameters. Request send must be encoded in utf-8.'
        )
    # This might happen if a POST request is aborted before all the data could be transmitted
    except IOError:  # pragma: no cover
        raise HTTPRequestTimeout(
            'Request was aborted. Didn\'t receive full request')

    settings = get_current_registry().settings
    languages = settings['available_languages'].split()
    if lang == 'rm':
        return 'fi'
    elif lang is None or lang not in languages:
        if request.accept_language:
            return request.accept_language.best_match(languages, 'de')
        # the default_locale_name configuration variable
        return get_locale_name(request)
    return lang