[
  {
    "path": ".coveragerc",
    "content": "[run]\nbranch = True\nsource = jupyter_spark\n\n[paths]\nsource =\n   .tox/*/lib/python*/site-packages/jupyter_spark\n   .tox/pypy*/site-packages/jupyter_spark\n\n[report]\nshow_missing = True\n"
  },
  {
    "path": ".eslintrc.json",
    "content": "{\n    \"env\": {\n        \"browser\": true,\n        \"jquery\": true,\n        \"amd\": true\n    },\n    \"plugins\": [\n        \"amd-imports\"\n    ],\n    \"extends\": \"eslint:recommended\",\n    \"rules\": {\n        \"indent\": [\n            \"error\",\n            4\n        ],\n        \"linebreak-style\": [\n            \"error\",\n            \"unix\"\n        ]\n    }\n}\n"
  },
  {
    "path": ".gitignore",
    "content": "# Byte-compiled / optimized / DLL files\n__pycache__/\n*.py[cod]\n*$py.class\n\n# C extensions\n*.so\n\n# Distribution / packaging\n.Python\nenv/\nbuild/\ndevelop-eggs/\ndist/\ndownloads/\neggs/\n.eggs/\nlib/\nlib64/\nparts/\nsdist/\nvar/\n*.egg-info/\n.installed.cfg\n*.egg\n\n# PyInstaller\n#  Usually these files are written by a python script from a template\n#  before PyInstaller builds the exe, so as to inject date/other infos into it.\n*.manifest\n*.spec\n\n# Installer logs\npip-log.txt\npip-delete-this-directory.txt\n\n# Unit test / coverage reports\nhtmlcov/\n.tox/\n.coverage\n.coverage.*\n.cache\nnosetests.xml\ncoverage.xml\n*,cover\n.hypothesis/\n\n# Translations\n*.mo\n*.pot\n\n# Django stuff:\n*.log\n\n# Sphinx documentation\ndocs/_build/\n\n# PyBuilder\ntarget/\n\n#Ipython Notebook\n.ipynb_checkpoints\n\nnode_modules/\n"
  },
  {
    "path": ".travis.yml",
    "content": "language: python\nsudo: false\ncache: pip\npython:\n- '2.7'\n- '3.4'\n- '3.5'\n- '3.6'\n- pypy\ninstall:\n- pip install tox-travis\nscript:\n- tox -v\nafter_success:\n- bash <(curl -s https://codecov.io/bash)\njobs:\n  include:\n    - stage: deploy\n      python: '3.5'\n      script: skip\n      deploy:\n        provider: pypi\n        user: jezdez\n        distributions: sdist bdist_wheel\n        password:\n          secure: 0WAa8nmsv3VE/sKgd6AYLXJFujUe0YSo11shN2G7EarVlB/d0TLdU/ZyY5C5ClKutMTgnjlcpaCzgImMh86tA0W0lb3n2o5M7ssyIbOqKSIUPZBOFmqFJ2F9Wy01Woj0V+gQx6gS5U7lntTjNFbYnycH801FXrhub0ZMLynDO5y5fy2p91Qu9qMOs+gahSyb0KrkzQCXXLlaqwhmKAwfYj0JjrEuKTe/ltRlz/Ffw01cpJJoU2j+SophMCcd4taM4ESW0eAuXjDf3XmxZY2oSYTEDIhJATmgi3Y+I7TxI5N9/PJSyeuVnxP2uL+rs1iaZWWBD2SJPO4jvlliUwbapOqZG7MSP15OaGeKST6vSdxLp17zFXVhXSXOhUJTFQ1uPtmddt9hTNTnQbXcZRLz1oqomSt39+f/MH7RhAEJiqL+7qJPtp3AtFDX0AW/LBvgNO4i0tc3RxCIF00urMTHgk8HHKUa7wGEJ6R5qmNClihu2KkVNqRIGAATe7VDwqr990IADGl1cGL5yy+HTj2GtCdLPaxJuz9/Pv3YNUFusWbL4YXQQqxPRS3dSoUZ0zYEW8KGJsAMCpWJYyvUkzLnub3GZTm79Pty6PiNuuO3kmu/wSjztYgc0cfPygJdIy9Xw6j9qM4JT6oBVyA1vOFXIJ4IeFcq/wvQANXsBClpzqQ=\n        on:\n          tags: true\n          repo: mozilla/jupyter-spark\nmatrix:\n  include:\n  - env: eslint\n    sudo: false\n    cache:\n      directories:\n      - node_modules # NPM packages\n    install:\n      - nvm install 8\n      - npm install\n    script:\n      - node ./node_modules/eslint/bin/eslint.js --ext .js src/jupyter_spark/static\nallow_failures:\n  - env: eslint\n"
  },
  {
    "path": "CODE_OF_CONDUCT.md",
    "content": "# Community Participation Guidelines\n\nThis repository is governed by Mozilla's code of conduct and etiquette guidelines. \nFor more details, please read the\n[Mozilla Community Participation Guidelines](https://www.mozilla.org/about/governance/policies/participation/). \n\n## How to Report\nFor more information on how to report violations of the Community Participation Guidelines, please read our '[How to Report](https://www.mozilla.org/about/governance/policies/participation/reporting/)' page.\n"
  },
  {
    "path": "LICENSE",
    "content": "Mozilla Public License Version 2.0\n==================================\n\n1. Definitions\n--------------\n\n1.1. \"Contributor\"\n    means each individual or legal entity that creates, contributes to\n    the creation of, or owns Covered Software.\n\n1.2. \"Contributor Version\"\n    means the combination of the Contributions of others (if any) used\n    by a Contributor and that particular Contributor's Contribution.\n\n1.3. \"Contribution\"\n    means Covered Software of a particular Contributor.\n\n1.4. \"Covered Software\"\n    means Source Code Form to which the initial Contributor has attached\n    the notice in Exhibit A, the Executable Form of such Source Code\n    Form, and Modifications of such Source Code Form, in each case\n    including portions thereof.\n\n1.5. \"Incompatible With Secondary Licenses\"\n    means\n\n    (a) that the initial Contributor has attached the notice described\n        in Exhibit B to the Covered Software; or\n\n    (b) that the Covered Software was made available under the terms of\n        version 1.1 or earlier of the License, but not also under the\n        terms of a Secondary License.\n\n1.6. \"Executable Form\"\n    means any form of the work other than Source Code Form.\n\n1.7. \"Larger Work\"\n    means a work that combines Covered Software with other material, in\n    a separate file or files, that is not Covered Software.\n\n1.8. \"License\"\n    means this document.\n\n1.9. \"Licensable\"\n    means having the right to grant, to the maximum extent possible,\n    whether at the time of the initial grant or subsequently, any and\n    all of the rights conveyed by this License.\n\n1.10. \"Modifications\"\n    means any of the following:\n\n    (a) any file in Source Code Form that results from an addition to,\n        deletion from, or modification of the contents of Covered\n        Software; or\n\n    (b) any new file in Source Code Form that contains any Covered\n        Software.\n\n1.11. \"Patent Claims\" of a Contributor\n    means any patent claim(s), including without limitation, method,\n    process, and apparatus claims, in any patent Licensable by such\n    Contributor that would be infringed, but for the grant of the\n    License, by the making, using, selling, offering for sale, having\n    made, import, or transfer of either its Contributions or its\n    Contributor Version.\n\n1.12. \"Secondary License\"\n    means either the GNU General Public License, Version 2.0, the GNU\n    Lesser General Public License, Version 2.1, the GNU Affero General\n    Public License, Version 3.0, or any later versions of those\n    licenses.\n\n1.13. \"Source Code Form\"\n    means the form of the work preferred for making modifications.\n\n1.14. \"You\" (or \"Your\")\n    means an individual or a legal entity exercising rights under this\n    License. For legal entities, \"You\" includes any entity that\n    controls, is controlled by, or is under common control with You. For\n    purposes of this definition, \"control\" means (a) the power, direct\n    or indirect, to cause the direction or management of such entity,\n    whether by contract or otherwise, or (b) ownership of more than\n    fifty percent (50%) of the outstanding shares or beneficial\n    ownership of such entity.\n\n2. License Grants and Conditions\n--------------------------------\n\n2.1. Grants\n\nEach Contributor hereby grants You a world-wide, royalty-free,\nnon-exclusive license:\n\n(a) under intellectual property rights (other than patent or trademark)\n    Licensable by such Contributor to use, reproduce, make available,\n    modify, display, perform, distribute, and otherwise exploit its\n    Contributions, either on an unmodified basis, with Modifications, or\n    as part of a Larger Work; and\n\n(b) under Patent Claims of such Contributor to make, use, sell, offer\n    for sale, have made, import, and otherwise transfer either its\n    Contributions or its Contributor Version.\n\n2.2. Effective Date\n\nThe licenses granted in Section 2.1 with respect to any Contribution\nbecome effective for each Contribution on the date the Contributor first\ndistributes such Contribution.\n\n2.3. Limitations on Grant Scope\n\nThe licenses granted in this Section 2 are the only rights granted under\nthis License. No additional rights or licenses will be implied from the\ndistribution or licensing of Covered Software under this License.\nNotwithstanding Section 2.1(b) above, no patent license is granted by a\nContributor:\n\n(a) for any code that a Contributor has removed from Covered Software;\n    or\n\n(b) for infringements caused by: (i) Your and any other third party's\n    modifications of Covered Software, or (ii) the combination of its\n    Contributions with other software (except as part of its Contributor\n    Version); or\n\n(c) under Patent Claims infringed by Covered Software in the absence of\n    its Contributions.\n\nThis License does not grant any rights in the trademarks, service marks,\nor logos of any Contributor (except as may be necessary to comply with\nthe notice requirements in Section 3.4).\n\n2.4. Subsequent Licenses\n\nNo Contributor makes additional grants as a result of Your choice to\ndistribute the Covered Software under a subsequent version of this\nLicense (see Section 10.2) or under the terms of a Secondary License (if\npermitted under the terms of Section 3.3).\n\n2.5. Representation\n\nEach Contributor represents that the Contributor believes its\nContributions are its original creation(s) or it has sufficient rights\nto grant the rights to its Contributions conveyed by this License.\n\n2.6. Fair Use\n\nThis License is not intended to limit any rights You have under\napplicable copyright doctrines of fair use, fair dealing, or other\nequivalents.\n\n2.7. Conditions\n\nSections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted\nin Section 2.1.\n\n3. Responsibilities\n-------------------\n\n3.1. Distribution of Source Form\n\nAll distribution of Covered Software in Source Code Form, including any\nModifications that You create or to which You contribute, must be under\nthe terms of this License. You must inform recipients that the Source\nCode Form of the Covered Software is governed by the terms of this\nLicense, and how they can obtain a copy of this License. You may not\nattempt to alter or restrict the recipients' rights in the Source Code\nForm.\n\n3.2. Distribution of Executable Form\n\nIf You distribute Covered Software in Executable Form then:\n\n(a) such Covered Software must also be made available in Source Code\n    Form, as described in Section 3.1, and You must inform recipients of\n    the Executable Form how they can obtain a copy of such Source Code\n    Form by reasonable means in a timely manner, at a charge no more\n    than the cost of distribution to the recipient; and\n\n(b) You may distribute such Executable Form under the terms of this\n    License, or sublicense it under different terms, provided that the\n    license for the Executable Form does not attempt to limit or alter\n    the recipients' rights in the Source Code Form under this License.\n\n3.3. Distribution of a Larger Work\n\nYou may create and distribute a Larger Work under terms of Your choice,\nprovided that You also comply with the requirements of this License for\nthe Covered Software. If the Larger Work is a combination of Covered\nSoftware with a work governed by one or more Secondary Licenses, and the\nCovered Software is not Incompatible With Secondary Licenses, this\nLicense permits You to additionally distribute such Covered Software\nunder the terms of such Secondary License(s), so that the recipient of\nthe Larger Work may, at their option, further distribute the Covered\nSoftware under the terms of either this License or such Secondary\nLicense(s).\n\n3.4. Notices\n\nYou may not remove or alter the substance of any license notices\n(including copyright notices, patent notices, disclaimers of warranty,\nor limitations of liability) contained within the Source Code Form of\nthe Covered Software, except that You may alter any license notices to\nthe extent required to remedy known factual inaccuracies.\n\n3.5. Application of Additional Terms\n\nYou may choose to offer, and to charge a fee for, warranty, support,\nindemnity or liability obligations to one or more recipients of Covered\nSoftware. However, You may do so only on Your own behalf, and not on\nbehalf of any Contributor. You must make it absolutely clear that any\nsuch warranty, support, indemnity, or liability obligation is offered by\nYou alone, and You hereby agree to indemnify every Contributor for any\nliability incurred by such Contributor as a result of warranty, support,\nindemnity or liability terms You offer. You may include additional\ndisclaimers of warranty and limitations of liability specific to any\njurisdiction.\n\n4. Inability to Comply Due to Statute or Regulation\n---------------------------------------------------\n\nIf it is impossible for You to comply with any of the terms of this\nLicense with respect to some or all of the Covered Software due to\nstatute, judicial order, or regulation then You must: (a) comply with\nthe terms of this License to the maximum extent possible; and (b)\ndescribe the limitations and the code they affect. Such description must\nbe placed in a text file included with all distributions of the Covered\nSoftware under this License. Except to the extent prohibited by statute\nor regulation, such description must be sufficiently detailed for a\nrecipient of ordinary skill to be able to understand it.\n\n5. Termination\n--------------\n\n5.1. The rights granted under this License will terminate automatically\nif You fail to comply with any of its terms. However, if You become\ncompliant, then the rights granted under this License from a particular\nContributor are reinstated (a) provisionally, unless and until such\nContributor explicitly and finally terminates Your grants, and (b) on an\nongoing basis, if such Contributor fails to notify You of the\nnon-compliance by some reasonable means prior to 60 days after You have\ncome back into compliance. Moreover, Your grants from a particular\nContributor are reinstated on an ongoing basis if such Contributor\nnotifies You of the non-compliance by some reasonable means, this is the\nfirst time You have received notice of non-compliance with this License\nfrom such Contributor, and You become compliant prior to 30 days after\nYour receipt of the notice.\n\n5.2. If You initiate litigation against any entity by asserting a patent\ninfringement claim (excluding declaratory judgment actions,\ncounter-claims, and cross-claims) alleging that a Contributor Version\ndirectly or indirectly infringes any patent, then the rights granted to\nYou by any and all Contributors for the Covered Software under Section\n2.1 of this License shall terminate.\n\n5.3. In the event of termination under Sections 5.1 or 5.2 above, all\nend user license agreements (excluding distributors and resellers) which\nhave been validly granted by You or Your distributors under this License\nprior to termination shall survive termination.\n\n************************************************************************\n*                                                                      *\n*  6. Disclaimer of Warranty                                           *\n*  -------------------------                                           *\n*                                                                      *\n*  Covered Software is provided under this License on an \"as is\"       *\n*  basis, without warranty of any kind, either expressed, implied, or  *\n*  statutory, including, without limitation, warranties that the       *\n*  Covered Software is free of defects, merchantable, fit for a        *\n*  particular purpose or non-infringing. The entire risk as to the     *\n*  quality and performance of the Covered Software is with You.        *\n*  Should any Covered Software prove defective in any respect, You     *\n*  (not any Contributor) assume the cost of any necessary servicing,   *\n*  repair, or correction. This disclaimer of warranty constitutes an   *\n*  essential part of this License. No use of any Covered Software is   *\n*  authorized under this License except under this disclaimer.         *\n*                                                                      *\n************************************************************************\n\n************************************************************************\n*                                                                      *\n*  7. Limitation of Liability                                          *\n*  --------------------------                                          *\n*                                                                      *\n*  Under no circumstances and under no legal theory, whether tort      *\n*  (including negligence), contract, or otherwise, shall any           *\n*  Contributor, or anyone who distributes Covered Software as          *\n*  permitted above, be liable to You for any direct, indirect,         *\n*  special, incidental, or consequential damages of any character      *\n*  including, without limitation, damages for lost profits, loss of    *\n*  goodwill, work stoppage, computer failure or malfunction, or any    *\n*  and all other commercial damages or losses, even if such party      *\n*  shall have been informed of the possibility of such damages. This   *\n*  limitation of liability shall not apply to liability for death or   *\n*  personal injury resulting from such party's negligence to the       *\n*  extent applicable law prohibits such limitation. Some               *\n*  jurisdictions do not allow the exclusion or limitation of           *\n*  incidental or consequential damages, so this exclusion and          *\n*  limitation may not apply to You.                                    *\n*                                                                      *\n************************************************************************\n\n8. Litigation\n-------------\n\nAny litigation relating to this License may be brought only in the\ncourts of a jurisdiction where the defendant maintains its principal\nplace of business and such litigation shall be governed by laws of that\njurisdiction, without reference to its conflict-of-law provisions.\nNothing in this Section shall prevent a party's ability to bring\ncross-claims or counter-claims.\n\n9. Miscellaneous\n----------------\n\nThis License represents the complete agreement concerning the subject\nmatter hereof. If any provision of this License is held to be\nunenforceable, such provision shall be reformed only to the extent\nnecessary to make it enforceable. Any law or regulation which provides\nthat the language of a contract shall be construed against the drafter\nshall not be used to construe this License against a Contributor.\n\n10. Versions of the License\n---------------------------\n\n10.1. New Versions\n\nMozilla Foundation is the license steward. Except as provided in Section\n10.3, no one other than the license steward has the right to modify or\npublish new versions of this License. Each version will be given a\ndistinguishing version number.\n\n10.2. Effect of New Versions\n\nYou may distribute the Covered Software under the terms of the version\nof the License under which You originally received the Covered Software,\nor under the terms of any subsequent version published by the license\nsteward.\n\n10.3. Modified Versions\n\nIf you create software not governed by this License, and you want to\ncreate a new license for such software, you may create and use a\nmodified version of this License if you rename the license and remove\nany references to the name of the license steward (except to note that\nsuch modified license differs from this License).\n\n10.4. Distributing Source Code Form that is Incompatible With Secondary\nLicenses\n\nIf You choose to distribute Source Code Form that is Incompatible With\nSecondary Licenses under the terms of this version of the License, the\nnotice described in Exhibit B of this License must be attached.\n\nExhibit A - Source Code Form License Notice\n-------------------------------------------\n\n  This Source Code Form is subject to the terms of the Mozilla Public\n  License, v. 2.0. If a copy of the MPL was not distributed with this\n  file, You can obtain one at http://mozilla.org/MPL/2.0/.\n\nIf it is not possible or desirable to put the notice in a particular\nfile, then You may include the notice in a location (such as a LICENSE\nfile in a relevant directory) where a recipient would be likely to look\nfor such a notice.\n\nYou may add additional accurate notices of copyright ownership.\n\nExhibit B - \"Incompatible With Secondary Licenses\" Notice\n---------------------------------------------------------\n\n  This Source Code Form is \"Incompatible With Secondary Licenses\", as\n  defined by the Mozilla Public License, v. 2.0.\n"
  },
  {
    "path": "MANIFEST.in",
    "content": "include README.md\nrecursive-include src *.js\nrecursive-include tests *.py\nrecursive-include notebooks *.ipynb\nrecursive-include screenshots *.png\n"
  },
  {
    "path": "Makefile",
    "content": ".PHONY: install build uninstall enable clean dev\n\ninstall:\n\tjupyter serverextension enable --py jupyter_spark\n\tjupyter nbextension install --py jupyter_spark\n\tjupyter nbextension enable --py jupyter_spark\n\nuninstall:\n\tjupyter serverextension disable --py jupyter_spark\n\tjupyter nbextension disable --py jupyter_spark\n\tjupyter nbextension uninstall --py jupyter_spark\n\tpip uninstall -y jupyter-spark\n\nclean: uninstall\n\trm -rf dist/\n\nbuild: clean\n\tpython setup.py sdist\n\tpip install dist/*.tar.gz\n\ndev: build install\n\nnotebook:\n\tjupyter notebook\n"
  },
  {
    "path": "README.md",
    "content": "# jupyter-spark\n\n[![No Maintenance Intended](http://unmaintained.tech/badge.svg)](http://unmaintained.tech/)\n[![Build Status](https://travis-ci.org/mozilla/jupyter-spark.svg?branch=master)](https://travis-ci.org/mozilla/jupyter-spark)\n[![codecov](https://codecov.io/gh/mozilla/jupyter-spark/branch/master/graph/badge.svg)](https://codecov.io/gh/mozilla/jupyter-spark)\n\n**NOTE: This project is currently unmaintained, if anyone would like to take over maintenance please [let us know](https://github.com/mozilla/jupyter-spark/issues/55).**\n\nJupyter Notebook extension for Apache Spark integration.\n\nIncludes a progress indicator for the current Notebook cell if it invokes a\nSpark job. Queries the Spark UI service on the backend to get the required\nSpark job information.\n\n![Alt text](/screenshots/ProgressBar.png?raw=true \"Spark progress bar\")\n\nTo view all currently running jobs, click the \"show running Spark jobs\"\nbutton, or press ```Alt+S```.\n\n![Alt text](/screenshots/SparkButton.png?raw=true \"show running Spark jobs button\")\n\n![Alt text](/screenshots/Dialog.png?raw=true \"Spark dialog\")\n\nA proxied version of the Spark UI can be accessed at\nhttp://localhost:8888/spark.\n\n## Installation\n\nTo install, simply run:\n\n```\npip install jupyter-spark\njupyter serverextension enable --py jupyter_spark\njupyter nbextension install --py jupyter_spark\njupyter nbextension enable --py jupyter_spark\njupyter nbextension enable --py widgetsnbextension\n```\n\nThe last step is needed to enable the `widgetsnbextension` extension that\nJupyter-Spark depends on. It may have been enabled before by a different\nextension.\n\nYou may want to append ``--user`` to the commands above if you're getting\nconfiguration errors upon invoking them.\n\nTo double-check if the extension was correctly installed run:\n\n```\njupyter nbextension list\njupyter serverextension list\n```\n\nPleaes feel free to install [lxml](http://lxml.de/) as well to improve\nperformance of the server side communication to Spark using your favorite\npackage manager, e.g.:\n\n```\npip install lxml\n```\n\nFor development and testing, clone the project and run from a shell in the\nproject's root directory:\n\n```\npip install -e .\njupyter serverextension enable --py jupyter_spark\njupyter nbextension install --py jupyter_spark\njupyter nbextension enable --py jupyter_spark\n```\n\nTo uninstall the extension run:\n\n```\njupyter serverextension disable --py jupyter_spark\njupyter nbextension disable --py jupyter_spark\njupyter nbextension uninstall --py jupyter_spark\npip uninstall jupyter-spark\n```\n\n## Configuration\n\nTo change the URL of the Spark API that the job metadata is fetched from\noverride the `Spark.url` config value, e.g. on the command line:\n\n```\njupyter notebook --Spark.url=\"http://localhost:4040\"\n```\n\n## Example\n\nThere is a simple `pyspark` example included in `examples` to confirm that your\ninstallation is working.\n\n## Changelog\n\n### 0.3.0 (2016-07-04)\n\n- Rewrote proxy to use an async Tornado handler and HTTP client to fetch\n  responses from Spark.\n\n- Simplified proxy processing to take Amazon EMR proxying into account\n\n- Extended test suite to cover proxy handler, too.\n\n- Removed requests as a dependency.\n\n### 0.2.0 (2016-06-30)\n\n- Refactored to fix a bunch of Python packaging and code quality issues\n\n- Added test suite for Python code\n\n- Set up continuous integration: https://travis-ci.org/mozilla/jupyter-spark\n\n- Set up code coverage reports: https://codecov.io/gh/mozilla/jupyter-spark\n\n- Added ability to override Spark API URL via command line option\n\n- **IMPORTANT** Requires manual step to enable after running pip install\n  (see installation docs)!\n\n  To update:\n\n  1. Run `pip uninstall jupyter-spark`\n  2. Delete `spark.js` from your `nbextensions` folder.\n  3. Delete any references to `jupyter_spark.spark` in\n     `jupyter_notebook_config.json` (in your .jupyter directory)\n  4. Delete any references to `spark` in `notebook.json`\n     (in .jupyter/nbconfig)\n  5. Follow installation instructions to reinstall\n\n### 0.1.1 (2016-05-03)\n\n- Initial release with a working prototype\n"
  },
  {
    "path": "examples/Jupyter Spark example.ipynb",
    "content": "{\n \"cells\": [\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"## Example jupyter_spark notebook\\n\",\n    \"\\n\",\n    \"This is an example notebook to demonstrate the `jupyter_spark` notebook plugin.\\n\",\n    \"\\n\",\n    \"It is based on the [approximating pi](https://github.com/apache/spark/blob/master/examples/src/main/python/pi.py) example in the pyspark documentation.  This works by sampling random numbers in a square and counting the number that fall inside the unit circle.\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 1,\n   \"metadata\": {},\n   \"outputs\": [],\n   \"source\": [\n    \"import sys\\n\",\n    \"from random import random\\n\",\n    \"from operator import add\\n\",\n    \"\\n\",\n    \"from pyspark.sql import SparkSession\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"Create a `SparkSession` and give it a name.\\n\",\n    \"\\n\",\n    \"Note: This will start the spark client console -- there is no need to run `spark-shell` directly.\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 2,\n   \"metadata\": {\n    \"scrolled\": true\n   },\n   \"outputs\": [],\n   \"source\": [\n    \"spark = SparkSession \\\\\\n\",\n    \"            .builder \\\\\\n\",\n    \"            .appName(\\\"PythonPi\\\") \\\\\\n\",\n    \"            .getOrCreate()\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"`partitions` is the number of spark workers to partition the work into.\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 3,\n   \"metadata\": {},\n   \"outputs\": [],\n   \"source\": [\n    \"partitions = 2\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"`n` is the number of random samples to calculate\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 4,\n   \"metadata\": {},\n   \"outputs\": [],\n   \"source\": [\n    \"n = 100000000\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"This is the sampling function.  It generates numbers in the square from (-1, -1) to (1, 1), and returns 1 if it falls inside the unit circle, and 0 otherwise.\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 5,\n   \"metadata\": {},\n   \"outputs\": [],\n   \"source\": [\n    \"def f(_):\\n\",\n    \"    x = random() * 2 - 1\\n\",\n    \"    y = random() * 2 - 1\\n\",\n    \"    return 1 if x ** 2 + y ** 2 <= 1 else 0\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"Here's where we farm the work out to Spark.\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 6,\n   \"metadata\": {},\n   \"outputs\": [],\n   \"source\": [\n    \"count = spark.sparkContext \\\\\\n\",\n    \"    .parallelize(range(1, n + 1), partitions) \\\\\\n\",\n    \"    .map(f) \\\\\\n\",\n    \"    .reduce(add)\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 7,\n   \"metadata\": {},\n   \"outputs\": [\n    {\n     \"name\": \"stdout\",\n     \"output_type\": \"stream\",\n     \"text\": [\n      \"Pi is roughly 3.141880\\n\"\n     ]\n    }\n   ],\n   \"source\": [\n    \"print(\\\"Pi is roughly %f\\\" % (4.0 * count / n))\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"Shut down the spark server.\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 8,\n   \"metadata\": {},\n   \"outputs\": [],\n   \"source\": [\n    \"spark.stop()\"\n   ]\n  }\n ],\n \"metadata\": {\n  \"kernelspec\": {\n   \"display_name\": \"Python 3\",\n   \"language\": \"python\",\n   \"name\": \"python3\"\n  },\n  \"language_info\": {\n   \"codemirror_mode\": {\n    \"name\": \"ipython\",\n    \"version\": 3\n   },\n   \"file_extension\": \".py\",\n   \"mimetype\": \"text/x-python\",\n   \"name\": \"python\",\n   \"nbconvert_exporter\": \"python\",\n   \"pygments_lexer\": \"ipython3\",\n   \"version\": \"3.6.4\"\n  }\n },\n \"nbformat\": 4,\n \"nbformat_minor\": 2\n}\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"devDependencies\": {\n    \"eslint\": \"^4.17.0\",\n    \"eslint-plugin-amd-imports\": \"^4.0.0\"\n  }\n}\n"
  },
  {
    "path": "pytest.ini",
    "content": "[pytest]\naddopts = -v --flake8 --isort --cov-report xml --cov-report=term-missing --cov=jupyter_spark --cov-config .coveragerc\nnorecursedirs = *.egg .eggs dist build docs .tox\nflake8-ignore = E501\n"
  },
  {
    "path": "setup.cfg",
    "content": "[wheel]\nuniversal = 1\n"
  },
  {
    "path": "setup.py",
    "content": "from setuptools import find_packages, setup\n\nsetup(\n    name='jupyter-spark',\n    use_scm_version={\n        'version_scheme': 'post-release',\n        'local_scheme': 'dirty-tag'\n    },\n    setup_requires=['setuptools_scm'],\n    description='Jupyter Notebook extension for Apache Spark integration',\n    author='Mozilla Firefox Data Platform',\n    author_email='fx-data-platform@mozilla.com',\n    packages=find_packages(where='src'),\n    package_dir={'': 'src'},\n    include_package_data=True,\n    license='MPL2',\n    install_requires=[\n        'ipython >= 4',\n        'jupyter',\n        'notebook >= 4.2',\n        'beautifulsoup4',\n        'widgetsnbextension',\n    ],\n    url='https://github.com/mozilla/jupyter-spark',\n    zip_safe=False,\n)\n"
  },
  {
    "path": "src/jupyter_spark/__init__.py",
    "content": "from pkg_resources import get_distribution, DistributionNotFound\n\ntry:\n    __version__ = get_distribution(__name__).version\nexcept DistributionNotFound:\n    # package is not installed\n    pass\n\n\ndef _jupyter_nbextension_paths():  # pragma: no cover\n    return [{\n        'section': 'notebook',\n        # the path is relative to the `jupyter_spark` directory\n        'src': 'static',\n        # directory in the `nbextension/` namespace\n        'dest': 'jupyter-spark',\n        # _also_ in the `nbextension/` namespace\n        'require': 'jupyter-spark/extension',\n    }]\n\n\ndef _jupyter_server_extension_paths():  # pragma: no cover\n    return [{\n        'module': 'jupyter_spark',\n    }]\n\n\ndef load_jupyter_server_extension(nbapp):  # pragma: no cover\n    from .spark import Spark\n    from .handlers import SparkHandler\n\n    spark = Spark(\n        # add access to NotebookApp config, too\n        parent=nbapp,\n        base_url=nbapp.web_app.settings['base_url'],\n    )\n\n    nbapp.web_app.add_handlers(\n        r'.*',  # match any host\n        [(spark.proxy_url + '.*', SparkHandler, {'spark': spark})]\n    )\n    nbapp.log.info(\"Jupyter-Spark enabled!\")\n"
  },
  {
    "path": "src/jupyter_spark/handlers.py",
    "content": "import json\n\nimport tornado.web\nfrom notebook.base.handlers import IPythonHandler\nfrom tornado import httpclient\n\n\nclass SparkHandler(IPythonHandler):\n\n    def initialize(self, spark):\n        self.spark = spark\n\n    @tornado.web.asynchronous\n    def get(self):\n        \"\"\"\n        Fetch the requested URI from the Spark API, replace the\n        URLs in the response content for HTML responses or return\n        the verbatim response.\n        \"\"\"\n        http = httpclient.AsyncHTTPClient()\n        url = self.spark.backend_url(self.request)\n        self.spark.log.debug('Fetching from Spark %s', url)\n        http.fetch(url, self.handle_response)\n\n    def handle_response(self, response):\n        if response.error:\n            content_type = 'application/json'\n            content = json.dumps({'error': 'SPARK_NOT_RUNNING'})\n        else:\n            content_type = response.headers['Content-Type']\n            if 'text/html' in content_type:\n                content = self.spark.replace(response.body)\n            else:\n                # Probably binary response, send it directly.\n                content = response.body\n        self.set_header('Content-Type', content_type)\n        self.write(content)\n        self.finish()\n"
  },
  {
    "path": "src/jupyter_spark/spark.py",
    "content": "import re\n\nfrom bs4 import BeautifulSoup\nfrom notebook.utils import url_path_join\nfrom traitlets.config import LoggingConfigurable\nfrom traitlets.traitlets import Unicode\n\n# try importing lxml and use it as the BeautifulSoup builder if available\ntry:\n    import lxml  # noqa\nexcept ImportError:\n    BEAUTIFULSOUP_BUILDER = 'html.parser'\nelse:\n    BEAUTIFULSOUP_BUILDER = 'lxml'  # pragma: no cover\n\n# a regular expression to match paths against the Spark on EMR proxy paths\nPROXY_PATH_RE = re.compile(r'\\/proxy\\/application_\\d+_\\d+\\/(.*)')\n\n# a tuple of tuples with tag names and their attribute to automatically fix\nPROXY_ATTRIBUTES = (\n    (('a', 'link'), 'href'),\n    (('img', 'script'), 'src'),\n)\n\n\nclass Spark(LoggingConfigurable):\n    \"\"\"\n    A config object that is able to replace URLs of the Spark frontend\n    on the fly.\n    \"\"\"\n    url = Unicode(\n        'http://localhost:4040',\n        help='The URL of Spark API',\n    ).tag(config=True)\n\n    proxy_root = Unicode(\n        '/spark',\n        help='The URL path under which the Spark API will be proxied',\n    )\n\n    def __init__(self, *args, **kwargs):\n        self.base_url = kwargs.pop('base_url')\n        super(Spark, self).__init__(*args, **kwargs)\n        self.proxy_url = url_path_join(self.base_url, self.proxy_root)\n\n    def backend_url(self, request):\n        request_path = request.uri[len(self.proxy_url):]\n        return url_path_join(self.url, request_path)\n\n    def replace(self, content):\n        \"\"\"\n        Replace all the links with our prefixed handler links, e.g.:\n\n        /proxy/application_1467283586194_0015/static/styles.css' or\n        /static/styles.css\n\n        with\n\n        /spark/static/styles.css\n        \"\"\"\n        soup = BeautifulSoup(content, BEAUTIFULSOUP_BUILDER)\n        for tags, attribute in PROXY_ATTRIBUTES:\n            for tag in soup.find_all(tags, **{attribute: True}):\n                value = tag[attribute]\n                match = PROXY_PATH_RE.match(value)\n                if match is not None:\n                    value = match.groups()[0]\n                tag[attribute] = url_path_join(self.proxy_root, value)\n        return str(soup)\n"
  },
  {
    "path": "src/jupyter_spark/static/extension.js",
    "content": "var UPDATE_FREQUENCY = 10000; // ms\nvar UPDATE_FREQUENCY_ACTIVE = 500;\nvar PROGRESS_COUNT_TEXT = \"Running Spark job \";\n\n/*\ncache is an array of application objects with an added property jobs.\napplication.jobs is the result of the /applications/applicationId/jobs\nAPI request.\n*/\nvar cache = [];\nvar current_update_frequency;\n\nvar spark_is_running = false;\nvar cell_queue = [];\nvar current_cell;\nvar cell_jobs_counter = 0;\nvar jobs_in_cache = 0;\n\nvar update = function(api_url) {\n    update_cache(api_url, update_dialog_contents);\n};\n\n// callbacks follows jQuery callback style, can be either single function or array of functions\n// callbacks will be passed the cache as a parameter\nvar update_cache = function(api_url, callbacks) {\n    var cbs;\n    if (callbacks) {\n        cbs = $.Callbacks();\n        cbs.add(callbacks);\n    }\n    $.getJSON(api_url + '/applications').done(function(applications) {\n        var num_applications = cache.length;\n        var num_completed = 0;\n        // Check if Spark is running before processing applications\n        if(!applications.hasOwnProperty('error')){\n            spark_is_running = true;\n            applications.forEach(function(application, i) {\n                $.getJSON(api_url + '/applications/' + application.id + '/jobs').done(function (jobs) {\n                    cache[i] = application;\n                    cache[i].jobs = jobs;\n\n                    num_completed++;\n                    if (num_completed === num_applications && cbs) {\n                        cbs.fire(cache);\n                    }\n                    // Update progress bars if jobs have been run and there are cells to be updated\n                    if (jobs.length > jobs_in_cache && cell_queue.length > 0 ) {\n                        $(document).trigger('update.progress.bar');\n                    }\n                });\n            });\n        } else {\n            spark_is_running = false;\n        }\n    });\n};\n\nvar update_dialog_contents = function() {\n    if ($('#dialog_contents').length) {\n        var element = $('<div/>').attr('id', 'dialog_contents');\n        cache.forEach(function(application){\n            element.append(create_application_table(application));\n        });\n\n        $('#dialog_contents').replaceWith(element);\n    }\n};\n\nvar create_application_table = function(e) {\n    var application_div = $('<div/>');\n    application_div.append($('<h5/>').text(e.name + ': ' + e.id));\n    var application_table = $('<table/>').addClass('table table-hover');\n\n    var header_row = $('<tr/>');\n    header_row.append($('<th/>').text('Job ID'));\n    header_row.append($('<th/>').text('Job Name'));\n    header_row.append($('<th/>').text('Progress'));\n    application_table.append(header_row);\n\n    e.jobs.forEach(function(job) {\n        application_table.append(create_table_row(job));\n    });\n\n    application_div.append(application_table);\n    return application_div;\n};\n\nvar create_table_row = function(e) {\n    var row = $('<tr/>');\n    row.append($('<td/>').text(e.jobId));\n    row.append($('<td/>').text(e.name));\n\n    var status_class = get_status_class(e.status);\n\n    var progress_bar_div = create_progress_bar(status_class, e.numCompletedTasks, e.numTasks);\n\n    row.append($('<td/>').append(progress_bar_div));\n    return row;\n};\n\nvar get_status_class = function(status) {\n    var status_class;\n    switch(status) {\n    case 'SUCCEEDED':\n        status_class = 'progress-bar-success';\n        break;\n    case 'RUNNING':\n        status_class = 'progress-bar-info';\n        break;\n    case 'FAILED':\n        status_class = 'progress-bar-danger';\n        break;\n    case 'UNKNOWN':\n        status_class = 'progress-bar-warning';\n        break;\n    }\n    return status_class;\n}\n\nvar create_progress_bar = function(status_class, completed, total) {\n    // progress defined in percent\n    var progress = completed / total * 100;\n\n    var progress_bar_div = $('<div/>')\n        .addClass('progress')\n        .css({'min-width': '100px', 'margin-bottom': 0});\n    var progress_bar = $('<div/>')\n        .addClass('progress-bar ' + status_class)\n        .attr('role', 'progressbar')\n        .attr('aria-valuenow', progress)\n        .attr('aria-valuemin', 0)\n        .attr('aria-valuemax', 100)\n        .css({'width': progress + '%',\n            'white-space': 'nowrap',\n            'overflow': 'visible'});\n    if (status_class == 'progress-bar-warning') {\n        progress_bar.text('Loading Spark...');\n    } else {\n        progress_bar.text(completed + ' out of ' + total + ' tasks');\n    }\n    progress_bar_div.append(progress_bar);\n    return progress_bar_div;\n};\n\n\ndefine([\n    'jquery',\n    'base/js/namespace',\n    'base/js/dialog',\n    'base/js/events',\n    'base/js/utils',\n    'notebook/js/codecell'\n], function ($, Jupyter, dialog, events, utils, codecell) {\n    var CodeCell = codecell.CodeCell;\n    var base_url = utils.get_body_data('baseUrl') || '/';\n    var api_url = base_url + 'spark/api/v1';\n\n    var show_running_jobs = function() {\n        var element = $('<div/>').attr('id', 'dialog_contents');\n        dialog.modal({\n            title: \"Running Spark Jobs\",\n            body: element,\n            buttons: {\n                \"Close\": {}\n            },\n            open: update_dialog_contents\n        });\n    };\n\n    var spark_progress_bar = function(event, data) {\n        var cell = data.cell;\n        if (is_spark_cell(cell)) {\n            window.clearInterval(current_update_frequency);\n            current_update_frequency = window.setInterval(update, UPDATE_FREQUENCY_ACTIVE, api_url);\n            cell_queue.push(cell);\n            current_cell = cell_queue[0];\n            add_progress_bar(current_cell);\n        }\n    };\n\n    var add_progress_bar = function(cell) {\n        var progress_bar_div = cell.element.find('.progress-container');\n        if (progress_bar_div.length < 1) {\n            var input_area = cell.element.find('.input_area');\n            cell_jobs_counter = 0;\n            if (spark_is_running) {\n                jobs_in_cache = cache[0].jobs.length;\n            }\n            var panel = $('<div/>')\n                .addClass('panel')\n                .addClass('panel-default')\n                .addClass('progress-panel')\n                .css({'margin-bottom': '0'})\n                .hide();\n            var jobs_completed_container = $('<div/>')\n                .addClass('progress_counter')\n                .addClass('panel-heading')\n                .text(PROGRESS_COUNT_TEXT + cell_jobs_counter);\n            var progress_bar_container = $('<div/>')\n                .addClass('progress-container');\n            var progress_bar = create_progress_bar('progress-bar-warning', 1, 5);\n            progress_bar.appendTo(progress_bar_container);\n            jobs_completed_container.appendTo(panel);\n            progress_bar_container.appendTo(panel);\n            panel.appendTo(input_area);\n        }\n    };\n\n    var update_progress_bar = function() {\n        var job = cache[0].jobs[0];\n        var completed = job.numCompletedTasks;\n        var total = job.numTasks;\n\n        var progress_bar = current_cell.element.find('.progress');\n        update_progress_count(current_cell, job.jobId);\n\n        var progress = completed / total * 100;\n        progress_bar.show();\n        progress_bar.find('.progress-bar')\n            .attr('class', 'progress-bar ' + get_status_class(job.status))\n            .attr('aria-valuenow', progress)\n            .css('width', progress + '%')\n            .text(completed + ' out of ' + total + ' tasks');\n    };\n\n    var update_progress_count = function(cell, jobId) {\n        var progress_count = cell.element.find('.progress_counter');\n        var job_name = \"\";\n        var canceller = null;\n        if (spark_is_running) {\n            cell_jobs_counter = cache[0].jobs.length - jobs_in_cache;\n            job_name =  \": \" + cache[0].jobs[0].name\n            canceller = $('<a href=\"#\" class=\"btn btn-default btn-xs pull-right\">Cancel</a>').on(\n                'click',\n                function () { $.get(base_url + \"spark/jobs/job/kill?id=\" + jobId)});\n        }\n\n        progress_count.text(PROGRESS_COUNT_TEXT + cell_jobs_counter + job_name);\n        progress_count.append(canceller)\n        cell.element.find('.progress-panel').show();\n    };\n\n    var remove_progress_bar = function() {\n        if (current_cell != null) {\n            var progress_panel = current_cell.element.find('.progress-panel');\n            progress_panel.remove();\n\n            start_next_progress_bar();\n        }\n    };\n\n    var start_next_progress_bar = function() {\n        cell_queue.shift();\n        current_cell = cell_queue[0];\n        if (current_cell != null) {\n            add_progress_bar(current_cell);\n        } else {\n            window.clearInterval(current_update_frequency);\n            current_update_frequency = window.setInterval(update, UPDATE_FREQUENCY, api_url);\n        }\n    };\n\n    var is_spark_cell = function(cell) {\n        // TODO: Find a way to detect if cell is actually running Spark\n        return (cell instanceof CodeCell)\n    };\n\n    var load_ipython_extension = function () {\n        events.on('execute.CodeCell', spark_progress_bar);\n\n        $(document).on('update.progress.bar', update_progress_bar);\n\n        // Kernel becomes idle after a cell finishes executing\n        events.on('kernel_idle.Kernel', remove_progress_bar);\n\n        Jupyter.keyboard_manager.command_shortcuts.add_shortcut('Alt-S', show_running_jobs);\n        Jupyter.toolbar.add_buttons_group([{\n            'label': 'Show running Spark jobs',\n            'icon': 'fa-tasks',\n            'callback': show_running_jobs,\n            'id': 'show_running_jobs'\n        }]);\n        update(api_url);\n        current_update_frequency = window.setInterval(update, UPDATE_FREQUENCY, api_url);\n    };\n\n    return {\n        load_ipython_extension: load_ipython_extension\n    };\n});\n"
  },
  {
    "path": "tests/test_spark.py",
    "content": "# -*- coding: utf-8 -*-\nimport pytest\nimport six\nimport tornado\nimport tornado.httpclient\nimport tornado.testing\nimport tornado.web\nfrom bs4 import BeautifulSoup\nfrom jupyter_spark.handlers import SparkHandler\nfrom jupyter_spark.spark import BEAUTIFULSOUP_BUILDER, Spark\n\nPROXY_PREFIX = \"/proxy/application_1234556789012_3456\"\nspark = Spark(base_url='http://localhost:8888')\n\n\nclass FakeHandler(tornado.web.RequestHandler):\n\n    def get(self):\n        self.set_header('Content-Type', self.CONTENT_TYPE)\n        self.write(self.RESPONSE)\n\n\nclass FakeReplaceHandler(FakeHandler):\n    handler_root = '/backend/replace'\n    RESPONSE = six.b('<img src=\"/image.png\" />')\n    REPLACED = six.b('<img src=\"/spark/image.png\"/>')\n    CONTENT_TYPE = 'text/html'\n\n\nclass FakeVerbatimHandler(FakeHandler):\n    handler_root = '/backend/verbatim'\n    RESPONSE = six.b('<a href=\"/\">Hello, world!</a>')\n    CONTENT_TYPE = 'plain/text'\n\n\nclass SparkHandlerTests(tornado.testing.AsyncHTTPTestCase):\n\n    def get_app(self):\n        port = self.get_http_port()\n        base_url = 'http://localhost:%s' % port\n        self.spark = Spark(base_url=base_url)\n        return tornado.web.Application([\n            (spark.proxy_root + '.*', SparkHandler, {'spark': self.spark}),\n            (FakeReplaceHandler.handler_root, FakeReplaceHandler),\n            (FakeVerbatimHandler.handler_root, FakeVerbatimHandler),\n        ])\n\n    def test_http_fetch_error(self):\n        response = self.fetch(self.spark.proxy_root)\n        self.assertEqual(response.code, 200)\n        self.assertIn(six.b('SPARK_NOT_RUNNING'), response.body)\n\n    def test_http_fetch_replace_success(self):\n        self.spark.url = self.spark.base_url + FakeReplaceHandler.handler_root\n        response = self.fetch(self.spark.proxy_root)\n        self.assertEqual(response.code, 200)\n        self.assertNotEqual(response.body, FakeReplaceHandler.RESPONSE)\n        self.assertEqual(response.body, FakeReplaceHandler.REPLACED)\n        self.assertEqual(response.headers['Content-Type'],\n                         FakeReplaceHandler.CONTENT_TYPE)\n\n    def test_http_fetch_verbatim_success(self):\n        self.spark.url = self.spark.base_url + FakeVerbatimHandler.handler_root\n        response = self.fetch(self.spark.proxy_root)\n        self.assertEqual(response.code, 200)\n        self.assertEqual(response.body, FakeVerbatimHandler.RESPONSE)\n        self.assertEqual(response.headers['Content-Type'],\n                         FakeVerbatimHandler.CONTENT_TYPE)\n\n    def test_spark_backend_url(self):\n        class FakeRequest(object):\n            # http://localhost:8888/spark/api\n            uri = self.spark.base_url + self.spark.proxy_root + '/api'\n        fake_request = FakeRequest()\n        self.assertEqual(self.spark.backend_url(fake_request),\n                         self.spark.url + '/api')\n\n\n@pytest.mark.parametrize('content', [\n    '<a href=\"{prefix}/page/\">page</a>',\n    '<link rel=\"stylesheet\" href=\"{prefix}/styles.css\" />',\n    six.u('<a href=\"{prefix}/über-uns/\">Über uns</a>'),\n    # missing href attribute so expected to fail:\n    pytest.mark.xfail('<a data-href=\"{prefix}/page/\">page</a>'),\n    pytest.mark.xfail('<link rel=\"stylesheet\" data-href=\"{prefix}/styles.css\" />'),\n    # fails because the URL path doesn't start with the prefix\n    pytest.mark.xfail('<a href=\"/something/completely/\">different</a>'),\n])\ndef test_replace_href_tags(content):\n    content = content.format(prefix=PROXY_PREFIX)\n    replaced = spark.replace(content)\n    assert replaced != content\n    soup = BeautifulSoup(replaced, BEAUTIFULSOUP_BUILDER)\n    for tag in soup.find_all(['a', 'link']):\n        assert tag.attrs['href'].startswith(spark.proxy_root)\n\n\n@pytest.mark.parametrize('content', [\n    '<img src=\"{prefix}/img.png\" />',\n    '<script src=\"{prefix}/script.js\" />',\n    '<img src=\"/logo.png\" />',\n    six.u('<script src=\"{prefix}/scrüpt.js\" />'),\n    # missing src attribute so expected to fail:\n    pytest.mark.xfail('<img data-src=\"{prefix}/img.png\" />'),\n    pytest.mark.xfail('<script data-src=\"{prefix}/script.js\" />'),\n])\ndef test_replace_src_tags(content):\n    content = content.format(prefix=PROXY_PREFIX)\n    replaced = spark.replace(content)\n    assert replaced != content\n    soup = BeautifulSoup(replaced, BEAUTIFULSOUP_BUILDER)\n    for tag in soup.find_all(['img', 'script']):\n        assert tag.attrs['src'].startswith(spark.proxy_root)\n"
  },
  {
    "path": "tox.ini",
    "content": "# Tox (http://tox.testrun.org/) is a tool for running tests\n# in multiple virtualenvs. This configuration file will run the\n# test suite on all supported python versions. To use it, \"pip install tox\"\n# and then run \"tox\" from this directory.\n[tox]\nrecreate = true\n\n[testenv]\ncommands =\n    py.test {posargs}\ndeps:\n    tornado\n    coverage>=4.0\n    pytest-isort\n    pytest-cache>=1.0\n    pytest-cov\n    flake8\n    pytest-flake8>=0.5\n    pytest>=2.8.0\n    six\n\n[flake8]\nignore = E501\n"
  }
]