1 # This file is part of Indico.
2 # Copyright (C) 2002 - 2015 European Organization for Nuclear Research (CERN).
4 # Indico is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3 of the
7 # License, or (at your option) any later version.
9 # Indico is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with Indico; if not, see <http://www.gnu.org/licenses/>.
18 Some "monkey patches" for old Python versions
21 from __future__
import absolute_import
25 import operator
as ops
28 VERSION_RE
= re
.compile(r
'(>=|>|<|<=)?(\d)(?:\.(\d))?')
32 def _version_data(ver
):
33 m
= VERSION_RE
.match(ver
)
36 return m
[0], int(m
[1]), int(m
[2])
38 raise Exception("Wrong version specification: '{0}'".format(ver
))
41 def _version_matches(my_ver
, op
, rule_ver
):
49 }[op
](my_ver
, rule_ver
)
54 version_data
= _version_data(ver
)
55 PATCHES
.append((version_data
, f
))
60 PATCHES
.append((None, f
))
64 def redis_pipeline_nonzero():
66 py-redis added a __len__ method to its BasePipeline class recently.
67 For our magic to work we need redis objects to be always considered
68 nonzero - no matter if it's a redis client or a redis pipeline.
75 redis
.client
.BasePipeline
.__nonzero
__ = lambda self
: True
79 for version_data
, func
in PATCHES
:
80 if version_data
is not None:
81 op
, maj
, minor
= version_data
82 if not _version_matches((maj
, minor
), op
, sys
.version_info
[:2]):