當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。