/usr/lib/python2.7/dist-packages/citeproc/string.py is in python-citeproc 0.3.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | from __future__ import (absolute_import, division, print_function,
unicode_literals)
from citeproc.py2compat import *
from functools import wraps
def discard_empty_other(method):
"""Decorator for addition operator methods that returns the object itself if
`other` is the empty string."""
@wraps(method)
def wrapper(obj, other):
if other == '':
return obj
else:
return method(obj, other)
return wrapper
class String(str):
@discard_empty_other
def __radd__(self, other):
return MixedString([other]).__add__(self)
@discard_empty_other
def __add__(self, other):
return MixedString([self]).__add__(other)
def __iadd__(self, other):
return self.__add__(other)
def replace(self, *args, **kwargs):
return self.__class__(super(String, self).replace(*args, **kwargs))
def rstrip(self, *args, **kwargs):
return self.__class__(super(String, self).rstrip(*args, **kwargs))
def lower(self):
return self.__class__(super(String, self).lower())
def upper(self):
return self.__class__(super(String, self).upper())
def soft_lower(self):
return self.lower()
def soft_upper(self):
return self.upper()
def capitalize_first(self):
return self.__class__(self[0].upper() + self[1:])
def words(self):
for word in self.split():
yield self.__class__(word)
class MixedString(list):
@discard_empty_other
def __add__(self, other):
super_obj = super(MixedString, self)
try:
return self.__class__(super_obj.__add__(other))
except TypeError:
return self.__class__(super_obj.__add__(MixedString([other])))
@discard_empty_other
def __radd__(self, other):
return self.__class__([other]).__add__(self)
def __iadd__(self, other):
return self.__add__(other)
def __str__(self):
return ''.join(map(str, self))
def __getitem__(self, index):
return str(self)[index]
def replace(self, *args):
return self.__class__([string.replace(*args) for string in self])
def translate(self, table):
return self.__class__([string.translate(table) for string in self])
def lower(self):
return self.__class__([string.lower() for string in self])
def upper(self):
return self.__class__([string.upper() for string in self])
def title(self):
return self.__class__([string.title() for string in self])
def capitalize_first(self):
self_iter = iter(self)
output = [next(self_iter).capitalize_first()]
output += [string for string in self_iter]
return self.__class__(output)
def isupper(self):
return all(string.isupper() for string in self)
def split(self, *args, **kwargs):
return str(self).split(*args, **kwargs)
def rstrip(self, *args, **kwargs):
rev_iter = reversed(self)
output = [next(rev_iter).rstrip(*args, **kwargs)]
output += [string for string in rev_iter]
return self.__class__(reversed(output))
def words(self):
for string in self:
for word in string.words():
yield word
if PY2:
MixedString.__unicode__ = MixedString.__str__
del MixedString.__str__
class NoCase(String):
def __repr__(self):
return '{}({})'.format(self.__class__.__name__, str(self))
def soft_lower(self):
return self
def soft_upper(self):
return self
def capitalize_first(self):
return self
|