def stage_pywbem_result(self, ret, exc):
        """
        Log result return or exception parameter. This method provides varied
        type of formatting based on the detail_level parameter and the
        data in ret.
        """
        def format_result(ret, max_len):
            """ format ret as repr while clipping it to max_len if
                max_len is not None.
            """
            # Format the 'summary' and 'paths' detail_levels
            if self.api_detail_level == 'summary':  # pylint: disable=R1705
                if isinstance(ret, list):
                    if ret:
                        ret_type = type(ret[0]).__name__ if ret else ""
                        return _format("list of {0}; count={1}",
                                       ret_type, len(ret))
                    return "Empty"

                ret_type = type(ret).__name__
                if hasattr(ret, 'classname'):
                    name = ret.classname
                elif hasattr(ret, 'name'):
                    name = ret.name
                else:
                    name = ""
                return _format("{0} {1}", ret_type, name)

            elif self.api_detail_level == 'paths':
                if isinstance(ret, list):
                    if ret:
                        if hasattr(ret[0], 'path'):
                            result_fmt = ', '.join(
                                [_format("{0!A}", str(p.path)) for p in ret])
                        else:
                            result_fmt = _format("{0!A}", ret)
                    else:
                        result_fmt = ''
                else:
                    if hasattr(ret, 'path'):
                        result_fmt = _format("{0!A}", str(ret.path))
                    else:
                        result_fmt = _format("{0!A}", ret)

            else:
                result_fmt = _format("{0!A}", ret)

            if max_len and (len(result_fmt) > max_len):
                result_fmt = result_fmt[:max_len] + '...'
            return result_fmt

        if self.enabled and self.api_detail_level is not None and \
                self.apilogger.isEnabledFor(logging.DEBUG):
            if exc:  # format exception
                # exceptions are always either all or reduced length
                result = format_result(
                    _format("{0}({1})", exc.__class__.__name__, exc),
                    self.api_maxlen)

                return_type = 'Exception'

            else:    # format result
                # test if type is tuple (subclass of tuple but not type tuple)
                # pylint: disable=unidiomatic-typecheck
                qrc = ""
                # format open/pull response
                if isinstance(ret, tuple) and \
                        type(ret) is not tuple:  # pylint: disable=C0123
                    try:    # test if field instances or paths
                        rtn_data = ret.instances
                        data_str = 'instances'
                    except AttributeError:
                        rtn_data = ret.paths
                        data_str = 'paths'

                    try:    # test for query_result_class
                        qrc = _format(
                            ", query_result_class={0}",
                            ret.query_result_class)
                    except AttributeError:
                        pass

                    result = _format(
                        "{0}(context={1}, eos={2}{3}, {4}={5})",
                        type(ret).__name__, ret.context, ret.eos, qrc,
                        data_str, format_result(rtn_data, self.api_maxlen))

                # format enumerate response except not open/pull
                elif isinstance(ret, list):
                    try:    # test for query_result_class
                        qrc = _format(
                            ", query_result_class={0}",
                            ret.query_result_class)
                    except AttributeError:
                        pass
                    ret_fmtd = format_result(ret, self.api_maxlen)
                    result = _format("{0}{1}", qrc, ret_fmtd)

                # format single return object
                else:
                    result = format_result(ret, self.api_maxlen)

                return_type = 'Return'

            self.apilogger.debug('%s:%s %s(%s)', return_type, self._conn_id,
                                 self._pywbem_method, result)
def stage_pywbem_result ( self , ret , exc ) : def format_result ( ret , max_len ) : if self . api_detail_level == 'summary' : if isinstance ( ret , list ) : if ret : ret_type = type ( ret [ 0 ] ) . __name__ if ret else "" return _format ( "list of {0}; count={1}" , ret_type , len ( ret ) ) return "Empty" ret_type = type ( ret ) . __name__ if hasattr ( ret , 'classname' ) : name = ret . classname elif hasattr ( ret , 'name' ) : name = ret . name else : name = "" return _format ( "{0} {1}" , ret_type , name ) elif self . api_detail_level == 'paths' : if isinstance ( ret , list ) : if ret : if hasattr ( ret [ 0 ] , 'path' ) : result_fmt = ', ' . join ( [ _format ( "{0!A}" , str ( p . path ) ) for p in ret ] ) else : result_fmt = _format ( "{0!A}" , ret ) else : result_fmt = '' else : if hasattr ( ret , 'path' ) : result_fmt = _format ( "{0!A}" , str ( ret . path ) ) else : result_fmt = _format ( "{0!A}" , ret ) else : result_fmt = _format ( "{0!A}" , ret ) if max_len and ( len ( result_fmt ) > max_len ) : result_fmt = result_fmt [ : max_len ] + '...' return result_fmt if self . enabled and self . api_detail_level is not None and self . apilogger . isEnabledFor ( logging . DEBUG ) : if exc : result = format_result ( _format ( "{0}({1})" , exc . __class__ . __name__ , exc ) , self . api_maxlen ) return_type = 'Exception' else : qrc = "" if isinstance ( ret , tuple ) and type ( ret ) is not tuple : try : rtn_data = ret . instances data_str = 'instances' except AttributeError : rtn_data = ret . paths data_str = 'paths' try : qrc = _format ( ", query_result_class={0}" , ret . query_result_class ) except AttributeError : pass result = _format ( "{0}(context={1}, eos={2}{3}, {4}={5})" , type ( ret ) . __name__ , ret . context , ret . eos , qrc , data_str , format_result ( rtn_data , self . api_maxlen ) ) elif isinstance ( ret , list ) : try : qrc = _format ( ", query_result_class={0}" , ret . query_result_class ) except AttributeError : pass ret_fmtd = format_result ( ret , self . api_maxlen ) result = _format ( "{0}{1}" , qrc , ret_fmtd ) else : result = format_result ( ret , self . api_maxlen ) return_type = 'Return' self . apilogger . debug ( '%s:%s %s(%s)' , return_type , self . _conn_id , self . _pywbem_method , result )
Log result return or exception parameter. This method provides varied
        type of formatting based on the detail_level parameter and the
        data in ret.