File: compatibility.py

package info (click to toggle)
python-feedvalidator 0~svn1022-3
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 648 kB
  • ctags: 2,452
  • sloc: python: 9,481; makefile: 27; sh: 8
file content (40 lines) | stat: -rw-r--r-- 1,125 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""$Id: compatibility.py 988 2008-03-12 18:22:48Z sa3ruby $"""

__author__ = "Sam Ruby <http://intertwingly.net/> and Mark Pilgrim <http://diveintomark.org/>"
__version__ = "$Revision: 988 $"
__copyright__ = "Copyright (c) 2002 Sam Ruby and Mark Pilgrim"

from logging import *

def _must(event):
  return isinstance(event, Error)

def _should(event):
  return isinstance(event, Warning)

def _may(event):
  return isinstance(event, Info)

def A(events):
  return [event for event in events if _must(event)]

def AA(events):
  return [event for event in events if _must(event) or _should(event)]

def AAA(events):
  return [event for event in events if _must(event) or _should(event) or _may(event)]

def AAAA(events):
  return events

def analyze(events, rawdata):
  block = rawdata[0:512].strip().upper()
  if block.startswith('<HTML'): return 'html'
  if block.startswith('<!DOCTYPE HTML'): return 'html'

  for event in events:
    if isinstance(event,UndefinedElement):
      if event.params['parent'] == 'root':
        if event.params['element'].lower() in ['html','xhtml:html']:
          return "html"
  return None