Best Python code snippet using localstack_python
ContentProviders.js
Source:ContentProviders.js  
1/*2 * Copyright (C) 2011 Google Inc. All rights reserved.3 *4 * Redistribution and use in source and binary forms, with or without5 * modification, are permitted provided that the following conditions are6 * met:7 *8 *     * Redistributions of source code must retain the above copyright9 * notice, this list of conditions and the following disclaimer.10 *     * Redistributions in binary form must reproduce the above11 * copyright notice, this list of conditions and the following disclaimer12 * in the documentation and/or other materials provided with the13 * distribution.14 *     * Neither the name of Google Inc. nor the names of its15 * contributors may be used to endorse or promote products derived from16 * this software without specific prior written permission.17 *18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.29 */30/**31 * @constructor32 * @implements {WebInspector.ContentProvider}33 * @param {!Array.<!WebInspector.Script>} scripts34 */35WebInspector.ConcatenatedScriptsContentProvider = function(scripts)36{37    this._scripts = scripts;38}39WebInspector.ConcatenatedScriptsContentProvider.scriptOpenTag = "<script>";40WebInspector.ConcatenatedScriptsContentProvider.scriptCloseTag = "</script>";41WebInspector.ConcatenatedScriptsContentProvider.prototype = {42    /**43     * @return {!Array.<!WebInspector.Script>}44     */45    _sortedScripts: function()46    {47        if (this._sortedScriptsArray)48            return this._sortedScriptsArray;49        this._sortedScriptsArray = [];50        var scripts = this._scripts.slice();51        scripts.sort(function(x, y) { return x.lineOffset - y.lineOffset || x.columnOffset - y.columnOffset; });52        var scriptOpenTagLength = WebInspector.ConcatenatedScriptsContentProvider.scriptOpenTag.length;53        var scriptCloseTagLength = WebInspector.ConcatenatedScriptsContentProvider.scriptCloseTag.length;54        this._sortedScriptsArray.push(scripts[0]);55        for (var i = 1; i < scripts.length; ++i) {56            var previousScript = this._sortedScriptsArray[this._sortedScriptsArray.length - 1];57            var lineNumber = previousScript.endLine;58            var columnNumber = previousScript.endColumn + scriptCloseTagLength + scriptOpenTagLength;59            if (lineNumber < scripts[i].lineOffset || (lineNumber === scripts[i].lineOffset && columnNumber <= scripts[i].columnOffset))60                this._sortedScriptsArray.push(scripts[i]);61        }62        return this._sortedScriptsArray;63    },64    /**65     * @override66     * @return {string}67     */68    contentURL: function()69    {70        return "";71    },72    /**73     * @override74     * @return {!WebInspector.ResourceType}75     */76    contentType: function()77    {78        return WebInspector.resourceTypes.Document;79    },80    /**81     * @override82     * @param {function(?string)} callback83     */84    requestContent: function(callback)85    {86        var scripts = this._sortedScripts();87        var sources = [];88        /**89         * @param {?string} content90         * @this {WebInspector.ConcatenatedScriptsContentProvider}91         */92        function didRequestSource(content)93        {94            sources.push(content);95            if (sources.length == scripts.length)96                callback(this._concatenateScriptsContent(scripts, sources));97        }98        for (var i = 0; i < scripts.length; ++i)99            scripts[i].requestContent(didRequestSource.bind(this));100    },101    /**102     * @override103     * @param {string} query104     * @param {boolean} caseSensitive105     * @param {boolean} isRegex106     * @param {function(!Array.<!WebInspector.ContentProvider.SearchMatch>)} callback107     */108    searchInContent: function(query, caseSensitive, isRegex, callback)109    {110        var results = {};111        var scripts = this._sortedScripts();112        var scriptsLeft = scripts.length;113        function maybeCallback()114        {115            if (scriptsLeft)116                return;117            var result = [];118            for (var i = 0; i < scripts.length; ++i)119                result = result.concat(results[scripts[i].scriptId]);120            callback(result);121        }122        /**123         * @param {!WebInspector.Script} script124         * @param {!Array.<!DebuggerAgent.SearchMatch>} searchMatches125         */126        function searchCallback(script, searchMatches)127        {128            results[script.scriptId] = [];129            for (var i = 0; i < searchMatches.length; ++i) {130                var searchMatch = new WebInspector.ContentProvider.SearchMatch(searchMatches[i].lineNumber + script.lineOffset, searchMatches[i].lineContent);131                results[script.scriptId].push(searchMatch);132            }133            scriptsLeft--;134            maybeCallback();135        }136        maybeCallback();137        for (var i = 0; i < scripts.length; ++i)138            scripts[i].searchInContent(query, caseSensitive, isRegex, searchCallback.bind(null, scripts[i]));139    },140    /**141     * @return {string}142     */143    _concatenateScriptsContent: function(scripts, sources)144    {145        var content = "";146        var lineNumber = 0;147        var columnNumber = 0;148        var scriptOpenTag = WebInspector.ConcatenatedScriptsContentProvider.scriptOpenTag;149        var scriptCloseTag = WebInspector.ConcatenatedScriptsContentProvider.scriptCloseTag;150        for (var i = 0; i < scripts.length; ++i) {151            // Fill the gap with whitespace characters.152            for (var newLinesCount = scripts[i].lineOffset - lineNumber; newLinesCount > 0; --newLinesCount) {153                columnNumber = 0;154                content += "\n";155            }156            for (var spacesCount = scripts[i].columnOffset - columnNumber - scriptOpenTag.length; spacesCount > 0; --spacesCount)157                content += " ";158            // Add script tag.159            content += scriptOpenTag;160            content += sources[i];161            content += scriptCloseTag;162            lineNumber = scripts[i].endLine;163            columnNumber = scripts[i].endColumn + scriptCloseTag.length;164        }165        return content;166    }167}168/**169 * @constructor170 * @implements {WebInspector.ContentProvider}171 * @param {string} sourceURL172 * @param {!WebInspector.ResourceType} contentType173 */174WebInspector.CompilerSourceMappingContentProvider = function(sourceURL, contentType)175{176    this._sourceURL = sourceURL;177    this._contentType = contentType;178}179WebInspector.CompilerSourceMappingContentProvider.prototype = {180    /**181     * @override182     * @return {string}183     */184    contentURL: function()185    {186        return this._sourceURL;187    },188    /**189     * @override190     * @return {!WebInspector.ResourceType}191     */192    contentType: function()193    {194        return this._contentType;195    },196    /**197     * @override198     * @param {function(?string)} callback199     */200    requestContent: function(callback)201    {202        WebInspector.ResourceLoader.loadUsingTargetUA(this._sourceURL, {}, contentLoaded.bind(this));203        /**204         * @param {number} statusCode205         * @param {!Object.<string, string>} headers206         * @param {string} content207         * @this {WebInspector.CompilerSourceMappingContentProvider}208         */209        function contentLoaded(statusCode, headers, content)210        {211            if (statusCode >= 400) {212                console.error("Could not load content for " + this._sourceURL + " : " + "HTTP status code: " + statusCode);213                callback(null);214                return;215            }216            callback(content);217        }218    },219    /**220     * @override221     * @param {string} query222     * @param {boolean} caseSensitive223     * @param {boolean} isRegex224     * @param {function(!Array.<!WebInspector.ContentProvider.SearchMatch>)} callback225     */226    searchInContent: function(query, caseSensitive, isRegex, callback)227    {228        this.requestContent(contentLoaded);229        /**230         * @param {?string} content231         */232        function contentLoaded(content)233        {234            if (typeof content !== "string") {235                callback([]);236                return;237            }238            callback(WebInspector.ContentProvider.performSearchInContent(content, query, caseSensitive, isRegex));239        }240    }...run-script.js
Source:run-script.js  
1module.exports = runScript2var lifecycle = require('./utils/lifecycle.js')3var npm = require('./npm.js')4var path = require('path')5var readJson = require('read-package-json')6var log = require('npmlog')7var chain = require('slide').chain8var usage = require('./utils/usage')9var output = require('./utils/output.js')10runScript.usage = usage(11  'run-script',12  'npm run-script <command> [-- <args>...]'13)14runScript.completion = function (opts, cb) {15  // see if there's already a package specified.16  var argv = opts.conf.argv.remain17  if (argv.length >= 4) return cb()18  if (argv.length === 3) {19    // either specified a script locally, in which case, done,20    // or a package, in which case, complete against its scripts21    var json = path.join(npm.localPrefix, 'package.json')22    return readJson(json, function (er, d) {23      if (er && er.code !== 'ENOENT' && er.code !== 'ENOTDIR') return cb(er)24      if (er) d = {}25      var scripts = Object.keys(d.scripts || {})26      console.error('local scripts', scripts)27      if (scripts.indexOf(argv[2]) !== -1) return cb()28      // ok, try to find out which package it was, then29      var pref = npm.config.get('global') ? npm.config.get('prefix')30               : npm.localPrefix31      var pkgDir = path.resolve(pref, 'node_modules', argv[2], 'package.json')32      readJson(pkgDir, function (er, d) {33        if (er && er.code !== 'ENOENT' && er.code !== 'ENOTDIR') return cb(er)34        if (er) d = {}35        var scripts = Object.keys(d.scripts || {})36        return cb(null, scripts)37      })38    })39  }40  readJson(path.join(npm.localPrefix, 'package.json'), function (er, d) {41    if (er && er.code !== 'ENOENT' && er.code !== 'ENOTDIR') return cb(er)42    d = d || {}43    cb(null, Object.keys(d.scripts || {}))44  })45}46function runScript (args, cb) {47  if (!args.length) return list(cb)48  var pkgdir = npm.localPrefix49  var cmd = args.shift()50  readJson(path.resolve(pkgdir, 'package.json'), function (er, d) {51    if (er) return cb(er)52    run(d, pkgdir, cmd, args, cb)53  })54}55function list (cb) {56  var json = path.join(npm.localPrefix, 'package.json')57  var cmdList = [58    'publish',59    'install',60    'uninstall',61    'test',62    'stop',63    'start',64    'restart',65    'version'66  ].reduce(function (l, p) {67    return l.concat(['pre' + p, p, 'post' + p])68  }, [])69  return readJson(json, function (er, d) {70    if (er && er.code !== 'ENOENT' && er.code !== 'ENOTDIR') return cb(er)71    if (er) d = {}72    var allScripts = Object.keys(d.scripts || {})73    var scripts = []74    var runScripts = []75    allScripts.forEach(function (script) {76      if (cmdList.indexOf(script) !== -1) scripts.push(script)77      else runScripts.push(script)78    })79    if (log.level === 'silent') {80      return cb(null, allScripts)81    }82    if (npm.config.get('json')) {83      output(JSON.stringify(d.scripts || {}, null, 2))84      return cb(null, allScripts)85    }86    if (npm.config.get('parseable')) {87      allScripts.forEach(function (script) {88        output(script + ':' + d.scripts[script])89      })90      return cb(null, allScripts)91    }92    var s = '\n    '93    var prefix = '  '94    if (scripts.length) {95      output('Lifecycle scripts included in %s:', d.name)96    }97    scripts.forEach(function (script) {98      output(prefix + script + s + d.scripts[script])99    })100    if (!scripts.length && runScripts.length) {101      output('Scripts available in %s via `npm run-script`:', d.name)102    } else if (runScripts.length) {103      output('\navailable via `npm run-script`:')104    }105    runScripts.forEach(function (script) {106      output(prefix + script + s + d.scripts[script])107    })108    return cb(null, allScripts)109  })110}111function run (pkg, wd, cmd, args, cb) {112  if (!pkg.scripts) pkg.scripts = {}113  var cmds114  if (cmd === 'restart' && !pkg.scripts.restart) {115    cmds = [116      'prestop', 'stop', 'poststop',117      'restart',118      'prestart', 'start', 'poststart'119    ]120  } else {121    if (!pkg.scripts[cmd]) {122      if (cmd === 'test') {123        pkg.scripts.test = 'echo \'Error: no test specified\''124      } else if (cmd === 'env') {125        if (process.platform === 'win32') {126          log.verbose('run-script using default platform env: SET (Windows)')127          pkg.scripts[cmd] = 'SET'128        } else {129          log.verbose('run-script using default platform env: env (Unix)')130          pkg.scripts[cmd] = 'env'131        }132      } else if (npm.config.get('if-present')) {133        return cb(null)134      } else {135        return cb(new Error('missing script: ' + cmd))136      }137    }138    cmds = [cmd]139  }140  if (!cmd.match(/^(pre|post)/)) {141    cmds = ['pre' + cmd].concat(cmds).concat('post' + cmd)142  }143  log.verbose('run-script', cmds)144  chain(cmds.map(function (c) {145    // pass cli arguments after -- to script.146    if (pkg.scripts[c] && c === cmd) {147      pkg.scripts[c] = pkg.scripts[c] + joinArgs(args)148    }149    // when running scripts explicitly, assume that they're trusted.150    return [lifecycle, pkg, c, wd, true]151  }), cb)152}153// join arguments after '--' and pass them to script,154// handle special characters such as ', ", ' '.155function joinArgs (args) {156  var joinedArgs = ''157  args.forEach(function (arg) {158    joinedArgs += ' "' + arg.replace(/"/g, '\\"') + '"'159  })160  return joinedArgs...react-scripts_vx.x.x.js
Source:react-scripts_vx.x.x.js  
1// flow-typed signature: e71bd75d0d638a7e37ecba0a886eed5b2// flow-typed version: <<STUB>>/react-scripts_v2.1.5/flow_v0.92.13/**4 * This is an autogenerated libdef stub for:5 *6 *   'react-scripts'7 *8 * Fill this stub out by replacing all the `any` types.9 *10 * Once filled out, we encourage you to share your work with the11 * community by sending a pull request to:12 * https://github.com/flowtype/flow-typed13 */14declare module 'react-scripts' {15  declare module.exports: any;16}17/**18 * We include stubs for each file inside this npm package in case you need to19 * require those files directly. Feel free to delete any files that aren't20 * needed.21 */22declare module 'react-scripts/bin/react-scripts' {23  declare module.exports: any;24}25declare module 'react-scripts/config/env' {26  declare module.exports: any;27}28declare module 'react-scripts/config/jest/babelTransform' {29  declare module.exports: any;30}31declare module 'react-scripts/config/jest/cssTransform' {32  declare module.exports: any;33}34declare module 'react-scripts/config/jest/fileTransform' {35  declare module.exports: any;36}37declare module 'react-scripts/config/paths' {38  declare module.exports: any;39}40declare module 'react-scripts/config/webpack.config' {41  declare module.exports: any;42}43declare module 'react-scripts/config/webpackDevServer.config' {44  declare module.exports: any;45}46declare module 'react-scripts/scripts/build' {47  declare module.exports: any;48}49declare module 'react-scripts/scripts/eject' {50  declare module.exports: any;51}52declare module 'react-scripts/scripts/init' {53  declare module.exports: any;54}55declare module 'react-scripts/scripts/start' {56  declare module.exports: any;57}58declare module 'react-scripts/scripts/test' {59  declare module.exports: any;60}61declare module 'react-scripts/scripts/utils/createJestConfig' {62  declare module.exports: any;63}64declare module 'react-scripts/scripts/utils/verifyPackageTree' {65  declare module.exports: any;66}67declare module 'react-scripts/scripts/utils/verifyTypeScriptSetup' {68  declare module.exports: any;69}70declare module 'react-scripts/template/src/App' {71  declare module.exports: any;72}73declare module 'react-scripts/template/src/App.test' {74  declare module.exports: any;75}76declare module 'react-scripts/template/src/index' {77  declare module.exports: any;78}79declare module 'react-scripts/template/src/serviceWorker' {80  declare module.exports: any;81}82// Filename aliases83declare module 'react-scripts/bin/react-scripts.js' {84  declare module.exports: $Exports<'react-scripts/bin/react-scripts'>;85}86declare module 'react-scripts/config/env.js' {87  declare module.exports: $Exports<'react-scripts/config/env'>;88}89declare module 'react-scripts/config/jest/babelTransform.js' {90  declare module.exports: $Exports<'react-scripts/config/jest/babelTransform'>;91}92declare module 'react-scripts/config/jest/cssTransform.js' {93  declare module.exports: $Exports<'react-scripts/config/jest/cssTransform'>;94}95declare module 'react-scripts/config/jest/fileTransform.js' {96  declare module.exports: $Exports<'react-scripts/config/jest/fileTransform'>;97}98declare module 'react-scripts/config/paths.js' {99  declare module.exports: $Exports<'react-scripts/config/paths'>;100}101declare module 'react-scripts/config/webpack.config.js' {102  declare module.exports: $Exports<'react-scripts/config/webpack.config'>;103}104declare module 'react-scripts/config/webpackDevServer.config.js' {105  declare module.exports: $Exports<'react-scripts/config/webpackDevServer.config'>;106}107declare module 'react-scripts/scripts/build.js' {108  declare module.exports: $Exports<'react-scripts/scripts/build'>;109}110declare module 'react-scripts/scripts/eject.js' {111  declare module.exports: $Exports<'react-scripts/scripts/eject'>;112}113declare module 'react-scripts/scripts/init.js' {114  declare module.exports: $Exports<'react-scripts/scripts/init'>;115}116declare module 'react-scripts/scripts/start.js' {117  declare module.exports: $Exports<'react-scripts/scripts/start'>;118}119declare module 'react-scripts/scripts/test.js' {120  declare module.exports: $Exports<'react-scripts/scripts/test'>;121}122declare module 'react-scripts/scripts/utils/createJestConfig.js' {123  declare module.exports: $Exports<'react-scripts/scripts/utils/createJestConfig'>;124}125declare module 'react-scripts/scripts/utils/verifyPackageTree.js' {126  declare module.exports: $Exports<'react-scripts/scripts/utils/verifyPackageTree'>;127}128declare module 'react-scripts/scripts/utils/verifyTypeScriptSetup.js' {129  declare module.exports: $Exports<'react-scripts/scripts/utils/verifyTypeScriptSetup'>;130}131declare module 'react-scripts/template/src/App.js' {132  declare module.exports: $Exports<'react-scripts/template/src/App'>;133}134declare module 'react-scripts/template/src/App.test.js' {135  declare module.exports: $Exports<'react-scripts/template/src/App.test'>;136}137declare module 'react-scripts/template/src/index.js' {138  declare module.exports: $Exports<'react-scripts/template/src/index'>;139}140declare module 'react-scripts/template/src/serviceWorker.js' {141  declare module.exports: $Exports<'react-scripts/template/src/serviceWorker'>;...Debugger-findScripts-08.js
Source:Debugger-findScripts-08.js  
1// Debugger.prototype.findScripts can filter scripts by URL.2var g1 = newGlobal('new-compartment');3var g2 = newGlobal('new-compartment');4var g3 = newGlobal('new-compartment');5// Define some functions whose url will be this test file.6g1.eval('function g1f() {}');7g2.eval('function g2f() {}');8// Define some functions whose url will be a different file.9url2 = scriptdir + "Debugger-findScripts-08-script2";10load(url2);11var dbg = new Debugger(g1, g2, g3);12var g1fw = dbg.addDebuggee(g1.g1f);13var g1gw = dbg.addDebuggee(g1.g1g);14var g2fw = dbg.addDebuggee(g2.g2f);15var g2gw = dbg.addDebuggee(g2.g2g);16// Find the url of this file.17url = g1fw.script.url;18var scripts;19scripts = dbg.findScripts({});20assertEq(scripts.indexOf(g1fw.script) != -1, true);21assertEq(scripts.indexOf(g1gw.script) != -1, true);22assertEq(scripts.indexOf(g2fw.script) != -1, true);23assertEq(scripts.indexOf(g2gw.script) != -1, true);24scripts = dbg.findScripts({url:url});25assertEq(scripts.indexOf(g1fw.script) != -1, true);26assertEq(scripts.indexOf(g1gw.script) != -1, false);27assertEq(scripts.indexOf(g2fw.script) != -1, true);28assertEq(scripts.indexOf(g2gw.script) != -1, false);29scripts = dbg.findScripts({url:url2});30assertEq(scripts.indexOf(g1fw.script) != -1, false);31assertEq(scripts.indexOf(g1gw.script) != -1, true);32assertEq(scripts.indexOf(g2fw.script) != -1, false);33assertEq(scripts.indexOf(g2gw.script) != -1, true);34scripts = dbg.findScripts({url:url, global:g1});35assertEq(scripts.indexOf(g1fw.script) != -1, true);36assertEq(scripts.indexOf(g1gw.script) != -1, false);37assertEq(scripts.indexOf(g2fw.script) != -1, false);38assertEq(scripts.indexOf(g2gw.script) != -1, false);39scripts = dbg.findScripts({url:url2, global:g1});40assertEq(scripts.indexOf(g1fw.script) != -1, false);41assertEq(scripts.indexOf(g1gw.script) != -1, true);42assertEq(scripts.indexOf(g2fw.script) != -1, false);43assertEq(scripts.indexOf(g2gw.script) != -1, false);44scripts = dbg.findScripts({url:url, global:g2});45assertEq(scripts.indexOf(g1fw.script) != -1, false);46assertEq(scripts.indexOf(g1gw.script) != -1, false);47assertEq(scripts.indexOf(g2fw.script) != -1, true);48assertEq(scripts.indexOf(g2gw.script) != -1, false);49scripts = dbg.findScripts({url:url2, global:g2});50assertEq(scripts.indexOf(g1fw.script) != -1, false);51assertEq(scripts.indexOf(g1gw.script) != -1, false);52assertEq(scripts.indexOf(g2fw.script) != -1, false);53assertEq(scripts.indexOf(g2gw.script) != -1, true);54scripts = dbg.findScripts({url:"xlerb"}); // "XLERB"???55assertEq(scripts.indexOf(g1fw.script) != -1, false);56assertEq(scripts.indexOf(g1gw.script) != -1, false);57assertEq(scripts.indexOf(g2fw.script) != -1, false);58assertEq(scripts.indexOf(g2gw.script) != -1, false);59scripts = dbg.findScripts({url:url, global:g3});60assertEq(scripts.indexOf(g1fw.script) != -1, false);61assertEq(scripts.indexOf(g1gw.script) != -1, false);62assertEq(scripts.indexOf(g2fw.script) != -1, false);...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
