@@ -149,42 +149,22 @@ def __exit__(self, exc_type, exc_val, exc_tb):
149
149
150
150
151
151
class ImageOpener (Opener ):
152
- """ Opener-type class passed to image classes to collect compressed extensions
152
+ """ Opener-type class to collect extra compressed extensions
153
153
154
- This class allows itself to have image extensions added to its class
155
- attributes, via the `register_ex_from_images`. The class can therefore
156
- change state when image classes are defined.
154
+ A trivial sub-class of opener to which image classes can add extra
155
+ extensions with custom openers, such as compressed openers.
156
+
157
+ To add an extension, add a line to the class definition (not __init__):
158
+
159
+ ImageOpener.compress_ext_map[ext] = func_def
160
+
161
+ ``ext`` is a file extension beginning with '.' and should be included in
162
+ the image class's ``valid_exts`` tuple.
163
+
164
+ ``func_def`` is a `(function, (args,))` tuple, where `function accepts a
165
+ filename as the first parameter, and `args` defines the other arguments
166
+ that `function` accepts. These arguments must be any (unordered) subset of
167
+ `mode`, `compresslevel`, and `buffering`.
157
168
"""
169
+ # Add new extensions to this dictionary
158
170
compress_ext_map = Opener .compress_ext_map .copy ()
159
-
160
- @classmethod
161
- def register_ext_from_image (opener_klass , ext , func_def ):
162
- """Decorator for adding extension / opener_function associations.
163
-
164
- Should be used to decorate classes. Updates ImageOpener class with
165
- desired extension / opener association. Updates decorated class by
166
- adding ```ext``` to ```klass.alternate_exts```.
167
-
168
- Parameters
169
- ----------
170
- opener_klass : decorated class
171
- ext : file extension to associate `func_def` with.
172
- should start with '.'
173
- func_def : opener function/parameter tuple
174
- Should be a `(function, (args,))` tuple, where `function` accepts
175
- a filename as the first parameter, and `args` defines the
176
- other arguments that `function` accepts. These arguments must
177
- be any (unordered) subset of `mode`, `compresslevel`,
178
- and `buffering`.
179
-
180
- Returns
181
- -------
182
- opener_klass
183
- """
184
- def decorate (klass ):
185
- assert ext not in opener_klass .compress_ext_map , \
186
- "Cannot redefine extension-function mappings."
187
- opener_klass .compress_ext_map [ext ] = func_def
188
- klass .valid_exts += (ext ,)
189
- return klass
190
- return decorate
0 commit comments