示例#1
0
 def map_sprites(self):
     with self.open_parser() as p:
         srefs = find_sprite_refs(p, conf=self.conf, source=self.fname)
         def test_sref(sref):
             if not access(str(sref), R_OK):
                 logger.error("%s: not readable", sref); return False
             else:
                 logger.debug("%s passed", sref); return True
         return self.mapper.map_reduced(ifilter(test_sref, srefs))
示例#2
0
    def map_file(self, fname, mapper=None):
        """Convenience function to map the sprites of a given CSS file."""
        from spritecss.css import CSSParser
        from spritecss.finder import find_sprite_refs

        with open(fname, "rb") as fp:
            parser = CSSParser.read_file(fp)
            evs = list(parser.iter_events())

        conf = CSSConfig(evs, base=self.conf, fname=fname)
        srefs = find_sprite_refs(evs, source=fname, conf=conf)

        if mapper is None:
            mapper = SpriteDirsMapper.from_conf(conf)

        return self.map_sprite_refs(srefs, mapper=mapper)
示例#3
0
文件: mapper.py 项目: 4u/Spritemapper
    def map_file(self, fname, mapper=None):
        """Convenience function to map the sprites of a given CSS file."""
        from spritecss.css import CSSParser
        from spritecss.finder import find_sprite_refs

        with open(fname, "rb") as fp:
            parser = CSSParser.read_file(fp)
            evs = list(parser.iter_events())

        conf = CSSConfig(evs, base=self.conf, fname=fname)
        srefs = find_sprite_refs(evs, source=fname, conf=conf)

        if mapper is None:
            mapper = SpriteDirsMapper.from_conf(conf)

        return self.map_sprite_refs(srefs, mapper=mapper)