~ubuntu-branches/ubuntu/saucy/gaupol/saucy-proposed

« back to all changes in this revision

Viewing changes to aeidon/mutables.py

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski
  • Date: 2013-01-06 17:10:10 UTC
  • mfrom: (1.2.8)
  • mto: (10.2.3 experimental)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: package-import@ubuntu.com-20130106171010-kmlq0sy324jlp9zz
Tags: upstream-0.21
Import upstream version 0.21

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
 
1
3
# Copyright (C) 2006-2007,2009 Osmo Salomaa
2
4
#
3
5
# This file is part of Gaupol.
33
35
    return wrapper
34
36
 
35
37
 
36
 
class ObservableDict(dict):
 
38
class ObservableDict(dict, metaclass=aeidon.Contractual):
37
39
 
38
 
    """Observable version of ``dict``.
 
40
    """
 
41
    Observable version of ``dict``.
39
42
 
40
43
    :ivar master: Master instance with a ``notify`` method
41
44
    :ivar name: Argument passed when calling :attr:`master`'s ``notify`` method
42
45
    """
43
46
 
44
 
    __metaclass__ = aeidon.Contractual
45
 
 
46
47
    def __copy__(self):
47
48
        dic = dict(copy.copy(x) for  x in self.items())
48
49
        return self.__class__(dic, self.master, self.name)
88
89
        return dict.update(self, *args, **kwargs)
89
90
 
90
91
 
91
 
class ObservableList(list):
 
92
class ObservableList(list, metaclass=aeidon.Contractual):
92
93
 
93
 
    """Observable version of ``list``.
 
94
    """
 
95
    Observable version of ``list``.
94
96
 
95
97
    :ivar master: Master instance with a ``notify`` method
96
98
    :ivar name: Argument passed when calling :attr:`master`'s ``notify`` method
97
99
    """
98
100
 
99
 
    __metaclass__ = aeidon.Contractual
100
 
 
101
101
    def __copy__(self):
102
102
        lst = list(copy.copy(x) for x in self)
103
103
        return self.__class__(lst, self.master, self.name)
111
111
        return list.__delitem__(self, *args, **kwargs)
112
112
 
113
113
    @_mutation
114
 
    def __delslice__(self, *args, **kwargs):
115
 
        return list.__delslice__(self, *args, **kwargs)
116
 
 
117
 
    @_mutation
118
114
    def __iadd__(self, *args, **kwargs):
119
115
        return list.__iadd__(self, *args, **kwargs)
120
116
 
135
131
        return list.__setitem__(self, *args, **kwargs)
136
132
 
137
133
    @_mutation
138
 
    def __setslice__(self, *args, **kwargs):
139
 
        return list.__setslice__(self, *args, **kwargs)
140
 
 
141
 
    @_mutation
142
134
    def append(self, *args, **kwargs):
143
135
        return list.append(self, *args, **kwargs)
144
136
 
167
159
        return list.sort(self, *args, **kwargs)
168
160
 
169
161
 
170
 
class ObservableSet(set):
 
162
class ObservableSet(set, metaclass=aeidon.Contractual):
171
163
 
172
 
    """Observable version of ``set``.
 
164
    """
 
165
    Observable version of ``set``.
173
166
 
174
167
    :ivar master: Master instance with a ``notify`` method
175
168
    :ivar name: Argument passed when calling :attr:`master`'s ``notify`` method
176
169
    """
177
170
 
178
 
    __metaclass__ = aeidon.Contractual
179
 
 
180
171
    def __copy__(self):
181
172
        zet = set(copy.copy(x) for x in self)
182
173
        return self.__class__(zet, self.master, self.name)