Lichen

lib/__builtins__/str.py

227:3a4ba5788f0f
2016-11-23 Paul Boddie Fixed list and tuple initialisation via their initialisers. Introduced generic string representation support for sequences. Removed superfluous tuple native functions. Added element-setting and size-setting native functions for fragments. Added __setitem__ support for sequences. Added initialisation and serialisation tests for lists and tuples.
     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__.iterator import listiterator    23 from __builtins__.operator import _binary_op, _negate    24 import native    25     26 class basestring(object):    27     def __init__(self, data=None):    28         # Note member.    29         self.__data__ = ""    30     31     def __contains__(self, value): pass    32     33     def __getitem__(self, index):    34         # Note usage.    35         IndexError    36     37     def __getslice__(self, start, end=None): pass    38     39     def __iadd__(self, other):    40         "Return a new string for the operation."    41         return _binary_op(self, other, native._str_add)    42     43     __add__ = __radd__ = __iadd__    44     45     def __mul__(self, other): pass    46     def __rmul__(self, other): pass    47     def __mod__(self, other): pass    48     def __rmod__(self, other): pass    49     50     def __lt__(self, other):    51         "Return a new boolean for the comparison."    52         return _binary_op(self, other, native._str_lt)    53     54     def __gt__(self, other):    55         "Return a new boolean for the comparison."    56         return _binary_op(self, other, native._str_gt)    57     58     def __le__(self, other):    59         "Return a new boolean for the comparison."    60         return _negate(self.__gt__(other))    61     62     def __ge__(self, other):    63         "Return a new boolean for the comparison."    64         return _negate(self.__lt__(other))    65     66     def __eq__(self, other):    67         "Return a new boolean for the comparison."    68         return _binary_op(self, other, native._str_eq)    69     70     def __ne__(self, other):    71         "Return a new boolean for the comparison."    72         return _negate(self.__eq__(other))    73     74     def __len__(self):    75         return native._str_len(self)    76     77     def __str__(self):    78         "Return a string representation."    79         return self    80     81     def __repr__(self):    82         "Return a program representation."    83         # NOTE: To be implemented with proper quoting.    84         b = buffer(['"', self, '"'])    85         return str(b)    86     87     def __bool__(self):    88         return native._str_nonempty(self)    89     90     def endswith(self, s): pass    91     def find(self, sub, start=None, end=None): pass    92     def index(self, sub, start=None, end=None): pass    93     def join(self, l): pass    94     def lower(self): pass    95     def lstrip(self, chars=None): pass    96     def replace(self, old, new, count=None): pass    97     def rfind(self, sub, start=None, end=None): pass    98     def rsplit(self, sep=None, maxsplit=None): pass    99     def rstrip(self, chars=None): pass   100     def split(self, sep=None, maxsplit=None): pass   101     def splitlines(self, keepends=False): pass   102     def startswith(self, s): pass   103     def strip(self, chars=None): pass   104     def upper(self): pass   105    106 class string(basestring):   107     pass   108    109 class unicode(basestring):   110     def encode(self, encoding): pass   111    112 def str(obj):   113    114     "Return the string representation of 'obj'."   115    116     return obj.__str__()   117    118 # vim: tabstop=4 expandtab shiftwidth=4