当前位置: 首页>>代码示例>>Python>>正文


Python Util.fileGetContents方法代码示例

本文整理汇总了Python中util.Util.fileGetContents方法的典型用法代码示例。如果您正苦于以下问题:Python Util.fileGetContents方法的具体用法?Python Util.fileGetContents怎么用?Python Util.fileGetContents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在util.Util的用法示例。


在下文中一共展示了Util.fileGetContents方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: optimizeJsManifest

# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import fileGetContents [as 别名]
    def optimizeJsManifest(self):
        contents = Util.fileGetContents(self.config.js_manifest)

        for key, value in self.manifest_ids.items():
            if "#" + value in self.id_map:
                contents = re.sub(r'((?<!\$)\${1}[A-Z0-9_]+\s?=\s?[\'|\"])(' + value + ')([\'|\"][,|;])', r'\1' + self.id_map["#" + value].replace("#", "") + r'\3', contents)

        for key, value in self.manifest_classes.items():
            if "." + value in self.class_map:
                contents = re.sub(r'(\${2}[A-Z0-9_]+\s?=\s?[\'|\"])(' + value + ')([\'|\"][,|;])', r'\1' + self.class_map["." + value].replace(".", "") + r'\3', contents)

        if self.config.rewrite_constants:
            constants = re.findall(r'(\s+?(var\s)?([A-Z0-9_]+)\s?=\s?[\'|\"](.*?)[\'|\"][,|;])', contents)
            new_constants = {}
            i = 0
            for constant in constants:
                # underscore variables are ignored
                if constant[2][0] == "_":
                    continue

                i += 1
                new_constant = re.sub(r'=(.*)([,|;])','= ' + str(i) + r'\2', constant[0])
                contents = contents.replace(constant[0], new_constant)

        new_manifest = Util.prependExtension("opt", self.config.js_manifest)
        Util.filePutContents(new_manifest, contents)

        if self.config.show_savings:
            SizeTracker.trackFile(self.config.js_manifest, new_manifest)
开发者ID:Mondego,项目名称:pyreco,代码行数:31,代码来源:allPythonContent.py

示例2: processJsFile

# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import fileGetContents [as 别名]
    def processJsFile(self, path, inline = False):
        """processes a single js file to find all classes and ids to replace

        Arguments:
        path -- path to css file to process

        Returns:
        void

        """
        contents = Util.fileGetContents(path)
        if inline is True:
            blocks = self.getJsBlocks(contents)
            contents = ""
            for block in blocks:
                contents = contents + block

        selectors = self.getJsSelectors(contents, self.config)
        for selector in selectors:
            if selector[0] in self.config.id_selectors:
                if ',' in selector[2]:
                    id_to_add = re.search(r'(\'|\")(.*?)(\'|\")', selector[2])
                    if id_to_add is None:
                        continue

                    if not id_to_add.group(2):
                        continue

                    self.addId("#" + id_to_add.group(2))

                # if this is something like document.getElementById(variable) don't add it
                if not '\'' in selector[2] and not '"' in selector[2]:
                    continue

                self.addId("#" + selector[2].strip("\"").strip("'"))
                continue

            if selector[0] in self.config.class_selectors:
                class_to_add = re.search(r'(\'|\")(.*?)(\'|\")', selector[2])
                if class_to_add is None:
                    continue

                if not class_to_add.group(2):
                    continue

                self.addClass("." + class_to_add.group(2))
                continue

            if selector[0] in self.config.custom_selectors:
                matches = re.findall(r'((#|\.)[a-zA-Z0-9_]*)', selector[2])
                for match in matches:
                    if match[1] == "#":
                        self.addId(match[0])
                        continue

                    self.addClass(match[0])
开发者ID:Mondego,项目名称:pyreco,代码行数:58,代码来源:allPythonContent.py

示例3: optimizeCss

# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import fileGetContents [as 别名]
    def optimizeCss(self, path):
        """replaces classes and ids with new values in a css file

        Arguments:
        path -- string path to css file to optimize

        Returns:
        string

        """
        css = Util.fileGetContents(path)
        return self.replaceCss(css)
开发者ID:Mondego,项目名称:pyreco,代码行数:14,代码来源:allPythonContent.py

示例4: optimizeJavascript

# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import fileGetContents [as 别名]
    def optimizeJavascript(self, path):
        """optimizes javascript for a specific file

        Arguments:
        path -- path to js file on disk that we are optimizing

        Returns:
        string -- contents to replace file with

        """
        js = Util.fileGetContents(path)
        return self.replaceJavascript(js)
开发者ID:Mondego,项目名称:pyreco,代码行数:14,代码来源:allPythonContent.py

示例5: processJsManifest

# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import fileGetContents [as 别名]
    def processJsManifest(self):
        contents = Util.fileGetContents(self.config.js_manifest)
        ids = re.findall(r'\s+?(var\s)?\${1}([A-Z0-9_]+)\s?=\s?[\'|\"](.*?)[\'|\"][,|;]', contents)
        classes = re.findall(r'\s+?(var\s)?\${2}([A-Z0-9_]+)\s?=\s?[\'|\"](.*?)[\'|\"][,|;]', contents)

        self.manifest_ids = {}
        self.manifest_classes = {}

        for id in ids:
            self.addId("#" + id[2])
            self.manifest_ids[id[1]] = id[2]

        for manifest_class in classes:
            self.addClass("." + manifest_class[2])
            self.manifest_classes[manifest_class[1]] = manifest_class[2]
开发者ID:Mondego,项目名称:pyreco,代码行数:17,代码来源:allPythonContent.py

示例6: optimizeHtml

# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import fileGetContents [as 别名]
    def optimizeHtml(self, path):
        """replaces classes and ids with new values in an html file

        Uses:
        Muncher.replaceHtml

        Arguments:
        path -- string path to file to optimize

        Returns:
        string

        """
        html = Util.fileGetContents(path)
        html = self.replaceHtml(html)
        html = self.optimizeCssBlocks(html)
        html = self.optimizeJavascriptBlocks(html)

        return html
开发者ID:Mondego,项目名称:pyreco,代码行数:21,代码来源:allPythonContent.py

示例7: processCssFile

# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import fileGetContents [as 别名]
    def processCssFile(self, path, inline = False):
        """processes a single css file to find all classes and ids to replace

        Arguments:
        path -- path to css file to process

        Returns:
        void

        """
        contents = Util.fileGetContents(path)
        if inline is True:
            blocks = self.getCssBlocks(contents)
            contents = ""
            for block in blocks:
                contents = contents + block

        ids_found = re.findall(r'((?<!\:\s)(?<!\:)#\w+)(\.|\{|,|\s|#)', contents, re.DOTALL)
        classes_found = re.findall(r'(?!\.[0-9])\.\w+', contents)
        self.addIds(ids_found)
        self.addClasses(classes_found)
开发者ID:Mondego,项目名称:pyreco,代码行数:23,代码来源:allPythonContent.py


注:本文中的util.Util.fileGetContents方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。