(self, key)
| 336 | 'tagline': 'subtitle', |
| 337 | 'tagline_detail': 'subtitle_detail'} |
| 338 | def __getitem__(self, key): |
| 339 | if key == 'category': |
| 340 | try: |
| 341 | return dict.__getitem__(self, 'tags')[0]['term'] |
| 342 | except IndexError: |
| 343 | raise KeyError, "object doesn't have key 'category'" |
| 344 | elif key == 'enclosures': |
| 345 | norel = lambda link: FeedParserDict([(name,value) for (name,value) in link.items() if name!='rel']) |
| 346 | return [norel(link) for link in dict.__getitem__(self, 'links') if link['rel']==u'enclosure'] |
| 347 | elif key == 'license': |
| 348 | for link in dict.__getitem__(self, 'links'): |
| 349 | if link['rel']==u'license' and 'href' in link: |
| 350 | return link['href'] |
| 351 | elif key == 'updated': |
| 352 | # Temporarily help developers out by keeping the old |
| 353 | # broken behavior that was reported in issue 310. |
| 354 | # This fix was proposed in issue 328. |
| 355 | if not dict.__contains__(self, 'updated') and \ |
| 356 | dict.__contains__(self, 'published'): |
| 357 | #warnings.warn("To avoid breaking existing software while " |
| 358 | # "fixing issue 310, a temporary mapping has been created " |
| 359 | # "from `updated` to `published` if `updated` doesn't " |
| 360 | # "exist. This fallback will be removed in a future version " |
| 361 | # "of feedparser.", DeprecationWarning) |
| 362 | return dict.__getitem__(self, 'published') |
| 363 | return dict.__getitem__(self, 'updated') |
| 364 | elif key == 'updated_parsed': |
| 365 | if not dict.__contains__(self, 'updated_parsed') and \ |
| 366 | dict.__contains__(self, 'published_parsed'): |
| 367 | #warnings.warn("To avoid breaking existing software while " |
| 368 | # "fixing issue 310, a temporary mapping has been created " |
| 369 | # "from `updated_parsed` to `published_parsed` if " |
| 370 | # "`updated_parsed` doesn't exist. This fallback will be " |
| 371 | # "removed in a future version of feedparser.", |
| 372 | # DeprecationWarning) |
| 373 | return dict.__getitem__(self, 'published_parsed') |
| 374 | return dict.__getitem__(self, 'updated_parsed') |
| 375 | else: |
| 376 | realkey = self.keymap.get(key, key) |
| 377 | if isinstance(realkey, list): |
| 378 | for k in realkey: |
| 379 | if dict.__contains__(self, k): |
| 380 | return dict.__getitem__(self, k) |
| 381 | elif dict.__contains__(self, realkey): |
| 382 | return dict.__getitem__(self, realkey) |
| 383 | return dict.__getitem__(self, key) |
| 384 | |
| 385 | def __contains__(self, key): |
| 386 | if key in ('updated', 'updated_parsed'): |
no test coverage detected