Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
href
location of the style sheet to be imported.
mediaText
A list of media types for which this style sheet may be used
as a string
"""
super(CSSImportRule, self).__init__(parentRule=parentRule,
parentStyleSheet=parentStyleSheet)
self._atkeyword = u'@import'
self.hreftype = None
self._styleSheet = None
self._href = None
self.href = href
self._media = cssutils.stylesheets.MediaList()
if mediaText:
self._media.mediaText = mediaText
self._name = name
seq = self._tempSeq()
seq.append(self.href, 'href')
seq.append(self.media, 'media')
seq.append(self.name, 'name')
self._setSeq(seq)
self._readonly = readonly
- :exc:`~xml.dom.NoModificationAllowedErr`:
Raised if the rule is readonly.
- :exc:`~xml.dom.SyntaxErr`:
Raised if the specified CSS string value has a syntax error and
is unparsable.
"""
super(CSSImportRule, self)._setCssText(cssText)
tokenizer = self._tokenize2(cssText)
attoken = self._nexttoken(tokenizer, None)
if self._type(attoken) != self._prods.IMPORT_SYM:
self._log.error(u'CSSImportRule: No CSSImportRule found: %s' %
self._valuestr(cssText),
error=xml.dom.InvalidModificationErr)
else:
# save if parse goes wrong
oldmedia = cssutils.stylesheets.MediaList()
oldmedia._absorb(self.media)
# for closures: must be a mutable
new = {'keyword': self._tokenvalue(attoken),
'href': None,
'hreftype': None,
'media': None,
'name': None,
'wellformed': True
}
def __doname(seq, token):
# called by _string or _ident
new['name'] = self._stringtokenvalue(token)
seq.append(new['name'], 'name')
return ';'
else:
# save if parse goes wrong
oldMedia = self._media
oldName = self._name
oldCssRules = self._cssRules
ok = True
# media
mediatokens, end = self._tokensupto2(tokenizer,
mediaqueryendonly=True,
separateEnd=True)
if u'{' == self._tokenvalue(end)\
or self._prods.STRING == self._type(end):
self.media = cssutils.stylesheets.MediaList(parentRule=self)
# TODO: remove special case
self.media.mediaText = mediatokens
ok = ok and self.media.wellformed
else:
ok = False
# name (optional)
name = None
nameseq = self._tempSeq()
if self._prods.STRING == self._type(end):
name = self._stringtokenvalue(end)
# TODO: for now comments are lost after name
nametokens, end = self._tokensupto2(tokenizer,
blockstartonly=True,
separateEnd=True)
wellformed, expected = self._parse(None,
The ``href`` attribute to assign to the parsed style sheet.
Used to resolve other urls in the parsed sheet like @import hrefs.
:param media:
The ``media`` attribute to assign to the parsed style sheet
(may be a MediaList, list or a string).
:param title:
The ``title`` attribute to assign to the parsed style sheet.
:returns:
:class:`~cssutils.css.CSSStyleSheet`.
"""
self.__parseSetting(True)
if isinstance(cssText, str):
cssText = codecs.getdecoder('css')(cssText, encoding=encoding)[0]
sheet = cssutils.css.CSSStyleSheet(href=href,
media=cssutils.stylesheets.MediaList(media),
title=title)
sheet._setFetcher(self.__fetcher)
# tokenizing this ways closes open constructs and adds EOF
sheet._setCssTextWithEncodingOverride(self.__tokenizer.tokenize(cssText,
fullsheet=True),
encodingOverride=encoding)
self.__parseSetting(False)
return sheet
href
location of the style sheet to be imported.
mediaText
A list of media types for which this style sheet may be used
as a string
"""
super(CSSImportRule, self).__init__(parentRule=parentRule,
parentStyleSheet=parentStyleSheet)
self._atkeyword = u'@import'
self.hreftype = None
self._styleSheet = None
self._href = None
self.href = href
self._media = cssutils.stylesheets.MediaList()
if mediaText:
self._media.mediaText = mediaText
self._name = name
seq = self._tempSeq()
seq.append(self.href, 'href')
seq.append(self.media, 'media')
seq.append(self.name, 'name')
self._setSeq(seq)
self._readonly = readonly
def __init__(self, mediaText='all', name=None,
parentRule=None, parentStyleSheet=None, readonly=False):
"""constructor"""
super(CSSMediaRule, self).__init__(parentRule=parentRule,
parentStyleSheet=parentStyleSheet)
self._atkeyword = u'@media'
self._media = cssutils.stylesheets.MediaList(mediaText,
readonly=readonly)
self.name = name
self.cssRules = cssutils.css.cssrulelist.CSSRuleList()
self._readonly = readonly
def _setMedia(self, media):
"""
:param media:
a :class:`~cssutils.stylesheets.MediaList` or string
"""
self._checkReadonly()
if isinstance(media, basestring):
self._media = cssutils.stylesheets.MediaList(mediaText=media,
parentRule=self)
else:
media._parentRule = self
self._media = media
def __init__(self, mediaText=None, variables=None, parentRule=None,
parentStyleSheet=None, readonly=False):
"""
If readonly allows setting of properties in constructor only.
"""
super(CSSVariablesRule, self).__init__(parentRule=parentRule,
parentStyleSheet=parentStyleSheet)
self._atkeyword = u'@variables'
# dummy
self._media = cssutils.stylesheets.MediaList(mediaText,
readonly=readonly)
if variables:
self.variables = variables
else:
self.variables = CSSVariablesDeclaration(parentRule=self)
self._readonly = readonly
def __init__(self, mediaText='all', name=None,
parentRule=None, parentStyleSheet=None, readonly=False):
"""constructor"""
super(CSSMediaRule, self).__init__(parentRule=parentRule,
parentStyleSheet=parentStyleSheet)
self._atkeyword = u'@media'
self._media = cssutils.stylesheets.MediaList(mediaText,
readonly=readonly)
self.name = name
self.cssRules = cssutils.css.cssrulelist.CSSRuleList()
self.cssRules.append = self.insertRule
self.cssRules.extend = self.insertRule
self.cssRules.__delitem__ == self.deleteRule
self._readonly = readonly