[Python-checkins] CVS: python/dist/src/Lib UserList.py,1.10,1.11 UserString.py,1.4,1.5 dis.py,1.25,1.26 rfc822.py,1.47,1.48

Thomas Wouters python-dev@python.org
Thu, 24 Aug 2000 13:14:14 -0700


Update of /cvsroot/python/python/dist/src/Lib
In directory slayer.i.sourceforge.net:/tmp/cvs-serv14095/Lib

Modified Files:
	UserList.py UserString.py dis.py rfc822.py 
Log Message:

Support for augmented assignment in the UserList, UserDict, UserString and
rfc822 (Addresslist) modules. Also a preliminary testcase for augmented
assignment, which should actually be merged with the test_class testcase I
added last week.



Index: UserList.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/UserList.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -r1.10 -r1.11
*** UserList.py	2000/07/16 12:04:30	1.10
--- UserList.py	2000/08/24 20:14:09	1.11
***************
*** 52,58 ****
--- 52,69 ----
          else:
              return self.__class__(list(other) + self.data)
+     def __iadd__(self, other):
+         if isinstance(other, UserList):
+             self.data += other.data
+         elif isinstance(other, type(self.data)):
+             self.data += other
+         else:
+             self.data += list(other)
+         return self
      def __mul__(self, n):
          return self.__class__(self.data*n)
      __rmul__ = __mul__
+     def __imul__(self, n):
+         self.data *= n
+         return self
      def append(self, item): self.data.append(item)
      def insert(self, i, item): self.data.insert(i, item)

Index: UserString.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/UserString.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** UserString.py	2000/08/21 21:47:20	1.4
--- UserString.py	2000/08/24 20:14:09	1.5
***************
*** 51,57 ****
--- 51,68 ----
          else:
              return self.__class__(str(other) + self.data)
+     def __iadd__(self, other):
+         if isinstance(other, UserString):
+             self.data += other.data
+         elif isinstance(other, StringType) or isinstance(other, UnicodeType):
+             self.data += other
+         else
+             self.data += str(other)
+         return self
      def __mul__(self, n):
          return self.__class__(self.data*n)
      __rmul__ = __mul__
+     def __imull__(self, n):
+         self.data += n
+         return self
  
      # the following methods are defined in alphabetical order:

Index: dis.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/dis.py,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -r1.25 -r1.26
*** dis.py	2000/08/24 00:32:09	1.25
--- dis.py	2000/08/24 20:14:09	1.26
***************
*** 183,186 ****
--- 183,191 ----
  def_op('DELETE_SLICE+3', 53)
  
+ def_op('INPLACE_ADD', 55)
+ def_op('INPLACE_SUBTRACT', 56)
+ def_op('INPLACE_MULTIPLY', 57)
+ def_op('INPLACE_DIVIDE', 58)
+ def_op('INPLACE_MODULO', 59)
  def_op('STORE_SUBSCR', 60)
  def_op('DELETE_SUBSCR', 61)
***************
*** 191,194 ****
--- 196,200 ----
  def_op('BINARY_XOR', 65)
  def_op('BINARY_OR', 66)
+ def_op('INPLACE_POWER', 67)
  
  def_op('PRINT_EXPR', 70)
***************
*** 197,201 ****
  def_op('PRINT_ITEM_TO', 73)
  def_op('PRINT_NEWLINE_TO', 74)
! 
  def_op('BREAK_LOOP', 80)
  
--- 203,211 ----
  def_op('PRINT_ITEM_TO', 73)
  def_op('PRINT_NEWLINE_TO', 74)
! def_op('INPLACE_LSHIFT', 75)
! def_op('INPLACE_RSHIFT', 76)
! def_op('INPLACE_AND', 77)
! def_op('INPLACE_XOR', 78)
! def_op('INPLACE_OR', 79)
  def_op('BREAK_LOOP', 80)
  

Index: rfc822.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/rfc822.py,v
retrieving revision 1.47
retrieving revision 1.48
diff -C2 -r1.47 -r1.48
*** rfc822.py	2000/07/16 12:04:30	1.47
--- rfc822.py	2000/08/24 20:14:09	1.48
***************
*** 764,767 ****
--- 764,774 ----
          return newaddr
  
+     def __iadd__(self, other):
+         # Set union, in-place
+         for x in other.addresslist:
+             if not x in self.addresslist:
+                 self.addresslist.append(x)
+         return self
+ 
      def __sub__(self, other):
          # Set difference
***************
*** 771,774 ****
--- 778,788 ----
                  newaddr.addresslist.append(x)
          return newaddr
+ 
+     def __isub__(self, other):
+         # Set difference, in-place
+         for x in other.addresslist:
+             if x in self.addresslist:
+                 self.addresslist.remove(x)
+         return self
  
      def __getitem__(self, index):