Lichen

lib/__builtins__/str.py

254:165f86113bb0
2016-11-27 Paul Boddie Return class names for string representations, making instance representations more verbose.
     1 #!/usr/bin/env python     2      3 """     4 String objects.     5      6 Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk>     7      8 This program is free software; you can redistribute it and/or modify it under     9 the terms of the GNU General Public License as published by the Free Software    10 Foundation; either version 3 of the License, or (at your option) any later    11 version.    12     13 This program is distributed in the hope that it will be useful, but WITHOUT    14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS    15 FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more    16 details.    17     18 You should have received a copy of the GNU General Public License along with    19 this program.  If not, see <http://www.gnu.org/licenses/>.    20 """    21     22 from __builtins__.identity import isclass    23 from __builtins__.iterator import listiterator    24 from __builtins__.operator import _binary_op, _negate    25 import native    26     27 class basestring(object):    28     def __init__(self, data=None):    29         # Note member.    30         self.__data__ = ""    31     32     def __contains__(self, value): pass    33     34     def __getitem__(self, index):    35         # Note usage.    36         IndexError    37     38     def __getslice__(self, start, end=None): pass    39     40     def __iadd__(self, other):    41         "Return a new string for the operation."    42         return _binary_op(self, other, native._str_add)    43     44     __add__ = __radd__ = __iadd__    45     46     def __mul__(self, other): pass    47     def __rmul__(self, other): pass    48     def __mod__(self, other): pass    49     def __rmod__(self, other): pass    50     51     def __lt__(self, other):    52         "Return a new boolean for the comparison."    53         return _binary_op(self, other, native._str_lt)    54     55     def __gt__(self, other):    56         "Return a new boolean for the comparison."    57         return _binary_op(self, other, native._str_gt)    58     59     def __le__(self, other):    60         "Return a new boolean for the comparison."    61         return _negate(self.__gt__(other))    62     63     def __ge__(self, other):    64         "Return a new boolean for the comparison."    65         return _negate(self.__lt__(other))    66     67     def __eq__(self, other):    68         "Return a new boolean for the comparison."    69         return _binary_op(self, other, native._str_eq)    70     71     def __ne__(self, other):    72         "Return a new boolean for the comparison."    73         return _negate(self.__eq__(other))    74     75     def __len__(self):    76         return native._str_len(self)    77     78     def __str__(self):    79         "Return a string representation."    80         return self    81     82     def __repr__(self):    83         "Return a program representation."    84         # NOTE: To be implemented with proper quoting.    85         b = buffer(['"', self, '"'])    86         return str(b)    87     88     def __bool__(self):    89         return native._str_nonempty(self)    90     91     def endswith(self, s): pass    92     def find(self, sub, start=None, end=None): pass    93     def index(self, sub, start=None, end=None): pass    94     def join(self, l): pass    95     def lower(self): pass    96     def lstrip(self, chars=None): pass    97     def replace(self, old, new, count=None): pass    98     def rfind(self, sub, start=None, end=None): pass    99     def rsplit(self, sep=None, maxsplit=None): pass   100     def rstrip(self, chars=None): pass   101     def split(self, sep=None, maxsplit=None): pass   102     def splitlines(self, keepends=False): pass   103     def startswith(self, s): pass   104     def strip(self, chars=None): pass   105     def upper(self): pass   106    107 class string(basestring):   108     pass   109    110 class unicode(basestring):   111     def encode(self, encoding): pass   112    113 def str(obj):   114    115     "Return the string representation of 'obj'."   116    117     # Classes do not provide __str__ directly.   118    119     if isclass(obj):   120         return obj.__name__   121    122     # Class attributes of instances provide __str__.   123    124     else:   125         return obj.__str__()   126    127 # vim: tabstop=4 expandtab shiftwidth=4