How to use the imgkit.imgkit.IMGKit.SourceError function in imgkit

To help you get started, we’ve selected a few imgkit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jarrekk / imgkit / imgkit / imgkit.py View on Github external
def _prepend_css(self, path):
        if self.source.isUrl() or isinstance(self.source.source, list):
            raise self.SourceError('CSS files can be added only to a single file or string')

        if not isinstance(path, list):
            path = [path]

        css_data = []
        for p in path:
            with codecs.open(p, encoding="UTF-8") as f:
                css_data.append(f.read())
        css_data = "\n".join(css_data)

        if self.source.isFile():
            with codecs.open(self.source.to_s(), encoding="UTF-8") as f:
                inp = f.read()
            self.source = Source(
                inp.replace('', self._style_tag(css_data) + ''),
                'string')