home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / Calibre / calibre-0.8.18.msi / file_262 / UserString.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-09-09  |  12.3 KB  |  358 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.7)
  3.  
  4. import sys
  5. import collections
  6. __all__ = [
  7.     'UserString',
  8.     'MutableString']
  9.  
  10. class UserString(collections.Sequence):
  11.     
  12.     def __init__(self, seq):
  13.         if isinstance(seq, basestring):
  14.             self.data = seq
  15.         elif isinstance(seq, UserString):
  16.             self.data = seq.data[:]
  17.         else:
  18.             self.data = str(seq)
  19.  
  20.     
  21.     def __str__(self):
  22.         return str(self.data)
  23.  
  24.     
  25.     def __repr__(self):
  26.         return repr(self.data)
  27.  
  28.     
  29.     def __int__(self):
  30.         return int(self.data)
  31.  
  32.     
  33.     def __long__(self):
  34.         return long(self.data)
  35.  
  36.     
  37.     def __float__(self):
  38.         return float(self.data)
  39.  
  40.     
  41.     def __complex__(self):
  42.         return complex(self.data)
  43.  
  44.     
  45.     def __hash__(self):
  46.         return hash(self.data)
  47.  
  48.     
  49.     def __cmp__(self, string):
  50.         if isinstance(string, UserString):
  51.             return cmp(self.data, string.data)
  52.         return None(self.data, string)
  53.  
  54.     
  55.     def __contains__(self, char):
  56.         return char in self.data
  57.  
  58.     
  59.     def __len__(self):
  60.         return len(self.data)
  61.  
  62.     
  63.     def __getitem__(self, index):
  64.         return self.__class__(self.data[index])
  65.  
  66.     
  67.     def __getslice__(self, start, end):
  68.         start = max(start, 0)
  69.         end = max(end, 0)
  70.         return self.__class__(self.data[start:end])
  71.  
  72.     
  73.     def __add__(self, other):
  74.         if isinstance(other, UserString):
  75.             return self.__class__(self.data + other.data)
  76.         if None(other, basestring):
  77.             return self.__class__(self.data + other)
  78.         return None.__class__(self.data + str(other))
  79.  
  80.     
  81.     def __radd__(self, other):
  82.         if isinstance(other, basestring):
  83.             return self.__class__(other + self.data)
  84.         return None.__class__(str(other) + self.data)
  85.  
  86.     
  87.     def __mul__(self, n):
  88.         return self.__class__(self.data * n)
  89.  
  90.     __rmul__ = __mul__
  91.     
  92.     def __mod__(self, args):
  93.         return self.__class__(self.data % args)
  94.  
  95.     
  96.     def capitalize(self):
  97.         return self.__class__(self.data.capitalize())
  98.  
  99.     
  100.     def center(self, width, *args):
  101.         return self.__class__(self.data.center(width, *args))
  102.  
  103.     
  104.     def count(self, sub, start = 0, end = sys.maxint):
  105.         return self.data.count(sub, start, end)
  106.  
  107.     
  108.     def decode(self, encoding = None, errors = None):
  109.         if encoding:
  110.             if errors:
  111.                 return self.__class__(self.data.decode(encoding, errors))
  112.             return None.__class__(self.data.decode(encoding))
  113.         return self.__class__(self.data.decode())
  114.  
  115.     
  116.     def encode(self, encoding = None, errors = None):
  117.         if encoding:
  118.             if errors:
  119.                 return self.__class__(self.data.encode(encoding, errors))
  120.             return None.__class__(self.data.encode(encoding))
  121.         return self.__class__(self.data.encode())
  122.  
  123.     
  124.     def endswith(self, suffix, start = 0, end = sys.maxint):
  125.         return self.data.endswith(suffix, start, end)
  126.  
  127.     
  128.     def expandtabs(self, tabsize = 8):
  129.         return self.__class__(self.data.expandtabs(tabsize))
  130.  
  131.     
  132.     def find(self, sub, start = 0, end = sys.maxint):
  133.         return self.data.find(sub, start, end)
  134.  
  135.     
  136.     def index(self, sub, start = 0, end = sys.maxint):
  137.         return self.data.index(sub, start, end)
  138.  
  139.     
  140.     def isalpha(self):
  141.         return self.data.isalpha()
  142.  
  143.     
  144.     def isalnum(self):
  145.         return self.data.isalnum()
  146.  
  147.     
  148.     def isdecimal(self):
  149.         return self.data.isdecimal()
  150.  
  151.     
  152.     def isdigit(self):
  153.         return self.data.isdigit()
  154.  
  155.     
  156.     def islower(self):
  157.         return self.data.islower()
  158.  
  159.     
  160.     def isnumeric(self):
  161.         return self.data.isnumeric()
  162.  
  163.     
  164.     def isspace(self):
  165.         return self.data.isspace()
  166.  
  167.     
  168.     def istitle(self):
  169.         return self.data.istitle()
  170.  
  171.     
  172.     def isupper(self):
  173.         return self.data.isupper()
  174.  
  175.     
  176.     def join(self, seq):
  177.         return self.data.join(seq)
  178.  
  179.     
  180.     def ljust(self, width, *args):
  181.         return self.__class__(self.data.ljust(width, *args))
  182.  
  183.     
  184.     def lower(self):
  185.         return self.__class__(self.data.lower())
  186.  
  187.     
  188.     def lstrip(self, chars = None):
  189.         return self.__class__(self.data.lstrip(chars))
  190.  
  191.     
  192.     def partition(self, sep):
  193.         return self.data.partition(sep)
  194.  
  195.     
  196.     def replace(self, old, new, maxsplit = -1):
  197.         return self.__class__(self.data.replace(old, new, maxsplit))
  198.  
  199.     
  200.     def rfind(self, sub, start = 0, end = sys.maxint):
  201.         return self.data.rfind(sub, start, end)
  202.  
  203.     
  204.     def rindex(self, sub, start = 0, end = sys.maxint):
  205.         return self.data.rindex(sub, start, end)
  206.  
  207.     
  208.     def rjust(self, width, *args):
  209.         return self.__class__(self.data.rjust(width, *args))
  210.  
  211.     
  212.     def rpartition(self, sep):
  213.         return self.data.rpartition(sep)
  214.  
  215.     
  216.     def rstrip(self, chars = None):
  217.         return self.__class__(self.data.rstrip(chars))
  218.  
  219.     
  220.     def split(self, sep = None, maxsplit = -1):
  221.         return self.data.split(sep, maxsplit)
  222.  
  223.     
  224.     def rsplit(self, sep = None, maxsplit = -1):
  225.         return self.data.rsplit(sep, maxsplit)
  226.  
  227.     
  228.     def splitlines(self, keepends = 0):
  229.         return self.data.splitlines(keepends)
  230.  
  231.     
  232.     def startswith(self, prefix, start = 0, end = sys.maxint):
  233.         return self.data.startswith(prefix, start, end)
  234.  
  235.     
  236.     def strip(self, chars = None):
  237.         return self.__class__(self.data.strip(chars))
  238.  
  239.     
  240.     def swapcase(self):
  241.         return self.__class__(self.data.swapcase())
  242.  
  243.     
  244.     def title(self):
  245.         return self.__class__(self.data.title())
  246.  
  247.     
  248.     def translate(self, *args):
  249.         return self.__class__(self.data.translate(*args))
  250.  
  251.     
  252.     def upper(self):
  253.         return self.__class__(self.data.upper())
  254.  
  255.     
  256.     def zfill(self, width):
  257.         return self.__class__(self.data.zfill(width))
  258.  
  259.  
  260.  
  261. class MutableString(UserString, collections.MutableSequence):
  262.     
  263.     def __init__(self, string = ''):
  264.         warnpy3k = warnpy3k
  265.         import warnings
  266.         warnpy3k('the class UserString.MutableString has been removed in Python 3.0', stacklevel = 2)
  267.         self.data = string
  268.  
  269.     __hash__ = None
  270.     
  271.     def __setitem__(self, index, sub):
  272.         if isinstance(index, slice):
  273.             if isinstance(sub, UserString):
  274.                 sub = sub.data
  275.             elif not isinstance(sub, basestring):
  276.                 sub = str(sub)
  277.             (start, stop, step) = index.indices(len(self.data))
  278.             if step == -1:
  279.                 start = stop + 1
  280.                 stop = start + 1
  281.                 sub = sub[::-1]
  282.             elif step != 1:
  283.                 raise TypeError, 'invalid step in slicing assignment'
  284.             start = min(start, stop)
  285.             self.data = self.data[:start] + sub + self.data[stop:]
  286.         elif index < 0:
  287.             index += len(self.data)
  288.         if index < 0 or index >= len(self.data):
  289.             raise IndexError
  290.         self.data = self.data[:index] + sub + self.data[index + 1:]
  291.  
  292.     
  293.     def __delitem__(self, index):
  294.         if isinstance(index, slice):
  295.             (start, stop, step) = index.indices(len(self.data))
  296.             if step == -1:
  297.                 start = stop + 1
  298.                 stop = start + 1
  299.             elif step != 1:
  300.                 raise TypeError, 'invalid step in slicing deletion'
  301.             start = min(start, stop)
  302.             self.data = self.data[:start] + self.data[stop:]
  303.         elif index < 0:
  304.             index += len(self.data)
  305.         if index < 0 or index >= len(self.data):
  306.             raise IndexError
  307.         self.data = self.data[:index] + self.data[index + 1:]
  308.  
  309.     
  310.     def __setslice__(self, start, end, sub):
  311.         start = max(start, 0)
  312.         end = max(end, 0)
  313.         if isinstance(sub, UserString):
  314.             self.data = self.data[:start] + sub.data + self.data[end:]
  315.         elif isinstance(sub, basestring):
  316.             self.data = self.data[:start] + sub + self.data[end:]
  317.         else:
  318.             self.data = self.data[:start] + str(sub) + self.data[end:]
  319.  
  320.     
  321.     def __delslice__(self, start, end):
  322.         start = max(start, 0)
  323.         end = max(end, 0)
  324.         self.data = self.data[:start] + self.data[end:]
  325.  
  326.     
  327.     def immutable(self):
  328.         return UserString(self.data)
  329.  
  330.     
  331.     def __iadd__(self, other):
  332.         if isinstance(other, UserString):
  333.             self.data += other.data
  334.         elif isinstance(other, basestring):
  335.             self.data += other
  336.         else:
  337.             self.data += str(other)
  338.         return self
  339.  
  340.     
  341.     def __imul__(self, n):
  342.         self.data *= n
  343.         return self
  344.  
  345.     
  346.     def insert(self, index, value):
  347.         self[index:index] = value
  348.  
  349.  
  350. if __name__ == '__main__':
  351.     import os
  352.     (called_in_dir, called_as) = os.path.split(sys.argv[0])
  353.     (called_as, py) = os.path.splitext(called_as)
  354.     if '-q' in sys.argv:
  355.         from test import test_support
  356.         test_support.verbose = 0
  357.     __import__('test.test_' + called_as.lower())
  358.