URL: https://github.com/freeipa/freeipa/pull/1146
Author: slaykovsky
Title: #1146: rpcserver.py code cleaning
Action: opened
PR body:
"""
Hi!
I was going through `rpcserver` module code and just found out it's very hard
to read. So I've made some style changes and string formatting related changes.
For my point of view, it's now more easy to read.
Any comments welcomed.
Thanks.
"""
To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/1146/head:pr1146
git checkout pr1146
From 470646a36de94d07042d377d4ccebca3fff88185 Mon Sep 17 00:00:00 2001
From: Aleksei Slaikovskii
Date: Wed, 11 Oct 2017 15:40:30 +0200
Subject: [PATCH] rpcserver.py code cleaning
Fixes code formatting, changes old formatting for strings.
---
ipaserver/rpcserver.py | 581 -
1 file changed, 381 insertions(+), 200 deletions(-)
diff --git a/ipaserver/rpcserver.py b/ipaserver/rpcserver.py
index 5cbacf406d..ecc3d94fcf 100644
--- a/ipaserver/rpcserver.py
+++ b/ipaserver/rpcserver.py
@@ -1,7 +1,7 @@
# Authors:
# Jason Gerard DeRose
#
-# Copyright (C) 2008-2016 Red Hat
+# Copyright (C) 2008-2017 Red Hat
# see file 'COPYING' for use and warranty information
#
# This program is free software; you can redistribute it and/or modify
@@ -45,17 +45,21 @@
from ipalib.frontend import Local
from ipalib.install.kinit import kinit_armor, kinit_password
from ipalib.backend import Executioner
-from ipalib.errors import (PublicError, InternalError, JSONError,
-CCacheError, RefererError, InvalidSessionPassword, NotFound, ACIError,
-ExecutionError, PasswordExpired, KrbPrincipalExpired, UserLocked)
+from ipalib.errors import (
+PublicError, InternalError, JSONError,
+CCacheError, RefererError, InvalidSessionPassword,
+NotFound, ACIError, ExecutionError,
+PasswordExpired, KrbPrincipalExpired, UserLocked
+)
from ipalib.request import context, destroy_context
-from ipalib.rpc import (xml_dumps, xml_loads,
-json_encode_binary, json_decode_binary)
+from ipalib.rpc import (
+xml_dumps, xml_loads,
+json_encode_binary, json_decode_binary
+)
from ipapython.dn import DN
from ipaserver.plugins.ldap2 import ldap2
from ipalib.backend import Backend
-from ipalib.krb_utils import (
-get_credentials_if_valid)
+from ipalib.krb_utils import get_credentials_if_valid
from ipapython import kerberos
from ipapython import ipautil
from ipaplatform.paths import paths
@@ -80,7 +84,7 @@
Not Found
-The requested URL %(url)s was not found on this server.
+The requested URL {url} was not found on this server.
"""
@@ -92,7 +96,7 @@
Bad Request
-%(message)s
+{message}
"""
@@ -104,7 +108,7 @@
Internal Server Error
-%(message)s
+{message}
"""
@@ -116,7 +120,7 @@
Invalid Authentication
-%(message)s
+{message}
"""
@@ -126,13 +130,14 @@
200 Success
-%(title)s
+{title}
-%(message)s
+{message}
"""
+
class HTTP_Status(plugable.Plugin):
def not_found(self, environ, start_response, url, message):
"""
@@ -142,8 +147,10 @@ def not_found(self, environ, start_response, url, message):
response_headers = [('Content-Type', 'text/html; charset=utf-8')]
logger.info('%s: URL="%s", %s', status, url, message)
+
start_response(status, response_headers)
-output = _not_found_template % dict(url=escape(url))
+
+output = _not_found_template.format(url=escape(url))
return [output.encode('utf-8')]
def bad_request(self, environ, start_response, message):
@@ -156,7 +163,8 @@ def bad_request(self, environ, start_response, message):
logger.info('%s: %s', status, message)
start_response(status, response_headers)
-output = _bad_request_template % dict(message=escape(message))
+
+output = _bad_request_template.format(message=escape(message))
return [output.encode('utf-8')]
def internal_error(self, environ, start_response, message):
@@ -169,7 +177,8 @@ def internal_error(self, environ, start_response, message):
logger.error('%s: %s', status, message)
start_response(status, response_headers)
-output = _internal_error_template % dict(message=escape(message))
+
+output = _internal_error_template.format(message=escape(message))
return [output.encode('utf-8')]
def unauthorized(self, environ, start_response, message, reason):
@@ -178,15 +187,18 @@ def unauthorized(self, environ, start_response, message, reason):
"""
status = '401 Unauthorized'
response_headers = [('Content-Type', 'text/html; charset=utf-8')]
+
if reason:
response_headers.append(('X-IPA-Rejection-Reason', reason))
logger.info('%s: %s', status, message)
start_response(status, response_headers)
-output = _unauthorized_template %