From 8b029f8fa3616e214a9252a849ee1f15325b50fe Mon Sep 17 00:00:00 2001 From: Sam Zaydel Date: Sun, 17 Jun 2012 14:59:14 -0700 Subject: [PATCH] Due to lack of the `format` method in Python 2.5 and older functions were not working correctly. Added a conditional check, based on version of Python. --- kstat/kstat.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/kstat/kstat.py b/kstat/kstat.py index 6fc7b60..f3a6da0 100644 --- a/kstat/kstat.py +++ b/kstat/kstat.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). @@ -7,13 +8,14 @@ # and limitations under the License. # # -# Copyright 2011 Grigale Ltd. All rigths reserved. -# Use is sujbect to license terms. +# Copyright 2011 Grigale Ltd. All rights reserved. +# Use is subject to license terms. # import ctypes as C import libkstat +from sys import version_info class Kstat(): def __init__(self, module='', instance=-1, name=''): @@ -26,11 +28,23 @@ def __del__(self): libkstat.kstat_close(self._ctl) def __str__(self): - s = 'Module: {0}, instance: {1}, name: {2}'.format(self._module, self._inst, self._name) + """ + + """ + if version_info[1] > 5: + s = 'Module: {0}, instance: {1}, name: {2}'.format(self._module, self._inst, self._name) + else: + ## Include this for older versions of python where .format is not a valid method + s = 'Module: %s, instance: %s, name: %s' % (self._module, self._inst, self._name) return s def __repr__(self): - s = 'Kstat("{0}", {1}, "{2}")'.format(self._module, self._inst, self._name) + + if version_info[1] > 5: + s = 'Kstat("{0}", {1}, "{2}")'.format(self._module, self._inst, self._name) + else: + ## Include this for older versions of python where .format is not a valid method + s = 'Kstat("%s", "%s", "%s")' % (self._module, self._inst, self._name) return s def lookup(self):