[PATCH] pep8 cleanup for auth.py

From: Aline Manera <alinefm@br.ibm.com> This patch cleans up pep8 style issue in auth.py Signed-off-by: Aline Manera <alinefm@br.ibm.com> --- Makefile.am | 1 + src/kimchi/auth.py | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Makefile.am b/Makefile.am index e57d3b6..7770ba7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -39,6 +39,7 @@ EXTRA_DIST = \ # So it will be checked from now on. PEP8_WHITELIST = \ src/kimchi/asynctask.py \ + src/kimchi/auth.py \ src/kimchi/config.py.in \ src/kimchi/disks.py \ src/kimchi/server.py \ diff --git a/src/kimchi/auth.py b/src/kimchi/auth.py index b665f21..f38d3d6 100644 --- a/src/kimchi/auth.py +++ b/src/kimchi/auth.py @@ -20,7 +20,7 @@ # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import base64 import cherrypy @@ -53,9 +53,9 @@ def authenticate(username, password, service="passwd"): elif qtype == PAM.PAM_PROMPT_ERROR_MSG: cherrypy.log.error_log.error("PAM authenticate prompt error " "message: %s" % query) - resp.append(('', 0)); + resp.append(('', 0)) elif qtype == PAM.PAM_PROMPT_TEXT_INFO: - resp.append(('', 0)); + resp.append(('', 0)) else: return None return resp @@ -72,6 +72,7 @@ def authenticate(username, password, service="passwd"): return True + def from_browser(): # Enable Basic Authentication for REST tools. # Ajax request sent from jQuery in browser will have "X-Requested-With" @@ -79,6 +80,7 @@ def from_browser(): requestHeader = cherrypy.request.headers.get("X-Requested-With", None) return (requestHeader == "XMLHttpRequest") + def check_auth_session(): """ A user is considered authenticated if we have an established session open @@ -99,7 +101,7 @@ def check_auth_httpba(): """ REST API users may authenticate with HTTP Basic Auth. This is not allowed for the UI because web browsers would cache the credentials and make it - impossible for the user to log out without closing their browser completely. + impossible for the user to log out without closing their browser completely """ if from_browser() or not template.can_accept('application/json'): return False -- 1.7.10.4

The patch is ok for me, however , I am curious whether we should use 1 or 2 newline between functions. Here you are using two, but most of the code use 1. Reviewed-by: Rodrigo Trujillo <rodrigo.trujillo@linux.vnet.ibm.com> On 12/20/2013 12:34 PM, Aline Manera wrote:
From: Aline Manera <alinefm@br.ibm.com>
This patch cleans up pep8 style issue in auth.py
Signed-off-by: Aline Manera <alinefm@br.ibm.com> --- Makefile.am | 1 + src/kimchi/auth.py | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/Makefile.am b/Makefile.am index e57d3b6..7770ba7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -39,6 +39,7 @@ EXTRA_DIST = \ # So it will be checked from now on. PEP8_WHITELIST = \ src/kimchi/asynctask.py \ + src/kimchi/auth.py \ src/kimchi/config.py.in \ src/kimchi/disks.py \ src/kimchi/server.py \ diff --git a/src/kimchi/auth.py b/src/kimchi/auth.py index b665f21..f38d3d6 100644 --- a/src/kimchi/auth.py +++ b/src/kimchi/auth.py @@ -20,7 +20,7 @@ # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import base64 import cherrypy @@ -53,9 +53,9 @@ def authenticate(username, password, service="passwd"): elif qtype == PAM.PAM_PROMPT_ERROR_MSG: cherrypy.log.error_log.error("PAM authenticate prompt error " "message: %s" % query) - resp.append(('', 0)); + resp.append(('', 0)) elif qtype == PAM.PAM_PROMPT_TEXT_INFO: - resp.append(('', 0)); + resp.append(('', 0)) else: return None return resp @@ -72,6 +72,7 @@ def authenticate(username, password, service="passwd"):
return True
+ def from_browser(): # Enable Basic Authentication for REST tools. # Ajax request sent from jQuery in browser will have "X-Requested-With" @@ -79,6 +80,7 @@ def from_browser(): requestHeader = cherrypy.request.headers.get("X-Requested-With", None) return (requestHeader == "XMLHttpRequest")
+ def check_auth_session(): """ A user is considered authenticated if we have an established session open @@ -99,7 +101,7 @@ def check_auth_httpba(): """ REST API users may authenticate with HTTP Basic Auth. This is not allowed for the UI because web browsers would cache the credentials and make it - impossible for the user to log out without closing their browser completely. + impossible for the user to log out without closing their browser completely """ if from_browser() or not template.can_accept('application/json'): return False

On 12/20/2013 07:17 PM, Rodrigo Trujillo wrote:
The patch is ok for me, however , I am curious whether we should use 1 or 2 newline between functions. Here you are using two, but most of the code use 1.
Hi Rodrigo, Most of code aren't following pep8 rules because that we have inconsistencies about 1 or 2 newlines. Basically, 2 lines should be used in module composed by functions, and 1 line between functions in a class module.
Reviewed-by: Rodrigo Trujillo <rodrigo.trujillo@linux.vnet.ibm.com>
On 12/20/2013 12:34 PM, Aline Manera wrote:
From: Aline Manera <alinefm@br.ibm.com>
This patch cleans up pep8 style issue in auth.py
Signed-off-by: Aline Manera <alinefm@br.ibm.com> --- Makefile.am | 1 + src/kimchi/auth.py | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/Makefile.am b/Makefile.am index e57d3b6..7770ba7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -39,6 +39,7 @@ EXTRA_DIST = \ # So it will be checked from now on. PEP8_WHITELIST = \ src/kimchi/asynctask.py \ + src/kimchi/auth.py \ src/kimchi/config.py.in \ src/kimchi/disks.py \ src/kimchi/server.py \ diff --git a/src/kimchi/auth.py b/src/kimchi/auth.py index b665f21..f38d3d6 100644 --- a/src/kimchi/auth.py +++ b/src/kimchi/auth.py @@ -20,7 +20,7 @@ # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import base64 import cherrypy @@ -53,9 +53,9 @@ def authenticate(username, password, service="passwd"): elif qtype == PAM.PAM_PROMPT_ERROR_MSG: cherrypy.log.error_log.error("PAM authenticate prompt error " "message: %s" % query) - resp.append(('', 0)); + resp.append(('', 0)) elif qtype == PAM.PAM_PROMPT_TEXT_INFO: - resp.append(('', 0)); + resp.append(('', 0)) else: return None return resp @@ -72,6 +72,7 @@ def authenticate(username, password, service="passwd"):
return True
+ def from_browser(): # Enable Basic Authentication for REST tools. # Ajax request sent from jQuery in browser will have "X-Requested-With" @@ -79,6 +80,7 @@ def from_browser(): requestHeader = cherrypy.request.headers.get("X-Requested-With", None) return (requestHeader == "XMLHttpRequest")
+ def check_auth_session(): """ A user is considered authenticated if we have an established session open @@ -99,7 +101,7 @@ def check_auth_httpba(): """ REST API users may authenticate with HTTP Basic Auth. This is not allowed for the UI because web browsers would cache the credentials and make it - impossible for the user to log out without closing their browser completely. + impossible for the user to log out without closing their browser completely """ if from_browser() or not template.can_accept('application/json'): return False
participants (2)
-
Aline Manera
-
Rodrigo Trujillo