summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Th?nault <sylvain.thenault@logilab.fr>2012-03-15 13:39:55 +0100
committerSylvain Th?nault <sylvain.thenault@logilab.fr>2012-03-15 13:39:55 +0100
commit78b7f822cd7b92069c1f9de9480cf0bb483befca (patch)
treee7566c5b59c05dea3a2166b4e24e483664441d3b
parentcd55c7901ff556b0593c129536e258554d5165d0 (diff)
parent27e22487d92741e52c12e346123830a08f05243c (diff)
downloadlogilab-common-78b7f822cd7b92069c1f9de9480cf0bb483befca.tar.gz
backport stable
-rw-r--r--ChangeLog6
-rw-r--r--README2
-rw-r--r--__pkginfo__.py7
-rwxr-xr-xbin/pytest5
-rw-r--r--daemon.py2
-rw-r--r--modutils.py4
-rw-r--r--setup.py2
-rw-r--r--test/unittest_textutils.py11
-rw-r--r--testlib.py2
-rw-r--r--textutils.py10
10 files changed, 36 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index 61de712..8b42399 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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)
diff --git a/README b/README
index ea480b2..9eb6b92 100644
--- a/README
+++ b/README
@@ -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",
+ ]
diff --git a/bin/pytest b/bin/pytest
index 0ad0ecb..88f74ae 100755
--- a/bin/pytest
+++ b/bin/pytest
@@ -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()
diff --git a/daemon.py b/daemon.py
index c8342a8..66a6960 100644
--- a/daemon.py
+++ b/daemon.py
@@ -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:
diff --git a/setup.py b/setup.py
index da44fe0..5cca4c8 100644
--- a/setup.py
+++ b/setup.py
@@ -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):
diff --git a/testlib.py b/testlib.py
index ca452ca..a35ad98 100644
--- a/testlib.py
+++ b/testlib.py
@@ -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: