summaryrefslogtreecommitdiff
path: root/CSSParser.py
blob: 72c643e3853d195595f42afc2ca38576638dab4b (plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env python

import sys, re

class CSSUtils:
	ColorRegex = re.compile('', re.I | re.M | re.U)
	
	@staticmethod
	def compress_color(color):
		pass
	
	@staticmethod
	def is_color(color):
		pass

class CSSContainer:
	selector = ''
	
	def __init__(self):
		pass
	
class CSSParser:
	ValidProperties = (
		'azimuth',
		'background',
		'background-color',
		'background-image',
		'background-repeat',
		'background-attachment',
		'background-position',
		'border',
		'border-top',
		'border-right',
		'border-left',
		'border-bottom',
		'border-color',
		'border-top-color',
		'border-right-color',
		'border-bottom-color',
		'border-left-color',
		'border-style',
		'border-top-style',
		'border-right-style',
		'border-bottom-style',
		'border-left-style',
		'border-width',
		'border-top-width',
		'border-left-width',
		'border-right-width',
		'border-bottom-width',
		'border-collapse',
		'border-spacing',
		'bottom',
		'clear',
		'clip',
		'color',
		'cursor',
		'direction',
		'display',
		'float',
		'font',
		'font-family',
		'font-size',
		'font-style',
		'font-variant',
		'font-weight',
		'height',
		'left',
		'letter-spacing',
		'line-height',
		'list-style',
		'list-style-image',
		'list-style-position',
		'list-style-type',
		'margin',
		'margin-top',
		'margin-right',
		'margin-bottom',
		'margin-left',
		'marker-offset',
		'marks',
		'overflow',
		'padding',
		'padding-top',
		'padding-bottom',
		'padding-right',
		'padding-left',
		'page-break-before',
		'position',
		'right',
		'size',
		'src',
		'table-layout',
		'text-align',
		'text-decoration',
		'text-indent',
		'text-transform',
		'top',
		'vertical-align',
		'visibility',
		'white-space',
		'width',
		'z-index'
	)

	CSSRegex = re.compile(r'([^{]+)\s?{\s?([^}]*)\s?}', re.I | re.M | re.U)
	PropertyRegex = re.compile(r'([^:]+):([^;]+);', re.I | re.M | re.U)
	CommentRegex = re.compile(r'/\*(.|[\r\n])*?\*/', re.I | re.M | re.U)
	
	def __init__(self):
		pass

	def parse(self):
		pass

	def duplicate_check(self):
		pass

def load_file(filename):
	""" Loads a file line by line into a variable and returns it."""
	infile = ''
	
	try:
		theFile = file(filename, "r")
	except IOError:
		sys.exit()

	for line in theFile:
		infile += line

	return infile

if __name__ == '__main__':
	output = CSSParser.CommentRegex.sub(' ', load_file(sys.argv[1]))
	output = CSSParser.CSSRegex.findall(output)

	containers = 0
	errors = 0

	for item in output:
		containers += 1
		properties = re.sub('\s+', ' ', item[1])
		proparray = CSSParser.PropertyRegex.findall(properties)
		container = item[0].strip()
	
		#print "Container: %s" % item[0].strip()
		#print "Contents: %s" %  properties
		print "Property Array: %s \n\n" % proparray
		
		for item in proparray:
			if item[0].strip().lower() not in CSSParser.ValidProperties:
				errors += 1
				print "WARNING: Invalid property '%s' in container '%s'" % (item[0].strip(), container)

	print "---\n\nFound %s containers and %s errors" % (containers, errors)