def __add__(self, other): b = broadcast(self, other) arr = b.iters[1].base outitem = self.itemsize + arr.itemsize result = chararray(b.shape, outitem, self.dtype is unicode_) res = result.flat for k, val in enumerate(b): res[k] = (val[0] + val[1]) return result
def __radd__(self, other): b = broadcast(other, self) outitem = b.iters[0].base.itemsize + \ b.iters[1].base.itemsize result = chararray(b.shape, outitem, self.dtype is unicode_) res = result.flat for k, val in enumerate(b): res[k] = (val[0] + val[1]) return result
def __mod__(self, other): b = broadcast(self, other) res = [None]*b.size maxsize = -1 for k,val in enumerate(b): newval = val[0] % val[1] maxsize = max(len(newval), maxsize) res[k] = newval newarr = chararray(b.shape, maxsize, self.dtype is unicode_) newarr[:] = res return newarr
def __mul__(self, other): b = broadcast(self, other) arr = b.iters[1].base if not issubclass(arr.dtype.type, integer): raise ValueError, "Can only multiply by integers" outitem = b.iters[0].base.itemsize * arr.max() result = chararray(b.shape, outitem, self.dtype is unicode_) res = result.flat for k, val in enumerate(b): res[k] = val[0]*val[1] return result
def __rmul__(self, other): b = broadcast(self, other) arr = b.iters[1].base if not issubclass(arr.dtype.type, integer): raise ValueError, "Can only multiply by integers" outitem = b.iters[0].base.itemsize * arr.max() result = chararray(b.shape, outitem, self.dtype is unicode_) res = result.flat for k, val in enumerate(b): res[k] = val[0]*val[1] return result
def split(self, sep=None, maxsplit=None): return self._typedmethod('split', broadcast(self, sep, maxsplit), object)
def join(self, seq): return self._generalmethod('join', broadcast(self, seq))
def replace(self, old, new, count=None): return self._generalmethod('replace', broadcast(self, old, new, count))
def encode(self,encoding=None,errors=None): return self._generalmethod('encode', broadcast(self, encoding, errors))
def expandtabs(self, tabsize=None): return self._generalmethod('endswith', broadcast(self, tabsize))
def center(self, width): return self._generalmethod('center', broadcast(self, width))
def rindex(self, sub, start=None, end=None): return self._typedmethod('rindex', broadcast(self, sub, start, end), int)
def lstrip(self, chars): return self._generalmethod('lstrip', broadcast(self, chars))
def find(self, sub, start=None, end=None): return self._typedmethod('find', broadcast(self, sub, start, end), int)
def endswith(self, suffix, start=None, end=None): return self._typedmethod('endswith', broadcast(self, suffix, start, end), bool)
def startswith(self, prefix, start=None, end=None): return self._typedmethod('startswith', broadcast(self, prefix, start, end), bool)
def splitlines(self, keepends=None): return self._typedmethod('splitlines', broadcast(self, keepends), object)
def rjust(self, width): return self._generalmethod('rjust', broadcast(self, width))
def count(self, sub, start=None, end=None): return self._typedmethod('count', broadcast(self, sub, start, end), int)
def strip(self, chars=None): return self._generalmethod('strip', broadcast(self, chars))
def translate(self, table, deletechars=None): if self.dtype is unicode_: return self._generalmethod('translate', broadcast(self, table)) else: return self._generalmethod('translate', broadcast(self, table, deletechars))
def zfill(self, width): return self._generalmethod('zfill', broadcast(self, width))
def rjust(self, width, fillchar=' '): return self._generalmethod('rjust', broadcast(self, width, fillchar))
def center(self, width, fillchar=' '): return self._generalmethod('center', broadcast(self, width, fillchar))