From e9140bfb08995ee0ad03b46855dd0c6588851c33 Mon Sep 17 00:00:00 2001 From: Ken'ichi Ohmichi Date: Wed, 10 Dec 2014 05:31:16 +0000 Subject: [PATCH] Move safe_body() into specific class safe_body() is used in RestClient class only, so this patch moves safe_body() into the class for the code cleanup. Change-Id: Ice80d5ab19438162ba7a5705fa78c1ab91c1ccd5 --- tempest/common/rest_client.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/tempest/common/rest_client.py b/tempest/common/rest_client.py index 93ebcfc7f0..1df8896004 100644 --- a/tempest/common/rest_client.py +++ b/tempest/common/rest_client.py @@ -38,19 +38,6 @@ MAX_RECURSION_DEPTH = 2 HTTP_SUCCESS = (200, 201, 202, 203, 204, 205, 206, 207) -# convert a structure into a string safely -def safe_body(body, maxlen=4096): - try: - text = six.text_type(body) - except UnicodeDecodeError: - # if this isn't actually text, return marker that - return "" - if len(text) > maxlen: - return text[:maxlen] - else: - return text - - class ResponseBody(dict): """Class that wraps an http response and dict body into a single value. @@ -295,6 +282,18 @@ class RestClient(object): return resp[i] return "" + def _safe_body(self, body, maxlen=4096): + # convert a structure into a string safely + try: + text = six.text_type(body) + except UnicodeDecodeError: + # if this isn't actually text, return marker that + return "" + if len(text) > maxlen: + return text[:maxlen] + else: + return text + def _log_request_start(self, method, req_url, req_headers=None, req_body=None): if req_headers is None: @@ -325,9 +324,9 @@ class RestClient(object): req_url, secs, str(req_headers), - safe_body(req_body), + self._safe_body(req_body), str(resp), - safe_body(resp_body)), + self._safe_body(resp_body)), extra=extra) def _log_request(self, method, req_url, resp,