| 319 | } |
| 320 | |
| 321 | class FeedParserDict(dict): |
| 322 | keymap = {'channel': 'feed', |
| 323 | 'items': 'entries', |
| 324 | 'guid': 'id', |
| 325 | 'date': 'updated', |
| 326 | 'date_parsed': 'updated_parsed', |
| 327 | 'description': ['summary', 'subtitle'], |
| 328 | 'description_detail': ['summary_detail', 'subtitle_detail'], |
| 329 | 'url': ['href'], |
| 330 | 'modified': 'updated', |
| 331 | 'modified_parsed': 'updated_parsed', |
| 332 | 'issued': 'published', |
| 333 | 'issued_parsed': 'published_parsed', |
| 334 | 'copyright': 'rights', |
| 335 | 'copyright_detail': 'rights_detail', |
| 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: |
no outgoing calls
no test coverage detected
searching dependent graphs…