diff options
author | Agustin Zubiaga <aguz@sugarlabs.org> | 2012-07-02 00:48:34 (GMT) |
---|---|---|
committer | Agustin Zubiaga <aguz@sugarlabs.org> | 2012-07-02 00:48:34 (GMT) |
commit | 6c0355d7194c60dcb778bb34a3df5a9bac511f37 (patch) | |
tree | 147cf3f35abac2bcb0966255176d9c67cc261491 /sugarpycha/utils.py | |
parent | 1a133902641f5e81425fe330877f0c2b2c9fc17a (diff) |
Some charts.py fixes (sugarpycha)
Diffstat (limited to 'sugarpycha/utils.py')
-rw-r--r-- | sugarpycha/utils.py | 40 |
1 files changed, 40 insertions, 0 deletions
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 <lorenzo.gil.sanchez@gmail.com> +# 2009-2010 by Yaco S.L. <lgs@yaco.es> +# +# 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 <http://www.gnu.org/licenses/>. + + +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) |