def parseFile(self, filename, encoding=None, href=None, media=None, title=None): """Retrieve content from `filename` and parse it. Errors may be raised (e.g. IOError). :param filename: of the CSS file to parse, if no `href` is given filename is converted to a (file:) URL and set as ``href`` of resulting stylesheet. If `href` is given it is set as ``sheet.href``. Either way ``sheet.href`` is used to resolve e.g. stylesheet imports via @import rules. :param encoding: Value ``None`` defaults to encoding detection via BOM or an @charset rule. Other values override detected encoding for the sheet at `filename` including any imported sheets. :returns: :class:`~cssutils.css.CSSStyleSheet`. """ if not href: # prepend // for file URL, urllib does not do this? #href = u'file:' + urllib.pathname2url(os.path.abspath(filename)) href = path2url(filename) return self.parseString( open(filename, 'rb').read(), encoding=encoding, # read returns a str href=href, media=media, title=title)
def parseFile(self, filename, encoding=None, href=None, media=None, title=None): """Retrieve content from `filename` and parse it. Errors may be raised (e.g. IOError). :param filename: of the CSS file to parse, if no `href` is given filename is converted to a (file:) URL and set as ``href`` of resulting stylesheet. If `href` is given it is set as ``sheet.href``. Either way ``sheet.href`` is used to resolve e.g. stylesheet imports via @import rules. :param encoding: Value ``None`` defaults to encoding detection via BOM or an @charset rule. Other values override detected encoding for the sheet at `filename` including any imported sheets. :returns: :class:`~cssutils.css.CSSStyleSheet`. """ if not href: # prepend // for file URL, urllib does not do this? #href = u'file:' + urllib.pathname2url(os.path.abspath(filename)) href = path2url(filename) return self.parseString(open(filename, 'rb').read(), encoding=encoding, # read returns a str href=href, media=media, title=title)