1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/lib/operator/augmented.py Tue Aug 30 21:55:58 2016 +0200
1.3 @@ -0,0 +1,69 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +"""
1.7 +Operator support.
1.8 +
1.9 +Copyright (C) 2010, 2013, 2015 Paul Boddie <paul@boddie.org.uk>
1.10 +
1.11 +This program is free software; you can redistribute it and/or modify it under
1.12 +the terms of the GNU General Public License as published by the Free Software
1.13 +Foundation; either version 3 of the License, or (at your option) any later
1.14 +version.
1.15 +
1.16 +This program is distributed in the hope that it will be useful, but WITHOUT
1.17 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.18 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.19 +details.
1.20 +
1.21 +You should have received a copy of the GNU General Public License along with
1.22 +this program. If not, see <http://www.gnu.org/licenses/>.
1.23 +"""
1.24 +
1.25 +from operator.core import augassign
1.26 +
1.27 +# These functions defer method lookup by wrapping the attribute access in
1.28 +# lambda functions. Thus, the appropriate methods are defined locally, but no
1.29 +# attempt to obtain them is made until the generic function is called.
1.30 +
1.31 +# NOTE: The compiler should make it possible for the following functions to call
1.32 +# NOTE: the generic operator implementations with no additional call overhead.
1.33 +
1.34 +# Augmented assignment functions.
1.35 +
1.36 +def iadd(a, b):
1.37 + return augassign(a, b, lambda a: a.__iadd__, lambda a: a.__add__, lambda b: b.__radd__)
1.38 +
1.39 +def iand_(a, b):
1.40 + return augassign(a, b, lambda a: a.__iand__, lambda a: a.__and__, lambda b: b.__rand__)
1.41 +
1.42 +def idiv(a, b):
1.43 + return augassign(a, b, lambda a: a.__idiv__, lambda a: a.__div__, lambda b: b.__rdiv__)
1.44 +
1.45 +def ifloordiv(a, b):
1.46 + return augassign(a, b, lambda a: a.__ifloordiv__, lambda a: a.__floordiv__, lambda b: b.__rfloordiv__)
1.47 +
1.48 +def ilshift(a, b):
1.49 + return augassign(a, b, lambda a: a.__ilshift__, lambda a: a.__lshift__, lambda b: b.__rlshift__)
1.50 +
1.51 +def imod(a, b):
1.52 + return augassign(a, b, lambda a: a.__imod__, lambda a: a.__mod__, lambda b: b.__rmod__)
1.53 +
1.54 +def imul(a, b):
1.55 + return augassign(a, b, lambda a: a.__imul__, lambda a: a.__mul__, lambda b: b.__rmul__)
1.56 +
1.57 +def ior_(a, b):
1.58 + return augassign(a, b, lambda a: a.__ior__, lambda a: a.__or__, lambda b: b.__ror__)
1.59 +
1.60 +def ipow(a, b):
1.61 + return augassign(a, b, lambda a: a.__ipow__, lambda a: a.__pow__, lambda b: b.__rpow__)
1.62 +
1.63 +def irshift(a, b):
1.64 + return augassign(a, b, lambda a: a.__irshift__, lambda a: a.__rshift__, lambda b: b.__rrshift__)
1.65 +
1.66 +def isub(a, b):
1.67 + return augassign(a, b, lambda a: a.__isub__, lambda a: a.__sub__, lambda b: b.__rsub__)
1.68 +
1.69 +def ixor(a, b):
1.70 + return augassign(a, b, lambda a: a.__ixor__, lambda a: a.__xor__, lambda b: b.__rxor__)
1.71 +
1.72 +# vim: tabstop=4 expandtab shiftwidth=4