diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | README | 2 | ||||
-rw-r--r-- | __pkginfo__.py | 7 | ||||
-rwxr-xr-x | bin/pytest | 5 | ||||
-rw-r--r-- | daemon.py | 2 | ||||
-rw-r--r-- | modutils.py | 4 | ||||
-rw-r--r-- | setup.py | 2 | ||||
-rw-r--r-- | test/unittest_textutils.py | 11 | ||||
-rw-r--r-- | testlib.py | 2 | ||||
-rw-r--r-- | textutils.py | 10 |
10 files changed, 36 insertions, 15 deletions
@@ -1,11 +1,15 @@ ChangeLog for logilab.common ============================ - -- + -- #default * new `registry` module containing a backport of CubicWeb selectable objects registry (closes #84654) * testlib: DocTestCase fix builtins pollution after doctest execution. * shellutil: add argument to ``ProgressBar.update`` to tune cursor progression (closes #88981) + -- #stable + * texutils: apply_units raise ValueError if string isn'nt valid (closes #88808) + * pytest: do not enable extra warning other than DeprecationWarning. + 2011-10-28 -- 0.57.1 * daemon: change $HOME after dropping privileges (closes #81297) @@ -6,7 +6,7 @@ What's this ? This package contains some modules used by differents Logilab's projects. -It is released under the GNU Public License. +It is released under the GNU Lesser General Public License. There is no documentation available yet but the source code should be clean and well documented. diff --git a/__pkginfo__.py b/__pkginfo__.py index 83a43cf..81f5ffc 100644 --- a/__pkginfo__.py +++ b/__pkginfo__.py @@ -1,4 +1,4 @@ -# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. +# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr # # This file is part of logilab-common. @@ -43,3 +43,8 @@ include_dirs = [join('test', 'data')] if sys.version_info < (2, 7): install_requires = ['unittest2 >= 0.5.1'] +classifiers = ["Topic :: Utilities", + "Programming Language :: Python", + "Programming Language :: Python :: 2", + "Programming Language :: Python :: 3", + ] @@ -1,4 +1,7 @@ -#!/usr/bin/python -uWdefault +#!/usr/bin/python -u + +import warnings +warnings.simplefilter('default', DeprecationWarning) from logilab.common.pytest import run run() @@ -46,7 +46,7 @@ def setugid(user): raise OSError(err, os.strerror(err), 'initgroups') os.setgid(passwd.pw_gid) os.setuid(passwd.pw_uid) - os.putenv('HOME', passwd.pw_dir) + os.environ['HOME'] = passwd.pw_dir def daemonize(pidfile=None, uid=None, umask=077): diff --git a/modutils.py b/modutils.py index ce0c297..95c400a 100644 --- a/modutils.py +++ b/modutils.py @@ -92,7 +92,7 @@ class LazyObject(object): def load_module_from_name(dotted_name, path=None, use_sys=1): - """Load a Python module from it's name. + """Load a Python module from its name. :type dotted_name: str :param dotted_name: python name of a module or package @@ -117,7 +117,7 @@ def load_module_from_name(dotted_name, path=None, use_sys=1): def load_module_from_modpath(parts, path=None, use_sys=1): - """Load a python module from it's splitted name. + """Load a python module from its splitted name. :type parts: list(str) or tuple(str) :param parts: @@ -60,6 +60,7 @@ include_dirs = getattr(__pkginfo__, 'include_dirs', []) ext_modules = getattr(__pkginfo__, 'ext_modules', None) install_requires = getattr(__pkginfo__, 'install_requires', None) dependency_links = getattr(__pkginfo__, 'dependency_links', []) +classifiers = getattr(__pkginfo__, 'classifiers', []) STD_BLACKLIST = ('CVS', '.svn', '.hg', 'debian', 'dist', 'build') @@ -155,6 +156,7 @@ def install(**kwargs): license = license, description = description, long_description = long_description, + classifiers = classifiers, author = author, author_email = author_email, url = web, diff --git a/test/unittest_textutils.py b/test/unittest_textutils.py index e8b46b1..db18d0d 100644 --- a/test/unittest_textutils.py +++ b/test/unittest_textutils.py @@ -184,6 +184,12 @@ class UnitsTC(TestCase): result = tu.apply_units('1 000 KB', self.units) self.assertEqual(result, 1000 * self.units['kb']) + def test_unit_wrong_input(self): + self.assertRaises(ValueError, tu.apply_units, '', self.units) + self.assertRaises(ValueError, tu.apply_units, 'wrong input', self.units) + self.assertRaises(ValueError, tu.apply_units, 'wrong13 input', self.units) + self.assertRaises(ValueError, tu.apply_units, 'wrong input42', self.units) + RGX = re.compile('abcd') class PrettyMatchTC(TestCase): @@ -246,9 +252,8 @@ class UnormalizeTC(TestCase): 'ab _ cd') def test_unormalize_backward_compat(self): - self.assertRaises(ValueError, tu.unormalize, u"\u8000", - ignorenonascii=False) - self.assertEqual(tu.unormalize(u"\u8000", ignorenonascii=True), u'') + self.assertRaises(ValueError, tu.unormalize, u"\u8000") + self.assertEqual(tu.unormalize(u"\u8000", substitute=''), u'') class ModuleDocTest(DocTest): @@ -62,7 +62,7 @@ if not getattr(unittest_legacy, "__package__", None): import unittest2 as unittest from unittest2 import SkipTest except ImportError: - sys.exit("You have to install python-unittest2 to use this module") + raise ImportError("You have to install python-unittest2 to use %s" % __name__) else: import unittest from unittest import SkipTest diff --git a/textutils.py b/textutils.py index bdeed41..f55c004 100644 --- a/textutils.py +++ b/textutils.py @@ -313,6 +313,8 @@ _BLANK_RE = re.compile(_BLANK_URE) __VALUE_URE = r'-?(([0-9]+\.[0-9]*)|((0x?)?[0-9]+))' __UNITS_URE = r'[a-zA-Z]+' _VALUE_RE = re.compile(r'(?P<value>%s)(?P<unit>%s)?'%(__VALUE_URE, __UNITS_URE)) +_VALIDATION_RE = re.compile(r'^((%s)(%s))*(%s)?$' % (__VALUE_URE, __UNITS_URE, + __VALUE_URE)) BYTE_UNITS = { "b": 1, @@ -352,12 +354,12 @@ def apply_units(string, units, inter=None, final=float, blank_reg=_BLANK_RE, """ if inter is None: inter = final - string = _BLANK_RE.sub('', string) + fstring = _BLANK_RE.sub('', string) + if not (fstring and _VALIDATION_RE.match(fstring)): + raise ValueError("Invalid unit string: %r." % string) values = [] - for match in value_reg.finditer(string): + for match in value_reg.finditer(fstring): dic = match.groupdict() - #import sys - #print >> sys.stderr, dic lit, unit = dic["value"], dic.get("unit") value = inter(lit) if unit is not None: |