From 6c0355d7194c60dcb778bb34a3df5a9bac511f37 Mon Sep 17 00:00:00 2001 From: Agustin Zubiaga Date: Mon, 02 Jul 2012 00:48:34 +0000 Subject: Some charts.py fixes (sugarpycha) --- (limited to 'sugarpycha/utils.py') diff --git a/sugarpycha/utils.py b/sugarpycha/utils.py new file mode 100644 index 0000000..9e1b692 --- /dev/null +++ b/sugarpycha/utils.py @@ -0,0 +1,40 @@ +# Copyright(c) 2007-2010 by Lorenzo Gil Sanchez +# 2009-2010 by Yaco S.L. +# +# This file is part of PyCha. +# +# PyCha is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# PyCha is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with PyCha. If not, see . + + +def clamp(minValue, maxValue, value): + """Make sure value is between minValue and maxValue""" + if value < minValue: + return minValue + if value > maxValue: + return maxValue + return value + + +def safe_unicode(obj, encoding=None): + """Return a unicode value from the argument""" + if isinstance(obj, unicode): + return obj + elif isinstance(obj, str): + if encoding is None: + return unicode(obj) + else: + return unicode(obj, encoding) + else: + # it may be an int or a float + return unicode(obj) -- cgit v0.9.1