|
8 | 8 | absolute_import, division, print_function, unicode_literals |
9 | 9 | ) |
10 | 10 |
|
| 11 | +from warnings import warn |
| 12 | + |
11 | 13 | from . import BabelFish |
12 | 14 | from .latent import LatentStyles |
13 | 15 | from ..shared import ElementProxy |
@@ -35,14 +37,24 @@ def __contains__(self, name): |
35 | 37 |
|
36 | 38 | def __getitem__(self, key): |
37 | 39 | """ |
38 | | - Enables dictionary-style access by style id or UI name. |
| 40 | + Enables dictionary-style access by UI name. Lookup by style id is |
| 41 | + deprecated, triggers a warning, and will be removed in a near-future |
| 42 | + release. |
39 | 43 | """ |
40 | | - style_name = BabelFish.ui2internal(key) |
41 | | - for get in (self._element.get_by_id, self._element.get_by_name): |
42 | | - style_elm = get(style_name) |
43 | | - if style_elm is not None: |
44 | | - return StyleFactory(style_elm) |
45 | | - raise KeyError("no style with id or name '%s'" % key) |
| 44 | + style_elm = self._element.get_by_name(BabelFish.ui2internal(key)) |
| 45 | + if style_elm is not None: |
| 46 | + return StyleFactory(style_elm) |
| 47 | + |
| 48 | + style_elm = self._element.get_by_id(key) |
| 49 | + if style_elm is not None: |
| 50 | + msg = ( |
| 51 | + 'style lookup by style_id is deprecated. Use style name as ' |
| 52 | + 'key instead.' |
| 53 | + ) |
| 54 | + warn(msg, UserWarning) |
| 55 | + return StyleFactory(style_elm) |
| 56 | + |
| 57 | + raise KeyError("no style with name '%s'" % key) |
46 | 58 |
|
47 | 59 | def __iter__(self): |
48 | 60 | return (StyleFactory(style) for style in self._element.style_lst) |
|
0 commit comments