Module: check_mk
Branch: master
Commit: 72bc1cdcfe10c0d93ebc5ba320a80d14cbf8445e
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=72bc1cdcfe10c0…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Thu Jan 3 15:02:37 2019 +0100
Replaced cmk.gui.http_status by standard facilities.
Change-Id: I93346240a56dbf4d5126a8effc4f74f3bf62aa09
---
cmk/gui/exceptions.py | 16 ++++-----
cmk/gui/http.py | 8 ++---
cmk/gui/http_status.py | 93 --------------------------------------------------
web/app/index.wsgi | 6 ++--
4 files changed, 15 insertions(+), 108 deletions(-)
diff --git a/cmk/gui/exceptions.py b/cmk/gui/exceptions.py
index d2c4ed3..b2e81ad 100644
--- a/cmk/gui/exceptions.py
+++ b/cmk/gui/exceptions.py
@@ -24,9 +24,11 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
+import httplib
from typing import Optional, Text # pylint: disable=unused-import
-import cmk.gui.http_status
+from werkzeug.http import HTTP_STATUS_CODES
+
from cmk.gui.i18n import _
from cmk.utils.exceptions import MKGeneralException, MKException, MKTimeout
@@ -44,21 +46,19 @@ class FinalizeRequest(Exception):
# TODO: Drop this default and make exit code explicit for all call sites
def __init__(self, code=None):
# type: (Optional[int]) -> None
- self.status = code or cmk.gui.http_status.HTTP_OK # type: int
- super(FinalizeRequest,
self).__init__(cmk.gui.http_status.status_with_reason(self.status))
+ self.status = code or httplib.OK
+ super(FinalizeRequest,
+ self).__init__("%d %s" % (self.status,
HTTP_STATUS_CODES[self.status]))
class HTTPRedirect(FinalizeRequest):
"""Is used to end the HTTP request processing from deeper code levels
and making the client request another page after receiving the
response."""
- def __init__(self, url, code=cmk.gui.http_status.HTTP_MOVED_TEMPORARILY):
+ def __init__(self, url, code=httplib.FOUND):
# type: (str, int) -> None
super(HTTPRedirect, self).__init__(code)
- if code not in [
- cmk.gui.http_status.HTTP_MOVED_PERMANENTLY,
- cmk.gui.http_status.HTTP_MOVED_TEMPORARILY
- ]:
+ if code not in [httplib.MOVED_PERMANENTLY, httplib.FOUND]:
raise Exception("Invalid status code: %d" % code)
self.url = url #type: str
diff --git a/cmk/gui/http.py b/cmk/gui/http.py
index 99334bc..d8a19f4 100644
--- a/cmk/gui/http.py
+++ b/cmk/gui/http.py
@@ -25,15 +25,15 @@
# Boston, MA 02110-1301 USA.
"""Wrapper layer between WSGI and the GUI application
code"""
-import re
import cgi
+import httplib
+import re
import six
import werkzeug.http
import cmk.gui.log as log
from cmk.gui.i18n import _
-import cmk.gui.http_status
from cmk.gui.exceptions import HTTPRedirect
@@ -260,7 +260,7 @@ class Response(object):
super(Response, self).__init__()
self._logger = log.logger.getChild("http.Response")
self._secure = secure
- self._status_code = cmk.gui.http_status.HTTP_OK
+ self._status_code = httplib.OK
self._output = []
self._headers_out = []
@@ -319,7 +319,7 @@ class Response(object):
@property
def http_status(self):
"""Provides the HTTP response status header (code incl.
text)"""
- return cmk.gui.http_status.status_with_reason(self._status_code)
+ return "%d %s" % (self._status_code,
werkzeug.http.HTTP_STATUS_CODES[self._status_code])
@property
def headers(self):
diff --git a/cmk/gui/http_status.py b/cmk/gui/http_status.py
deleted file mode 100644
index 75d4316..0000000
--- a/cmk/gui/http_status.py
+++ /dev/null
@@ -1,93 +0,0 @@
-#!/usr/bin/env python
-# -*- encoding: utf-8; py-indent-offset: 4 -*-
-# +------------------------------------------------------------------+
-# | ____ _ _ __ __ _ __ |
-# | / ___| |__ ___ ___| | __ | \/ | |/ / |
-# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
-# | | |___| | | | __/ (__| < | | | | . \ |
-# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
-# | |
-# | Copyright Mathias Kettner 2014 mk(a)mathias-kettner.de |
-# +------------------------------------------------------------------+
-#
-# This file is part of Check_MK.
-# The official homepage is at
http://mathias-kettner.de/check_mk.
-#
-# check_mk is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by
-# the Free Software Foundation in version 2. check_mk is distributed
-# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
-# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
-# PARTICULAR PURPOSE. See the GNU General Public License for more de-
-# tails. You should have received a copy of the GNU General Public
-# License along with GNU Make; see the file COPYING. If not, write
-# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
-# Boston, MA 02110-1301 USA.
-
-# TODO: Use definitions from httplib (Python 3: http.HTTPStatus)
-HTTP_CONTINUE = 100
-HTTP_SWITCHING_PROTOCOLS = 101
-HTTP_PROCESSING = 102
-HTTP_OK = 200
-HTTP_CREATED = 201
-HTTP_ACCEPTED = 202
-HTTP_NON_AUTHORITATIVE = 203
-HTTP_NO_CONTENT = 204
-HTTP_RESET_CONTENT = 205
-HTTP_PARTIAL_CONTENT = 206
-HTTP_MULTI_STATUS = 207
-HTTP_MULTIPLE_CHOICES = 300
-HTTP_MOVED_PERMANENTLY = 301
-HTTP_MOVED_TEMPORARILY = 302
-HTTP_SEE_OTHER = 303
-HTTP_NOT_MODIFIED = 304
-HTTP_USE_PROXY = 305
-HTTP_TEMPORARY_REDIRECT = 307
-HTTP_BAD_REQUEST = 400
-HTTP_UNAUTHORIZED = 401
-HTTP_PAYMENT_REQUIRED = 402
-HTTP_FORBIDDEN = 403
-HTTP_NOT_FOUND = 404
-HTTP_METHOD_NOT_ALLOWED = 405
-HTTP_NOT_ACCEPTABLE = 406
-HTTP_PROXY_AUTHENTICATION_REQUIRED = 407
-HTTP_REQUEST_TIME_OUT = 408
-HTTP_CONFLICT = 409
-HTTP_GONE = 410
-HTTP_LENGTH_REQUIRED = 411
-HTTP_PRECONDITION_FAILED = 412
-HTTP_REQUEST_ENTITY_TOO_LARGE = 413
-HTTP_REQUEST_URI_TOO_LARGE = 414
-HTTP_UNSUPPORTED_MEDIA_TYPE = 415
-HTTP_RANGE_NOT_SATISFIABLE = 416
-HTTP_EXPECTATION_FAILED = 417
-HTTP_UNPROCESSABLE_ENTITY = 422
-HTTP_LOCKED = 423
-HTTP_FAILED_DEPENDENCY = 424
-HTTP_UPGRADE_REQUIRED = 426
-HTTP_INTERNAL_SERVER_ERROR = 500
-HTTP_NOT_IMPLEMENTED = 501
-HTTP_BAD_GATEWAY = 502
-HTTP_SERVICE_UNAVAILABLE = 503
-HTTP_GATEWAY_TIME_OUT = 504
-HTTP_VERSION_NOT_SUPPORTED = 505
-HTTP_VARIANT_ALSO_VARIES = 506
-HTTP_INSUFFICIENT_STORAGE = 507
-HTTP_NOT_EXTENDED = 510
-
-
-def status_with_reason(code):
- # type: (int) -> str
- if code == HTTP_OK:
- return '200 OK'
- if code == HTTP_MOVED_TEMPORARILY:
- return '301 Moved Permanently'
- if code == HTTP_MOVED_PERMANENTLY:
- return '302 Found'
- if code == HTTP_NOT_MODIFIED:
- return '304 Not Modified'
- if code == HTTP_INTERNAL_SERVER_ERROR:
- return '500 Internal Server Error'
- if code == HTTP_NOT_FOUND:
- return '404 Not Found'
- return str(code)
diff --git a/web/app/index.wsgi b/web/app/index.wsgi
index 6f62693..6ae66a0 100644
--- a/web/app/index.wsgi
+++ b/web/app/index.wsgi
@@ -24,6 +24,7 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
+import httplib
import os
import traceback
@@ -43,7 +44,6 @@ import cmk.gui.login as login
import cmk.gui.log as log
import cmk.gui.htmllib
import cmk.gui.http
-import cmk.gui.http_status
import cmk.gui.globals
from cmk.gui.log import logger
from cmk.gui.i18n import _
@@ -130,9 +130,9 @@ class Application(object):
# Some exception need to set a specific HTTP status code
if ty == MKUnauthenticatedException:
- html.response.set_status_code(cmk.gui.http_status.HTTP_UNAUTHORIZED)
+ html.response.set_status_code(httplib.UNAUTHORIZED)
elif ty == livestatus.MKLivestatusException:
- html.response.set_status_code(cmk.gui.http_status.HTTP_BAD_GATEWAY)
+ html.response.set_status_code(httplib.BAD_GATEWAY)
if ty in [MKConfigError, MKGeneralException]:
logger.error(_("%s: %s") % (plain_title, e))