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


Python jsmin.jsmin方法代码示例

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


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

示例1: load_config

# 需要导入模块: import jsmin [as 别名]
# 或者: from jsmin import jsmin [as 别名]
def load_config(config_file, template):
    """Loads the minified JSON config. Returns a dict."""

    # minify then load as JSON
    config = json.loads(jsmin(config_file.read()))

    # add packer required variables
    # Note: Backslashes are replaced with forward slashes (Packer on Windows)
    config['cache_dir'] = DIRS.user_cache_dir.replace('\\', '/')
    config['dir'] = resource_filename(__name__, "").replace('\\', '/')
    config['template_name'] = template
    config['config_dir'] = DIRS.user_config_dir.replace('\\', '/')

    # add default values
    # for users upgrading from versions where those values weren't defined
    # I don't want default to override the config so I reversed the merge logic
    default = {'hypervisor': 'virtualbox'}
    default.update(config)
    config = default

    return config 
开发者ID:GoSecure,项目名称:malboxes,代码行数:23,代码来源:malboxes.py

示例2: is_valid_commented_json

# 需要导入模块: import jsmin [as 别名]
# 或者: from jsmin import jsmin [as 别名]
def is_valid_commented_json(path, return_json=False, logger=None):
    """
    This function checks if the given file path is a valid commented JSON file.

    :param path: JSON file to be checked
    :param return_json: specify whether the return value (in case of success) should be the json object or True
    :param logger: pass a logger object to log a message in case of error
    :return: True if valid file, otherwise False
    """
    try:
        # TODO: check JSON file structure
        with open(path) as f:
            content = loads(jsmin(f.read()))
        return content if return_json else True
    except ValueError:
        if logger is not None:
            logger.error("JSON file '{}' cannot be read ! (check that the syntax is correct)".format(path))
        return False


# **************************************** DEBUG-PURPOSE HELPER **************************************** 
开发者ID:dhondta,项目名称:rpl-attacks,代码行数:23,代码来源:helpers.py

示例3: on_post_build

# 需要导入模块: import jsmin [as 别名]
# 或者: from jsmin import jsmin [as 别名]
def on_post_build(self, config):
        if self.config['minify_js']:
            jsfiles = self.config['js_files'] or []
            if not isinstance(jsfiles, list):
                jsfiles = [jsfiles]                                        
            for jsfile in jsfiles:
                # Minify
                input_filename = config['site_dir'] + '/' + jsfile
                if os.sep != '/':
                    input_filename = input_filename.replace(os.sep, '/')
                output_filename = input_filename.replace('.js','.min.js')
                minified = ''
                # Read original file and minify
                with open(input_filename) as inputfile:
                    minified = jsmin(inputfile.read())
                # Write minified output file
                with open(output_filename, 'w') as outputfile:
                    outputfile.write(minified)
                # Delete original file
                os.remove(input_filename)
        return config 
开发者ID:V1EngineeringInc,项目名称:V1EngineeringInc-Docs,代码行数:23,代码来源:plugin.py

示例4: testInputStream

# 需要导入模块: import jsmin [as 别名]
# 或者: from jsmin import jsmin [as 别名]
def testInputStream(self):
        try:
            from io import StringIO
        except ImportError:
            from io import StringIO
            
        ins = StringIO(r'''
            function foo('') {

            }
            ''')
        outs = StringIO()
        m = jsmin.JavascriptMinify()
        m.minify(ins, outs)
        output = outs.getvalue()
        assert output == "function foo(''){}" 
开发者ID:V1EngineeringInc,项目名称:V1EngineeringInc-Docs,代码行数:18,代码来源:test.py

示例5: load_json

# 需要导入模块: import jsmin [as 别名]
# 或者: from jsmin import jsmin [as 别名]
def load_json(string):
    return json.loads(jsmin.jsmin(string)) 
开发者ID:tokland,项目名称:shoogle,代码行数:4,代码来源:test_shoogle.py

示例6: load_json

# 需要导入模块: import jsmin [as 别名]
# 或者: from jsmin import jsmin [as 别名]
def load_json(json_string):
    """Return Python object from JSON string."""
    return json.loads(jsmin.jsmin(json_string)) 
开发者ID:tokland,项目名称:shoogle,代码行数:5,代码来源:lib.py

示例7: minify

# 需要导入模块: import jsmin [as 别名]
# 或者: from jsmin import jsmin [as 别名]
def minify(self, source, target):
        import jsmin
        js = jsmin.jsmin(open(source).read())
        with open(target, 'w') as f:
            f.write(js)
        log.info('minified js written to %s' % target) 
开发者ID:raelgc,项目名称:scudcloud,代码行数:8,代码来源:setup.py

示例8: load_profile

# 需要导入模块: import jsmin [as 别名]
# 或者: from jsmin import jsmin [as 别名]
def load_profile(profile_name):
    filename = os.path.join(
        DIRS.user_config_dir.replace('\\', '/'),
        "profiles",
        "{}.js".format(profile_name))

    """Loads the profile, minifies it and returns the content."""
    with open(filename, 'r') as profile_file:
        profile = json.loads(jsmin(profile_file.read()))
    return profile 
开发者ID:GoSecure,项目名称:malboxes,代码行数:12,代码来源:malboxes.py

示例9: minify_js_proc

# 需要导入模块: import jsmin [as 别名]
# 或者: from jsmin import jsmin [as 别名]
def minify_js_proc(src_text):
    """
    :param src_text: Source text to be minified
    :return: Minified text
    """
    return jsmin(src_text) 
开发者ID:BirkbeckCTP,项目名称:janeway,代码行数:8,代码来源:build_assets.py

示例10: test1_campaign_format

