/scss/__init__.py

http://github.com/klen/python-scss · Python · 403 lines · 365 code · 26 blank · 12 comment · 5 complexity · b257a02a387c6668ed56c9a188fcc120 MD5 · raw file

  1. #!/usr/bin/env python
  2. """ Python SCSS parser. """
  3. import operator
  4. from . import compat
  5. VERSION_INFO = (0, 8, 73)
  6. __project__ = "scss"
  7. __version__ = "0.8.73"
  8. __author__ = "Kirill Klenov <horneds@gmail.com>"
  9. __license__ = "GNU LGPL"
  10. CONV = {
  11. 'size': {
  12. 'em': 13.0,
  13. 'px': 1.0},
  14. 'length': {
  15. 'mm': 1.0,
  16. 'cm': 10.0,
  17. 'in': 25.4,
  18. 'pt': 25.4 / 72,
  19. 'pc': 25.4 / 6},
  20. 'time': {
  21. 'ms': 1.0,
  22. 's': 1000.0},
  23. 'freq': {
  24. 'hz': 1.0,
  25. 'khz': 1000.0},
  26. 'any': {
  27. '%': 1.0 / 100,
  28. 'deg': 1.0 / 360,
  29. 's': 1.0 / 60}}
  30. CONV_TYPE = {}
  31. CONV_FACTOR = {}
  32. for t, m in CONV.items():
  33. for k, f in m.items():
  34. CONV_TYPE[k] = t
  35. CONV_FACTOR[k] = f
  36. OPRT = {
  37. '^': operator.__pow__,
  38. '+': operator.__add__,
  39. '-': operator.__sub__,
  40. '*': operator.__mul__,
  41. '/': compat.div,
  42. '!': operator.__neg__,
  43. '<': operator.__lt__,
  44. '<=': operator.__le__,
  45. '>': operator.__gt__,
  46. '>=': operator.__ge__,
  47. '==': operator.__eq__,
  48. '=': operator.__eq__,
  49. '!=': operator.__ne__,
  50. '&': operator.__and__,
  51. '|': operator.__or__,
  52. 'and': lambda x, y: x and y,
  53. 'or': lambda x, y: x or y,
  54. }
  55. ELEMENTS_OF_TYPE = {
  56. 'block': (
  57. "address, article, aside, blockquote, center, dd, dialog, dir, div, dl, dt, fieldset, "
  58. "figure, footer, form, frameset, h1, h2, h3, h4, h5, h6, header, hgroup, hr, isindex, "
  59. "menu, nav, noframes, noscript, ol, p, pre, section, ul"),
  60. 'inline': (
  61. "a, abbr, acronym, b, basefont, bdo, big, br, cite, code, dfn, em, font, i, img, input, "
  62. "kbd, label, q, s, samp, select, small, span, strike, strong, sub, sup, textarea, tt, u, "
  63. "var"),
  64. 'table': 'table', 'list-item': 'li', 'table-row-group': 'tbody',
  65. 'table-header-group': 'thead', 'table-footer-group': 'tfoot', 'table-row':
  66. 'tr', 'table-cell': 'td, th', }
  67. COLORS = {
  68. 'aliceblue': '#f0f8ff',
  69. 'antiquewhite': '#faebd7',
  70. 'aqua': '#00ffff',
  71. 'aquamarine': '#7fffd4',
  72. 'azure': '#f0ffff',
  73. 'beige': '#f5f5dc',
  74. 'bisque': '#ffe4c4',
  75. 'black': '#000000',
  76. 'blanchedalmond': '#ffebcd',
  77. 'blue': '#0000ff',
  78. 'blueviolet': '#8a2be2',
  79. 'brown': '#a52a2a',
  80. 'burlywood': '#deb887',
  81. 'cadetblue': '#5f9ea0',
  82. 'chartreuse': '#7fff00',
  83. 'chocolate': '#d2691e',
  84. 'coral': '#ff7f50',
  85. 'cornflowerblue': '#6495ed',
  86. 'cornsilk': '#fff8dc',
  87. 'crimson': '#dc143c',
  88. 'cyan': '#00ffff',
  89. 'darkblue': '#00008b',
  90. 'darkcyan': '#008b8b',
  91. 'darkgoldenrod': '#b8860b',
  92. 'darkgray': '#a9a9a9',
  93. 'darkgreen': '#006400',
  94. 'darkkhaki': '#bdb76b',
  95. 'darkmagenta': '#8b008b',
  96. 'darkolivegreen': '#556b2f',
  97. 'darkorange': '#ff8c00',
  98. 'darkorchid': '#9932cc',
  99. 'darkred': '#8b0000',
  100. 'darksalmon': '#e9967a',
  101. 'darkseagreen': '#8fbc8f',
  102. 'darkslateblue': '#483d8b',
  103. 'darkslategray': '#2f4f4f',
  104. 'darkturquoise': '#00ced1',
  105. 'darkviolet': '#9400d3',
  106. 'deeppink': '#ff1493',
  107. 'deepskyblue': '#00bfff',
  108. 'dimgray': '#696969',
  109. 'dodgerblue': '#1e90ff',
  110. 'firebrick': '#b22222',
  111. 'floralwhite': '#fffaf0',
  112. 'forestgreen': '#228b22',
  113. 'fuchsia': '#ff00ff',
  114. 'gainsboro': '#dcdcdc',
  115. 'ghostwhite': '#f8f8ff',
  116. 'gold': '#ffd700',
  117. 'goldenrod': '#daa520',
  118. 'gray': '#808080',
  119. 'green': '#008000',
  120. 'greenyellow': '#adff2f',
  121. 'honeydew': '#f0fff0',
  122. 'hotpink': '#ff69b4',
  123. 'indianred': '#cd5c5c',
  124. 'indigo': '#4b0082',
  125. 'ivory': '#fffff0',
  126. 'khaki': '#f0e68c',
  127. 'lavender': '#e6e6fa',
  128. 'lavenderblush': '#fff0f5',
  129. 'lawngreen': '#7cfc00',
  130. 'lemonchiffon': '#fffacd',
  131. 'lightblue': '#add8e6',
  132. 'lightcoral': '#f08080',
  133. 'lightcyan': '#e0ffff',
  134. 'lightgoldenrodyellow': '#fafad2',
  135. 'lightgreen': '#90ee90',
  136. 'lightgrey': '#d3d3d3',
  137. 'lightpink': '#ffb6c1',
  138. 'lightsalmon': '#ffa07a',
  139. 'lightseagreen': '#20b2aa',
  140. 'lightskyblue': '#87cefa',
  141. 'lightslategray': '#778899',
  142. 'lightsteelblue': '#b0c4de',
  143. 'lightyellow': '#ffffe0',
  144. 'lime': '#00ff00',
  145. 'limegreen': '#32cd32',
  146. 'linen': '#faf0e6',
  147. 'magenta': '#ff00ff',
  148. 'maroon': '#800000',
  149. 'mediumaquamarine': '#66cdaa',
  150. 'mediumblue': '#0000cd',
  151. 'mediumorchid': '#ba55d3',
  152. 'mediumpurple': '#9370db',
  153. 'mediumseagreen': '#3cb371',
  154. 'mediumslateblue': '#7b68ee',
  155. 'mediumspringgreen': '#00fa9a',
  156. 'mediumturquoise': '#48d1cc',
  157. 'mediumvioletred': '#c71585',
  158. 'midnightblue': '#191970',
  159. 'mintcream': '#f5fffa',
  160. 'mistyrose': '#ffe4e1',
  161. 'moccasin': '#ffe4b5',
  162. 'navajowhite': '#ffdead',
  163. 'navy': '#000080',
  164. 'oldlace': '#fdf5e6',
  165. 'olive': '#808000',
  166. 'olivedrab': '#6b8e23',
  167. 'orange': '#ffa500',
  168. 'orangered': '#ff4500',
  169. 'orchid': '#da70d6',
  170. 'palegoldenrod': '#eee8aa',
  171. 'palegreen': '#98fb98',
  172. 'paleturquoise': '#afeeee',
  173. 'palevioletred': '#db7093',
  174. 'papayawhip': '#ffefd5',
  175. 'peachpuff': '#ffdab9',
  176. 'peru': '#cd853f',
  177. 'pink': '#ffc0cb',
  178. 'plum': '#dda0dd',
  179. 'powderblue': '#b0e0e6',
  180. 'purple': '#800080',
  181. 'red': '#ff0000',
  182. 'rosybrown': '#bc8f8f',
  183. 'royalblue': '#4169e1',
  184. 'saddlebrown': '#8b4513',
  185. 'salmon': '#fa8072',
  186. 'sandybrown': '#f4a460',
  187. 'seagreen': '#2e8b57',
  188. 'seashell': '#fff5ee',
  189. 'sienna': '#a0522d',
  190. 'silver': '#c0c0c0',
  191. 'skyblue': '#87ceeb',
  192. 'slateblue': '#6a5acd',
  193. 'slategray': '#708090',
  194. 'snow': '#fffafa',
  195. 'springgreen': '#00ff7f',
  196. 'steelblue': '#4682b4',
  197. 'tan': '#d2b48c',
  198. 'teal': '#008080',
  199. 'thistle': '#d8bfd8',
  200. 'tomato': '#ff6347',
  201. 'turquoise': '#40e0d0',
  202. 'violet': '#ee82ee',
  203. 'wheat': '#f5deb3',
  204. 'white': '#ffffff',
  205. 'whitesmoke': '#f5f5f5',
  206. 'yellow': '#ffff00',
  207. 'yellowgreen': '#9acd32'
  208. }
  209. SORTING = dict((v, k) for k, v in enumerate((
  210. # Positioning
  211. 'position',
  212. 'top',
  213. 'right',
  214. 'bottom',
  215. 'left',
  216. 'z-index',
  217. # Box behavior and properties
  218. 'float',
  219. 'clear',
  220. 'display',
  221. 'visibility',
  222. 'overflow',
  223. 'overflow-x',
  224. 'overflow-y',
  225. 'overflow-style',
  226. 'zoom',
  227. 'clip',
  228. 'box-sizing',
  229. 'box-shadow',
  230. # Sizing
  231. 'margin',
  232. 'margin-top',
  233. 'margin-right',
  234. 'margin-bottom',
  235. 'margin-left',
  236. 'padding',
  237. 'padding-top',
  238. 'padding-right',
  239. 'padding-bottom',
  240. 'padding-left',
  241. 'width',
  242. 'height',
  243. 'max-width',
  244. 'max-height',
  245. 'min-width',
  246. 'min-height',
  247. # Color appearance
  248. 'outline',
  249. 'outline-offset',
  250. 'outline-width',
  251. 'outline-style',
  252. 'outline-color',
  253. 'border',
  254. 'border-break',
  255. 'border-collapse',
  256. 'border-color',
  257. 'border-image',
  258. 'border-top-image',
  259. 'border-right-image',
  260. 'border-bottom-image',
  261. 'border-left-image',
  262. 'border-corner-image',
  263. 'border-top-left-image',
  264. 'border-top-right-image',
  265. 'border-bottom-right-image',
  266. 'border-bottom-left-image',
  267. 'border-fit',
  268. 'border-length',
  269. 'border-spacing',
  270. 'border-style',
  271. 'border-width',
  272. 'border-top',
  273. 'border-top-width',
  274. 'border-top-style',
  275. 'border-top-color',
  276. 'border-right',
  277. 'border-right-width',
  278. 'border-right-style',
  279. 'border-right-color',
  280. 'border-bottom',
  281. 'border-bottom-width',
  282. 'border-bottom-style',
  283. 'border-bottom-color',
  284. 'border-left',
  285. 'border-left-width',
  286. 'border-left-style',
  287. 'border-left-color',
  288. 'border-radius',
  289. 'border-top-right-radius',
  290. 'border-top-left-radius',
  291. 'border-bottom-right-radius',
  292. 'border-bottom-left-radius',
  293. 'background',
  294. 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader',
  295. 'background-color',
  296. 'background-image',
  297. 'background-repeat',
  298. 'background-attachment',
  299. 'background-position',
  300. 'background-position-x',
  301. 'background-position-y',
  302. 'background-break',
  303. 'background-clip',
  304. 'background-origin',
  305. 'background-size',
  306. 'color',
  307. # Special content types
  308. 'table-layout',
  309. 'caption-side',
  310. 'empty-cells',
  311. 'list-style',
  312. 'list-style-position',
  313. 'list-style-type',
  314. 'list-style-image',
  315. 'quotes',
  316. 'content',
  317. 'counter-increment',
  318. 'counter-reset',
  319. # Text
  320. 'direction',
  321. 'vertical-align',
  322. 'text-align',
  323. 'text-align-last',
  324. 'text-decoration',
  325. 'text-emphasis',
  326. 'text-height',
  327. 'text-indent',
  328. 'text-justify',
  329. 'text-outline',
  330. 'text-replace',
  331. 'text-transform',
  332. 'text-wrap',
  333. 'text-shadow',
  334. 'line-height',
  335. 'white-space',
  336. 'white-space-collapse',
  337. 'word-break',
  338. 'word-spacing',
  339. 'word-wrap',
  340. 'letter-spacing',
  341. 'font',
  342. 'font-weight',
  343. 'font-style',
  344. 'font-variant',
  345. 'font-size',
  346. 'font-size-adjust',
  347. 'font-family',
  348. 'font-effect',
  349. 'font-emphasize',
  350. 'font-emphasize-position',
  351. 'font-emphasize-style',
  352. 'font-smooth',
  353. 'font-stretch',
  354. 'src',
  355. # Visual properties
  356. 'opacity',
  357. 'filter:progid:DXImageTransform.Microsoft.Alpha',
  358. '-ms-filter:progid:DXImageTransform.Microsoft.Alpha',
  359. 'transitions',
  360. 'resize',
  361. 'cursor',
  362. # Print
  363. 'page-break-before',
  364. 'page-break-inside',
  365. 'page-break-after',
  366. 'orphans',
  367. 'widows',
  368. # Transfom
  369. 'transition',
  370. 'transition-delay',
  371. 'transition-duration',
  372. 'transition-property',
  373. 'transition-timing-function',
  374. )))
  375. class ScssException(Exception):
  376. """ Raise SCSS exception. """
  377. pass