Menu

[r1]: / StyleSheet.py  Maximize  Restore  History

Download this file

127 lines (83 with data), 2.9 kB

  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
from Translator import *
import Declaration
import CharsetRule
import ImportRule
import MediaRule
import StyleRule
import CommentRule
import IncludeRule
import InheritRule
import ConstantRule
import CopyRule
import Object
import os.path, pdb
class SSSStyleSheet(Object.SSSObject):
"""
SSSStylesheet is the first class of Switch. It's the entry point of the
program.
"""
_parser = None
_selectors = None
_constants = {}
_inherit_offset = 0
_path = ''
_abs_path = ''
_working_dir = ''
_filename = ''
_extension = ''
_basename = ''
_href = ''
imported = None
def __init__(self, href = None):
super(SSSStyleSheet, self).__init__()
if href: self._setHref(href)
def _setHref(self, href):
self._href = href
if href.find('http:') != -1:
self._abs_path = href
if self.imported is None:
import urllib2
self.imported = True
from_url = urllib2.urlopen( self._href )
sss_text = from_url.read()
else:
# get path to resource
# if this stylesheet has a parent, the url is relative to the parent
if self.parentStyleSheet:
#path = os.path.normpath( os.path.join( os.path.dirname( self.parentStyleSheet.href ), href ) )
self._abs_path = os.path.normpath( os.path.join( os.path.dirname( self.parentStyleSheet.abs_path ), href ) )
# if no parentstylesheet, use the path given
else:
self._abs_path = href
sss_obj = open( self._abs_path, 'r')
sss_text = sss_obj.read()
sss_obj.close()
# Should this return _parse -- should parse return True/False???? - JCG
self._parse(sss_text)
def __str__(self):
return self._declarations.cssText
def get_href(self):
return self._href
def set_href(self, href):
return self._setHref(href)
href = property(get_href, set_href)
def get_abs_path(self):
return self._abs_path
abs_path = property(get_abs_path)
def get_cssText(self):
return self.__str__()
def set_cssText(self, text):
return self._parse(text)
cssText = property(get_cssText, set_cssText)
def declareConstant(self, name, value):
if (self.parentStyleSheet):
return self.parentStyleSheet.declareConstant(name, value)
if name in self._constants.keys():
return
self._constants[name] = value
def getConstant(self, name):
if self.parentStyleSheet:
return self.parentStyleSheet.getConstant(name)
if name in self._constants.keys():
return self._constants[name]
return False
MongoDB Logo MongoDB