Changeset 574adc7 in sasview for src/sas/sascalc/data_util/odict.py


Ignore:
Timestamp:
Sep 22, 2017 4:01:32 PM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
34d7b35
Parents:
9706d88
Message:

convert sascalc to python 2/3 syntax

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/data_util/odict.py

    rb699768 r574adc7  
    3939    """ 
    4040    A class of dictionary that keeps the insertion order of keys. 
    41      
     41 
    4242    All appropriate methods return keys, items, or values in an ordered way. 
    43      
     43 
    4444    All normal dictionary methods are available. Update and comparison is 
    4545    restricted to other OrderedDict objects. 
    46      
     46 
    4747    Various sequence methods are available, including the ability to explicitly 
    4848    mutate the key ordering. 
    49      
     49 
    5050    __contains__ tests: 
    51      
     51 
    5252    >>> d = OrderedDict(((1, 3),)) 
    5353    >>> 1 in d 
     
    5555    >>> 4 in d 
    5656    0 
    57      
     57 
    5858    __getitem__ tests: 
    59      
     59 
    6060    >>> OrderedDict(((1, 3), (3, 2), (2, 1)))[2] 
    6161    1 
     
    6363    Traceback (most recent call last): 
    6464    KeyError: 4 
    65      
     65 
    6666    __len__ tests: 
    67      
     67 
    6868    >>> len(OrderedDict()) 
    6969    0 
    7070    >>> len(OrderedDict(((1, 3), (3, 2), (2, 1)))) 
    7171    3 
    72      
     72 
    7373    get tests: 
    74      
     74 
    7575    >>> d = OrderedDict(((1, 3), (3, 2), (2, 1))) 
    7676    >>> d.get(1) 
     
    8282    >>> d 
    8383    OrderedDict([(1, 3), (3, 2), (2, 1)]) 
    84      
     84 
    8585    has_key tests: 
    86      
     86 
    8787    >>> d = OrderedDict(((1, 3), (3, 2), (2, 1))) 
    8888    >>> d.has_key(1) 
     
    9696        Create a new ordered dictionary. Cannot init from a normal dict, 
    9797        nor from kwargs, since items order is undefined in those cases. 
    98          
     98 
    9999        If the ``strict`` keyword argument is ``True`` (``False`` is the 
    100100        default) then when doing slice assignment - the ``OrderedDict`` you are 
    101101        assigning from *must not* contain any keys in the remaining dict. 
    102          
     102 
    103103        >>> OrderedDict() 
    104104        OrderedDict([]) 
     
    283283        """ 
    284284        Used for __repr__ and __str__ 
    285          
     285 
    286286        >>> r1 = repr(OrderedDict((('a', 'b'), ('c', 'd'), ('e', 'f')))) 
    287287        >>> r1 
     
    321321        >>> d 
    322322        OrderedDict([(0, 1), (1, 2), (5, 6), (7, 8), (3, 4)]) 
    323          
     323 
    324324        >>> a = OrderedDict(((0, 1), (1, 2), (2, 3)), strict=True) 
    325325        >>> a[3] = 4 
     
    345345        >>> a 
    346346        OrderedDict([(3, 4), (2, 3), (1, 2), (0, 1)]) 
    347          
     347 
    348348        >>> d = OrderedDict([(0, 1), (1, 2), (2, 3), (3, 4)]) 
    349349        >>> d[:1] = 3 
    350350        Traceback (most recent call last): 
    351351        TypeError: slice assignment requires an OrderedDict 
    352          
     352 
    353353        >>> d = OrderedDict([(0, 1), (1, 2), (2, 3), (3, 4)]) 
    354354        >>> d[:1] = OrderedDict([(9, 8)]) 
     
    444444        """ 
    445445        Implemented so that access to ``sequence`` raises a warning. 
    446          
     446 
    447447        >>> d = OrderedDict() 
    448448        >>> d.sequence 
     
    463463        """ 
    464464        To allow deepcopy to work with OrderedDict. 
    465          
     465 
    466466        >>> from copy import deepcopy 
    467467        >>> a = OrderedDict([(1, 1), (2, 2), (3, 3)]) 
     
    490490    def items(self): 
    491491        """ 
    492         ``items`` returns a list of tuples representing all the  
     492        ``items`` returns a list of tuples representing all the 
    493493        ``(key, value)`` pairs in the dictionary. 
    494          
     494 
    495495        >>> d = OrderedDict(((1, 3), (3, 2), (2, 1))) 
    496496        >>> d.items() 
     
    505505        """ 
    506506        Return a list of keys in the ``OrderedDict``. 
    507          
     507 
    508508        >>> d = OrderedDict(((1, 3), (3, 2), (2, 1))) 
    509509        >>> d.keys() 
     
    515515        """ 
    516516        Return a list of all the values in the OrderedDict. 
    517          
     517 
    518518        Optionally you can pass in a list of values, which will replace the 
    519519        current list. The value list must be the same len as the OrderedDict. 
    520          
     520 
    521521        >>> d = OrderedDict(((1, 3), (3, 2), (2, 1))) 
    522522        >>> d.values() 
     
    596596        """ 
    597597        No dict.pop in Python 2.2, gotta reimplement it 
    598          
     598 
    599599        >>> d = OrderedDict(((1, 3), (3, 2), (2, 1))) 
    600600        >>> d.pop(3) 
     
    612612        """ 
    613613        if len(args) > 1: 
    614             raise TypeError, ('pop expected at most 2 arguments, got %s' % 
     614            raise TypeError('pop expected at most 2 arguments, got %s' % 
    615615                (len(args) + 1)) 
    616616        if key in self: 
     
    628628        Delete and return an item specified by index, not a random one as in 
    629629        dict. The index is -1 by default (the last item). 
    630          
     630 
    631631        >>> d = OrderedDict(((1, 3), (3, 2), (2, 1))) 
    632632        >>> d.popitem() 
     
    674674        """ 
    675675        Update from another OrderedDict or sequence of (key, value) pairs 
    676          
     676 
    677677        >>> d = OrderedDict(((1, 0), (0, 1))) 
    678678        >>> d.update(OrderedDict(((1, 3), (3, 2), (2, 1)))) 
     
    706706        """ 
    707707        Rename the key for a given value, without modifying sequence order. 
    708          
     708 
    709709        For the case where new_key already exists this raise an exception, 
    710710        since if new_key exists, it is ambiguous as to what happens to the 
    711711        associated values, and the position of new_key in the sequence. 
    712          
     712 
    713713        >>> od = OrderedDict() 
    714714        >>> od['a'] = 1 
     
    732732            raise ValueError("New key already exists: %r" % new_key) 
    733733        # rename sequence entry 
    734         value = self[old_key]  
     734        value = self[old_key] 
    735735        old_idx = self._sequence.index(old_key) 
    736736        self._sequence[old_idx] = new_key 
     
    742742        """ 
    743743        This method allows you to set the items in the dict. 
    744          
     744 
    745745        It takes a list of tuples - of the same sort returned by the ``items`` 
    746746        method. 
    747          
     747 
    748748        >>> d = OrderedDict() 
    749749        >>> d.setitems(((3, 1), (2, 3), (1, 2))) 
     
    760760        replace the current set. This must contain the same set of keys, but 
    761761        need not be in the same order. 
    762          
     762 
    763763        If you pass in new keys that don't match, a ``KeyError`` will be 
    764764        raised. 
    765          
     765 
    766766        >>> d = OrderedDict(((1, 3), (3, 2), (2, 1))) 
    767767        >>> d.keys() 
     
    791791        You can pass in a list of values, which will replace the 
    792792        current list. The value list must be the same len as the OrderedDict. 
    793          
     793 
    794794        (Or a ``ValueError`` is raised.) 
    795          
     795 
    796796        >>> d = OrderedDict(((1, 3), (3, 2), (2, 1))) 
    797797        >>> d.setvalues((1, 2, 3)) 
     
    813813        """ 
    814814        Return the position of the specified key in the OrderedDict. 
    815          
     815 
    816816        >>> d = OrderedDict(((1, 3), (3, 2), (2, 1))) 
    817817        >>> d.index(3) 
     
    826826        """ 
    827827        Takes ``index``, ``key``, and ``value`` as arguments. 
    828          
     828 
    829829        Sets ``key`` to ``value``, so that ``key`` is at position ``index`` in 
    830830        the OrderedDict. 
    831          
     831 
    832832        >>> d = OrderedDict(((1, 3), (3, 2), (2, 1))) 
    833833        >>> d.insert(0, 4, 0) 
     
    850850        """ 
    851851        Reverse the order of the OrderedDict. 
    852          
     852 
    853853        >>> d = OrderedDict(((1, 3), (3, 2), (2, 1))) 
    854854        >>> d.reverse() 
     
    861861        """ 
    862862        Sort the key order in the OrderedDict. 
    863          
     863 
    864864        This method takes the same arguments as the ``list.sort`` method on 
    865865        your version of Python. 
    866          
     866 
    867867        >>> d = OrderedDict(((4, 1), (2, 2), (3, 3), (1, 4))) 
    868868        >>> d.sort() 
     
    876876    """ 
    877877    Custom object for accessing the keys of an OrderedDict. 
    878      
     878 
    879879    Can be called like the normal ``OrderedDict.keys`` method, but also 
    880880    supports indexing and sequence methods. 
     
    897897        You cannot assign to keys, but you can do slice assignment to re-order 
    898898        them. 
    899          
     899 
    900900        You can only do slice assignment if the new set of keys is a reordering 
    901901        of the original set. 
     
    967967    """ 
    968968    Custom object for accessing the items of an OrderedDict. 
    969      
     969 
    970970    Can be called like the normal ``OrderedDict.items`` method, but also 
    971971    supports indexing and sequence methods. 
     
    10771077    """ 
    10781078    Custom object for accessing the values of an OrderedDict. 
    1079      
     1079 
    10801080    Can be called like the normal ``OrderedDict.values`` method, but also 
    10811081    supports indexing and sequence methods. 
     
    10991099        """ 
    11001100        Set the value at position i to value. 
    1101          
     1101 
    11021102        You can only do slice assignment to values if you supply a sequence of 
    11031103        equal length to the slice you are replacing. 
     
    11681168    Experimental version of OrderedDict that has a custom object for ``keys``, 
    11691169    ``values``, and ``items``. 
    1170      
     1170 
    11711171    These are callable sequence objects that work as methods, or can be 
    11721172    manipulated directly as sequences. 
    1173      
     1173 
    11741174    Test for ``keys``, ``items`` and ``values``. 
    1175      
     1175 
    11761176    >>> d = SequenceOrderedDict(((1, 2), (2, 3), (3, 4))) 
    11771177    >>> d 
     
    12931293    >>> d 
    12941294    SequenceOrderedDict([(1, 1), (2, 2), (3, 3)]) 
    1295      
     1295 
    12961296    >>> d = SequenceOrderedDict(((1, 2), (2, 3), (3, 4))) 
    12971297    >>> d 
Note: See TracChangeset for help on using the changeset viewer.