# 需要导入模块: import jsmin [as 别名]
# 或者: from jsmin import jsmin [as 别名]
def test1_campaign_format(self):
        """ > Is the new experiment campaign a correct JSON file ? """
        try:
            with open(self.path) as f:
                loads(jsmin(f.read()))
            passed = True
        except:
            passed = False
        self.assertTrue(passed) 
开发者ID:dhondta,项目名称:rpl-attacks,代码行数:11,代码来源:campaign.py

示例11: get_python2_recipe

# 需要导入模块: import jsmin [as 别名]
# 或者: from jsmin import jsmin [as 别名]
def get_python2_recipe():
    recipe = json.loads(jsmin(requests.get('https://raw.githubusercontent.com/flathub/shared-modules/master/python2.7/python-2.7.json').text))
    recipe['cleanup'] = ['*']
    return recipe 
开发者ID:flathub,项目名称:com.visualstudio.code.oss,代码行数:6,代码来源:build.py

示例12: run

# 需要导入模块: import jsmin [as 别名]
# 或者: from jsmin import jsmin [as 别名]
def run(self, worker_data):
        module = worker_data['module']
        module_data = worker_data['module_data']
        asar_working_path = worker_data['asar_working_path']

        # First we need to generate the JS variables that we will inject into the base.js script.
        js_variables = "\n".join(self.utils.generate_js_variable(module_data))

        file_to_inject = os.path.join(asar_working_path, 'browser', 'chrome-extension.js')
        if os.path.isfile(file_to_inject) is False:
            return False

        file_contents = self.utils.load_file(file_to_inject)

        # Get the JavaScript payload.
        js_payload = self.utils.load_file(os.path.join(module['path'], 'templates', 'code.js'))
        js_payload = js_payload.replace("%BEEMKA_VARIABLE_PLACEHOLDER%", js_variables)
        js_payload = jsmin.jsmin(js_payload).replace('"', '\\"').replace("\n", "").replace("\r", "")

        # Get the event payload.
        browser_payload = self.utils.load_file(os.path.join(module['path'], 'templates', 'browser-window-focus.js'))

        browser_param = 'bWindow'
        if self.utils.event_exists(file_contents, 'app.on', 'browser-window-focus'):
            # We need to get the name of the 'browser' variable.
            function_definition = self.utils.get_function_definition(file_contents, 'app.on', 'browser-window-focus')
            browser_param = self.utils.get_function_positional_argument(function_definition, 2)

        browser_payload = browser_payload.replace('%BROWSER_WINDOW%', browser_param)

        payload = browser_payload.replace('%PAYLOAD%', js_payload)

        file_contents = self.utils.inject_code(file_contents, 'app.on', 'browser-window-focus', payload, "app.on('browser-window-focus', function (event, bWindow) {\n\n%FUNCTION_CODE%\n\n});")

        certificate_payload = self.utils.load_file(os.path.join(module['path'], 'templates', 'certificate-error.js'))
        file_contents = self.utils.inject_code(file_contents, 'app.on', 'certificate-error', certificate_payload, "app.on('certificate-error', (event, webContents, url, error, certificate, callback) => { %FUNCTION_CODE% });")

        with open(file_to_inject, 'w') as f:
            f.write(file_contents)

        return True 
开发者ID:ctxis,项目名称:beemka,代码行数:43,代码来源:worker.py

示例13: minify_js_file

# 需要导入模块: import jsmin [as 别名]
# 或者: from jsmin import jsmin [as 别名]
def minify_js_file(js_file, jsmin_func):
    return jsmin_func(js_file, quote_chars="'\"`") 
开发者ID:vstconsulting,项目名称:polemarch,代码行数:4,代码来源:setup.py

示例14: minify_static_files

# 需要导入模块: import jsmin [as 别名]
# 或者: from jsmin import jsmin [as 别名]
def minify_static_files(base_dir, files, exclude=None):
    exclude = exclude or []
    patterns = dict()
    try:
        from jsmin import jsmin as jsmin_func
        patterns['*.js'] = (minify_js_file, jsmin_func)
    except:
        pass
    try:
        from csscompressor import compress as csscompressor_func
        patterns['*.css'] = (minify_css_file, csscompressor_func)
    except:
        pass

    regex_exclude = [re.compile(r, re.MULTILINE) for r in exclude]

    for fnext, funcs in patterns.items():
        for fext_file in filter(lambda f: fnmatch.fnmatch(f, fnext), files):
            if fnmatch.fnmatch(fext_file, '*.min.*'):
                continue
            fext_file = os.path.join(base_dir, fext_file)
            if os.path.exists(fext_file):
                if not any(filter(lambda fp: bool(fp.search(fext_file)), regex_exclude)):
                    func, subfunc = funcs
                    with codecs.open(fext_file, 'r', encoding='utf-8') as static_file_fd:
                        minified = func(static_file_fd.read(), subfunc)
                    with codecs.open(fext_file, 'w', encoding='utf-8') as static_file_fd:
                        static_file_fd.write(minified)
                    print('Minfied file {fext_file}.'.format(fext_file=fext_file))
                with open(fext_file, 'rb') as f_in:
                    with gzip.open("{}.gz".format(fext_file), 'wb') as f_out:
                        shutil.copyfileobj(f_in, f_out)
                print('Compressed file {fext_file}.'.format(fext_file=fext_file)) 
开发者ID:vstconsulting,项目名称:polemarch,代码行数:35,代码来源:setup.py

示例15: _minify

# 需要导入模块: import jsmin [as 别名]
# 或者: from jsmin import jsmin [as 别名]
def _minify(self, js):
        return jsmin.jsmin(js) 
开发者ID:V1EngineeringInc,项目名称:V1EngineeringInc-Docs,代码行数:4,代码来源:test.py


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