pax_global_header00006660000000000000000000000064130461040720014507gustar00rootroot0000000000000052 comment=519236ac0c5bdfc43e07fcbf6ade354f959a3923 portalocker-1.1.0/000077500000000000000000000000001304610407200140335ustar00rootroot00000000000000portalocker-1.1.0/.coveragerc000066400000000000000000000003741304610407200161600ustar00rootroot00000000000000[report] fail_under = 100 exclude_lines = pragma: no cover def __repr__ if self.debug: if settings.DEBUG raise AssertionError raise NotImplementedError if 0: if __name__ == .__main__.: [run] source = src branch = True portalocker-1.1.0/.gitignore000066400000000000000000000000621304610407200160210ustar00rootroot00000000000000build/ locked_file dist htmlcov *.egg-info .cache portalocker-1.1.0/.travis.yml000066400000000000000000000013031304610407200161410ustar00rootroot00000000000000sudo: false language: python python: - '2.6' - '2.7' - '3.3' - '3.4' - '3.5' - pypy - pypy3 before_install: - wheel version install: - pip install -r tests/requirements.txt - pip install -e . - pip install coveralls script: - python setup.py test after_success: - coveralls - python setup.py bdist_wheel - ls -la dist/ before_deploy: - python setup.py combine -o dist/portalocker.py deploy: provider: releases api_key: secure: xY/jF18OX/muUeSnncY3GeHpzOlPi9NGfOUM/Cl7LXCjNnqXVub2uxYiOdwGs1Z9GNqftNv4g1+th89jHVyPOvXK3DSQ0yemMMMM3ZLFdeuy/XcQyuS/32tMfFm5jBBG6sa/S8Mm6H9ShQfQcrQT4su7EzHJIAz72iUXMagKtHM= file: dist/portalocker.py skip_cleanup: true on: repo: WoLpH/portalocker tags: true portalocker-1.1.0/CHANGELOG.rst000066400000000000000000000015101304610407200160510ustar00rootroot000000000000001.0: * Complete code refactor. - Splitting of code in logical classes - 100% test coverage and change in API behaviour - The default behavior of the `Lock` class has changed to append instead of write/truncate. 0.6: * Added msvcrt support for Windows 0.5: * Python 3 support 0.4: * Fixing a few bugs, added coveralls support, switched to py.test and added 100% test coverage. - Fixing exception thrown when fail_when_locked is true - Fixing exception "Lock object has no attribute '_release_lock'" when fail_when_locked is true due to the call to Lock._release_lock() which fails because _release_lock is not defined. 0.3: * Now actually returning the file descriptor from the `Lock` class 0.2: * Added `Lock` class to help prevent cache race conditions 0.1: * Initial release portalocker-1.1.0/LICENSE000066400000000000000000000045631304610407200150500ustar00rootroot00000000000000PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2 -------------------------------------------- 1. This LICENSE AGREEMENT is between the Python Software Foundation ("PSF"), and the Individual or Organization ("Licensee") accessing and otherwise using this software ("Python") in source or binary form and its associated documentation. 2. Subject to the terms and conditions of this License Agreement, PSF hereby grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce, analyze, test, perform and/or display publicly, prepare derivative works, distribute, and otherwise use Python alone or in any derivative version, provided, however, that PSF's License Agreement and PSF's notice of copyright, i.e., "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Python Software Foundation; All Rights Reserved" are retained in Python alone or in any derivative version prepared by Licensee. 3. In the event Licensee prepares a derivative work that is based on or incorporates Python or any part thereof, and wants to make the derivative work available to others as provided herein, then Licensee hereby agrees to include in any such work a brief summary of the changes made to Python. 4. PSF is making Python available to Licensee on an "AS IS" basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT INFRINGE ANY THIRD PARTY RIGHTS. 5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON, OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF. 6. This License Agreement will automatically terminate upon a material breach of its terms and conditions. 7. Nothing in this License Agreement shall be deemed to create any relationship of agency, partnership, or joint venture between PSF and Licensee. This License Agreement does not grant permission to use PSF trademarks or trade name in a trademark sense to endorse or promote products or services of Licensee, or any third party. 8. By copying, installing or otherwise using Python, Licensee agrees to be bound by the terms and conditions of this License Agreement. portalocker-1.1.0/MANIFEST.in000066400000000000000000000001221304610407200155640ustar00rootroot00000000000000include CHANGELOG include README.rst include LICENSE recursive-include tests *.py portalocker-1.1.0/README.rst000066400000000000000000000055031304610407200155250ustar00rootroot00000000000000############################################ portalocker - Cross-platform locking library ############################################ .. image:: https://travis-ci.org/WoLpH/portalocker.svg?branch=master :alt: Linux Test Status :target: https://travis-ci.org/WoLpH/portalocker .. image:: https://ci.appveyor.com/api/projects/status/mgqry98hgpy4prhh?svg=true :alt: Windows Tests Status :target: https://ci.appveyor.com/project/WoLpH/portalocker .. image:: https://coveralls.io/repos/WoLpH/portalocker/badge.svg?branch=master :alt: Coverage Status :target: https://coveralls.io/r/WoLpH/portalocker?branch=master Overview -------- Portalocker is a library to provide an easy API to file locking. An important detail to note is that on Linux and Unix systems the locks are advisory by default. By specifying the `-o mand` option to the mount command it is possible to enable mandatory file locking on Linux. This is generally not recommended however. For more information about the subject: - https://en.wikipedia.org/wiki/File_locking - http://stackoverflow.com/questions/39292051/portalocker-does-not-seem-to-lock - https://stackoverflow.com/questions/12062466/mandatory-file-lock-on-linux The module is currently maintained by Rick van Hattem . The project resides at https://github.com/WoLpH/portalocker . Bugs and feature requests can be submitted there. Patches are also very welcome. Links ----- * Documentation - http://portalocker.readthedocs.org/en/latest/ * Source - https://github.com/WoLpH/portalocker * Bug reports - https://github.com/WoLpH/portalocker/issues * Package homepage - https://pypi.python.org/pypi/portalocker * My blog - http://w.wol.ph/ Examples -------- To make sure your cache generation scripts don't race, use the `Lock` class: >>> import portalocker >>> with portalocker.Lock('somefile', timeout=1) as fh: print >>fh, 'writing some stuff to my cache...' To customize the opening and locking a manual approach is also possible: >>> import portalocker >>> file = open('somefile', 'r+') >>> portalocker.lock(file, portalocker.LOCK_EX) >>> file.seek(12) >>> file.write('foo') >>> file.close() There is no explicit need to unlock the file as it is automatically unlocked after `file.close()`. If you still feel the need to manually unlock a file than you can do it like this: >>> portalocker.unlock(file) Do note that your data might still be in a buffer so it is possible that your data is not available until you `flush()` or `close()`. More examples can be found in the `tests `_. Changelog --------- See the `changelog `_ page. License ------- See the `LICENSE `_ file. portalocker-1.1.0/appveyor.yml000066400000000000000000000005121304610407200164210ustar00rootroot00000000000000install: - echo "Installed Python versions:" - dir c:\Python* - C:\Python35\python -m pip install tox build: false # Not a C# project, build stuff at the test step instead. test_script: - 'set TESTENVS= py26, py27, py33, py34 ' - C:\Python35\python -m tox -e "%TESTENVS%" portalocker-1.1.0/docs/000077500000000000000000000000001304610407200147635ustar00rootroot00000000000000portalocker-1.1.0/docs/Makefile000066400000000000000000000127201304610407200164250ustar00rootroot00000000000000# Makefile for Sphinx documentation # # You can set these variables from the command line. SPHINXOPTS = SPHINXBUILD = sphinx-build PAPER = BUILDDIR = _build # Internal variables. PAPEROPT_a4 = -D latex_paper_size=a4 PAPEROPT_letter = -D latex_paper_size=letter ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . # the i18n builder cannot share the environment and doctrees with the others I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext help: @echo "Please use \`make ' where is one of" @echo " html to make standalone HTML files" @echo " dirhtml to make HTML files named index.html in directories" @echo " singlehtml to make a single large HTML file" @echo " pickle to make pickle files" @echo " json to make JSON files" @echo " htmlhelp to make HTML files and a HTML help project" @echo " qthelp to make HTML files and a qthelp project" @echo " devhelp to make HTML files and a Devhelp project" @echo " epub to make an epub" @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" @echo " latexpdf to make LaTeX files and run them through pdflatex" @echo " text to make text files" @echo " man to make manual pages" @echo " texinfo to make Texinfo files" @echo " info to make Texinfo files and run them through makeinfo" @echo " gettext to make PO message catalogs" @echo " changes to make an overview of all changed/added/deprecated items" @echo " linkcheck to check all external links for integrity" @echo " doctest to run all doctests embedded in the documentation (if enabled)" clean: -rm -rf $(BUILDDIR)/* html: $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." dirhtml: $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." singlehtml: $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml @echo @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." pickle: $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle @echo @echo "Build finished; now you can process the pickle files." json: $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json @echo @echo "Build finished; now you can process the JSON files." htmlhelp: $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp @echo @echo "Build finished; now you can run HTML Help Workshop with the" \ ".hhp project file in $(BUILDDIR)/htmlhelp." qthelp: $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp @echo @echo "Build finished; now you can run "qcollectiongenerator" with the" \ ".qhcp project file in $(BUILDDIR)/qthelp, like this:" @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/PythonUtils.qhcp" @echo "To view the help file:" @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/PythonUtils.qhc" devhelp: $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp @echo @echo "Build finished." @echo "To view the help file:" @echo "# mkdir -p $$HOME/.local/share/devhelp/PythonUtils" @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/PythonUtils" @echo "# devhelp" epub: $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub @echo @echo "Build finished. The epub file is in $(BUILDDIR)/epub." latex: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." @echo "Run \`make' in that directory to run these through (pdf)latex" \ "(use \`make latexpdf' here to do that automatically)." latexpdf: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo "Running LaTeX files through pdflatex..." $(MAKE) -C $(BUILDDIR)/latex all-pdf @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." text: $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text @echo @echo "Build finished. The text files are in $(BUILDDIR)/text." man: $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man @echo @echo "Build finished. The manual pages are in $(BUILDDIR)/man." texinfo: $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo @echo @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." @echo "Run \`make' in that directory to run these through makeinfo" \ "(use \`make info' here to do that automatically)." info: $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo @echo "Running Texinfo files through makeinfo..." make -C $(BUILDDIR)/texinfo info @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." gettext: $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale @echo @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." changes: $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes @echo @echo "The overview file is in $(BUILDDIR)/changes." linkcheck: $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck @echo @echo "Link check complete; look for any errors in the above output " \ "or in $(BUILDDIR)/linkcheck/output.txt." doctest: $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest @echo "Testing of doctests in the sources finished, look at the " \ "results in $(BUILDDIR)/doctest/output.txt." portalocker-1.1.0/docs/_theme/000077500000000000000000000000001304610407200162245ustar00rootroot00000000000000portalocker-1.1.0/docs/_theme/LICENSE000066400000000000000000000035541304610407200172400ustar00rootroot00000000000000Modifications: Copyright (c) 2012 Rick van Hattem. Original Projects: Copyright (c) 2010 Kenneth Reitz. Copyright (c) 2010 by Armin Ronacher. Some rights reserved. Redistribution and use in source and binary forms of the theme, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * The names of the contributors may not be used to endorse or promote products derived from this software without specific prior written permission. We kindly ask you to only use these themes in an unmodified manner just for Flask and Flask-related products, not for unrelated projects. If you like the visual style and want to use it for your own projects, please consider making some larger changes to the themes (such as changing font faces, sizes, colors or margins). THIS THEME IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS THEME, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. portalocker-1.1.0/docs/_theme/flask_theme_support.py000066400000000000000000000114171304610407200226600ustar00rootroot00000000000000# flasky extensions. flasky pygments style based on tango style from pygments.style import Style from pygments.token import Keyword, Name, Comment, String, Error, \ Number, Operator, Generic, Whitespace, Punctuation, Other, Literal class FlaskyStyle(Style): background_color = "#f8f8f8" default_style = "" styles = { # No corresponding class for the following: # Text: "", # class: '' Whitespace: "underline #f8f8f8", # class: 'w' Error: "#a40000 border:#ef2929", # class: 'err' Other: "#000000", # class 'x' Comment: "italic #8f5902", # class: 'c' Comment.Preproc: "noitalic", # class: 'cp' Keyword: "bold #004461", # class: 'k' Keyword.Constant: "bold #004461", # class: 'kc' Keyword.Declaration: "bold #004461", # class: 'kd' Keyword.Namespace: "bold #004461", # class: 'kn' Keyword.Pseudo: "bold #004461", # class: 'kp' Keyword.Reserved: "bold #004461", # class: 'kr' Keyword.Type: "bold #004461", # class: 'kt' Operator: "#582800", # class: 'o' Operator.Word: "bold #004461", # class: 'ow' - like keywords Punctuation: "bold #000000", # class: 'p' # because special names such as Name.Class, Name.Function, etc. # are not recognized as such later in the parsing, we choose them # to look the same as ordinary variables. Name: "#000000", # class: 'n' Name.Attribute: "#c4a000", # class: 'na' - to be revised Name.Builtin: "#004461", # class: 'nb' Name.Builtin.Pseudo: "#3465a4", # class: 'bp' Name.Class: "#000000", # class: 'nc' - to be revised Name.Constant: "#000000", # class: 'no' - to be revised Name.Decorator: "#888", # class: 'nd' - to be revised Name.Entity: "#ce5c00", # class: 'ni' Name.Exception: "bold #cc0000", # class: 'ne' Name.Function: "#000000", # class: 'nf' Name.Property: "#000000", # class: 'py' Name.Label: "#f57900", # class: 'nl' Name.Namespace: "#000000", # class: 'nn' - to be revised Name.Other: "#000000", # class: 'nx' Name.Tag: "bold #004461", # class: 'nt' - like a keyword Name.Variable: "#000000", # class: 'nv' - to be revised Name.Variable.Class: "#000000", # class: 'vc' - to be revised Name.Variable.Global: "#000000", # class: 'vg' - to be revised Name.Variable.Instance: "#000000", # class: 'vi' - to be revised Number: "#990000", # class: 'm' Literal: "#000000", # class: 'l' Literal.Date: "#000000", # class: 'ld' String: "#4e9a06", # class: 's' String.Backtick: "#4e9a06", # class: 'sb' String.Char: "#4e9a06", # class: 'sc' String.Doc: "italic #8f5902", # class: 'sd' - like a comment String.Double: "#4e9a06", # class: 's2' String.Escape: "#4e9a06", # class: 'se' String.Heredoc: "#4e9a06", # class: 'sh' String.Interpol: "#4e9a06", # class: 'si' String.Other: "#4e9a06", # class: 'sx' String.Regex: "#4e9a06", # class: 'sr' String.Single: "#4e9a06", # class: 's1' String.Symbol: "#4e9a06", # class: 'ss' Generic: "#000000", # class: 'g' Generic.Deleted: "#a40000", # class: 'gd' Generic.Emph: "italic #000000", # class: 'ge' Generic.Error: "#ef2929", # class: 'gr' Generic.Heading: "bold #000080", # class: 'gh' Generic.Inserted: "#00A000", # class: 'gi' Generic.Output: "#888", # class: 'go' Generic.Prompt: "#745334", # class: 'gp' Generic.Strong: "bold #000000", # class: 'gs' Generic.Subheading: "bold #800080", # class: 'gu' Generic.Traceback: "bold #a40000", # class: 'gt' } portalocker-1.1.0/docs/_theme/wolph/000077500000000000000000000000001304610407200173555ustar00rootroot00000000000000portalocker-1.1.0/docs/_theme/wolph/layout.html000066400000000000000000000011061304610407200215560ustar00rootroot00000000000000{%- extends "basic/layout.html" %} {%- block extrahead %} {{ super() }} {% if theme_touch_icon %} {% endif %} {% endblock %} {%- block relbar2 %}{% endblock %} {%- block footer %} {%- endblock %} portalocker-1.1.0/docs/_theme/wolph/relations.html000066400000000000000000000011161304610407200222420ustar00rootroot00000000000000

Related Topics

portalocker-1.1.0/docs/_theme/wolph/static/000077500000000000000000000000001304610407200206445ustar00rootroot00000000000000portalocker-1.1.0/docs/_theme/wolph/static/flasky.css_t000066400000000000000000000156061304610407200232020ustar00rootroot00000000000000/* * flasky.css_t * ~~~~~~~~~~~~ * * :copyright: Copyright 2010 by Armin Ronacher. Modifications by Kenneth Reitz. * :license: Flask Design License, see LICENSE for details. */ {% set page_width = '940px' %} {% set sidebar_width = '220px' %} @import url("basic.css"); /* -- page layout ----------------------------------------------------------- */ body { font-family: 'goudy old style', 'minion pro', 'bell mt', Georgia, 'Hiragino Mincho Pro'; font-size: 17px; background-color: white; color: #000; margin: 0; padding: 0; } div.document { width: {{ page_width }}; margin: 30px auto 0 auto; } div.documentwrapper { float: left; width: 100%; } div.bodywrapper { margin: 0 0 0 {{ sidebar_width }}; } div.sphinxsidebar { width: {{ sidebar_width }}; } hr { border: 1px solid #B1B4B6; } div.body { background-color: #ffffff; color: #3E4349; padding: 0 30px 0 30px; } img.floatingflask { padding: 0 0 10px 10px; float: right; } div.footer { width: {{ page_width }}; margin: 20px auto 30px auto; font-size: 14px; color: #888; text-align: right; } div.footer a { color: #888; } div.related { display: none; } div.sphinxsidebar a { color: #444; text-decoration: none; border-bottom: 1px dotted #999; } div.sphinxsidebar a:hover { border-bottom: 1px solid #999; } div.sphinxsidebar { font-size: 14px; line-height: 1.5; } div.sphinxsidebarwrapper { padding: 0px 10px; } div.sphinxsidebarwrapper p.logo { padding: 0 0 20px 0; margin: 0; text-align: center; } div.sphinxsidebar h3, div.sphinxsidebar h4 { font-family: 'Garamond', 'Georgia', serif; color: #555; font-size: 24px; font-weight: normal; margin: 0 0 5px 0; padding: 0; } div.sphinxsidebar h4 { font-size: 20px; } div.sphinxsidebar h3 a { color: #444; } div.sphinxsidebar p.logo a, div.sphinxsidebar h3 a, div.sphinxsidebar p.logo a:hover, div.sphinxsidebar h3 a:hover { border: none; } div.sphinxsidebar p { color: #555; margin: 10px 0; } div.sphinxsidebar ul { margin: 10px 0; padding: 0; color: #000; } div.sphinxsidebar input[type="text"] { width: 160px!important; } div.sphinxsidebar input { border: 1px solid #ccc; font-family: 'Georgia', serif; font-size: 1em; } /* -- body styles ----------------------------------------------------------- */ a { color: #004B6B; text-decoration: underline; } a:hover { color: #6D4100; text-decoration: underline; } div.body h1, div.body h2, div.body h3, div.body h4, div.body h5, div.body h6 { font-family: 'Garamond', 'Georgia', serif; font-weight: normal; margin: 30px 0px 10px 0px; padding: 0; } div.body h1 { margin-top: 0; padding-top: 0; font-size: 240%; } div.body h2 { font-size: 180%; } div.body h3 { font-size: 150%; } div.body h4 { font-size: 130%; } div.body h5 { font-size: 100%; } div.body h6 { font-size: 100%; } a.headerlink { color: #ddd; padding: 0 4px; text-decoration: none; } a.headerlink:hover { color: #444; background: #eaeaea; } div.body p, div.body dd, div.body li { line-height: 1.4em; } div.admonition { background: #fafafa; margin: 20px -30px; padding: 10px 30px; border-top: 1px solid #ccc; border-bottom: 1px solid #ccc; } div.admonition tt.xref, div.admonition a tt { border-bottom: 1px solid #fafafa; } dd div.admonition { margin-left: -60px; padding-left: 60px; } div.admonition p.admonition-title { font-family: 'Garamond', 'Georgia', serif; font-weight: normal; font-size: 24px; margin: 0 0 10px 0; padding: 0; line-height: 1; } div.admonition p.last { margin-bottom: 0; } div.highlight { background-color: white; } dt:target, .highlight { background: #FAF3E8; } div.note { background-color: #eee; border: 1px solid #ccc; } div.seealso { background-color: #ffc; border: 1px solid #ff6; } div.topic { background-color: #eee; } p.admonition-title { display: inline; } p.admonition-title:after { content: ":"; } pre, tt { font-family: 'Consolas', 'Menlo', 'Deja Vu Sans Mono', 'Bitstream Vera Sans Mono', monospace; font-size: 0.9em; } img.screenshot { } tt.descname, tt.descclassname { font-size: 0.95em; } tt.descname { padding-right: 0.08em; } img.screenshot { -moz-box-shadow: 2px 2px 4px #eee; -webkit-box-shadow: 2px 2px 4px #eee; box-shadow: 2px 2px 4px #eee; } table.docutils { border: 1px solid #888; -moz-box-shadow: 2px 2px 4px #eee; -webkit-box-shadow: 2px 2px 4px #eee; box-shadow: 2px 2px 4px #eee; } table.docutils td, table.docutils th { border: 1px solid #888; padding: 0.25em 0.7em; } table.field-list, table.footnote { border: none; -moz-box-shadow: none; -webkit-box-shadow: none; box-shadow: none; } table.footnote { margin: 15px 0; width: 100%; border: 1px solid #eee; background: #fdfdfd; font-size: 0.9em; } table.footnote + table.footnote { margin-top: -15px; border-top: none; } table.field-list th { padding: 0 0.8em 0 0; } table.field-list td { padding: 0; } table.footnote td.label { width: 0px; padding: 0.3em 0 0.3em 0.5em; } table.footnote td { padding: 0.3em 0.5em; } dl { margin: 0; padding: 0; } dl dd { margin-left: 30px; } blockquote { margin: 0 0 0 30px; padding: 0; } ul, ol { margin: 10px 0 10px 30px; padding: 0; } pre { background: #eee; padding: 7px 30px; margin: 15px -30px; line-height: 1.3em; } dl pre, blockquote pre, li pre { margin-left: -60px; padding-left: 60px; } dl dl pre { margin-left: -90px; padding-left: 90px; } tt { background-color: #ecf0f3; color: #222; /* padding: 1px 2px; */ } tt.xref, a tt { background-color: #FBFBFB; border-bottom: 1px solid white; } a.reference { text-decoration: none; border-bottom: 1px dotted #004B6B; } a.reference:hover { border-bottom: 1px solid #6D4100; } a.footnote-reference { text-decoration: none; font-size: 0.7em; vertical-align: top; border-bottom: 1px dotted #004B6B; } a.footnote-reference:hover { border-bottom: 1px solid #6D4100; } a:hover tt { background: #EEE; } /* scrollbars */ ::-webkit-scrollbar { width: 6px; height: 6px; } ::-webkit-scrollbar-button:start:decrement, ::-webkit-scrollbar-button:end:increment { display: block; height: 10px; } ::-webkit-scrollbar-button:vertical:increment { background-color: #fff; } ::-webkit-scrollbar-track-piece { background-color: #eee; -webkit-border-radius: 3px; } ::-webkit-scrollbar-thumb:vertical { height: 50px; background-color: #ccc; -webkit-border-radius: 3px; } ::-webkit-scrollbar-thumb:horizontal { width: 50px; background-color: #ccc; -webkit-border-radius: 3px; } /* misc. */ .revsys-inline { display: none!important; } portalocker-1.1.0/docs/_theme/wolph/static/small_flask.css000066400000000000000000000017201304610407200236460ustar00rootroot00000000000000/* * small_flask.css_t * ~~~~~~~~~~~~~~~~~ * * :copyright: Copyright 2010 by Armin Ronacher. * :license: Flask Design License, see LICENSE for details. */ body { margin: 0; padding: 20px 30px; } div.documentwrapper { float: none; background: white; } div.sphinxsidebar { display: block; float: none; width: 102.5%; margin: 50px -30px -20px -30px; padding: 10px 20px; background: #333; color: white; } div.sphinxsidebar h3, div.sphinxsidebar h4, div.sphinxsidebar p, div.sphinxsidebar h3 a { color: white; } div.sphinxsidebar a { color: #aaa; } div.sphinxsidebar p.logo { display: none; } div.document { width: 100%; margin: 0; } div.related { display: block; margin: 0; padding: 10px 0 20px 0; } div.related ul, div.related ul li { margin: 0; padding: 0; } div.footer { display: none; } div.bodywrapper { margin: 0; } div.body { min-height: 0; padding: 0; } portalocker-1.1.0/docs/_theme/wolph/theme.conf000066400000000000000000000001721304610407200213260ustar00rootroot00000000000000[theme] inherit = basic stylesheet = flasky.css pygments_style = flask_theme_support.FlaskyStyle [options] touch_icon = portalocker-1.1.0/docs/changelog.rst000066400000000000000000000002001304610407200174340ustar00rootroot00000000000000Changelog ========= For a more detailed overview of the changelog please view the Git history .. include :: ../CHANGELOG.rst portalocker-1.1.0/docs/conf.py000066400000000000000000000254011304610407200162640ustar00rootroot00000000000000# -*- coding: utf-8 -*- # # Documentation build configuration file, created by # sphinx-quickstart on Thu Feb 27 20:00:23 2014. # # This file is execfile()d with the current directory set to its # containing dir. # # Note that not all possible configuration values are present in this # autogenerated file. # # All configuration values have a default; values that are commented out # serve to show the default. import os import sys import datetime # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) from portalocker import __about__ as metadata # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. #needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ 'sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.intersphinx', 'sphinx.ext.todo', 'sphinx.ext.coverage', 'sphinx.ext.mathjax', 'sphinx.ext.ifconfig', 'sphinx.ext.viewcode', ] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] # The suffix of source filenames. source_suffix = '.rst' # The encoding of source files. #source_encoding = 'utf-8-sig' # The master toctree document. master_doc = 'index' # General information about the project. project = metadata.__package_name__.replace('-', ' ').capitalize() copyright = u'%s, %s' % ( datetime.date.today().year, metadata.__author__, ) # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. version = metadata.__version__ # The full version, including alpha/beta/rc tags. release = metadata.__version__ # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. #language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: #today = '' # Else, today_fmt is used as the format for a strftime call. #today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. exclude_patterns = ['_build'] # The reST default role (used for this markup: `text`) to use for all # documents. #default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. #add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). #add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. #show_authors = False # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' # A list of ignored prefixes for module index sorting. #modindex_common_prefix = [] # If true, keep warnings as "system message" paragraphs in the built documents. #keep_warnings = False # -- Options for HTML output ---------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. html_theme = 'wolph' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. #html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. html_theme_path = ['_theme'] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". #html_title = None # A shorter title for the navigation bar. Default is the same as html_title. #html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. #html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. #html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ['_static'] # Add any extra paths that contain custom files (such as robots.txt or # .htaccess) here, relative to this directory. These files are copied # directly to the root of the documentation. #html_extra_path = [] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. #html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. #html_use_smartypants = True # Custom sidebar templates, maps document names to template names. #html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. #html_additional_pages = {} # If false, no module index is generated. #html_domain_indices = True # If false, no index is generated. #html_use_index = True # If true, the index is split into individual pages for each letter. #html_split_index = False # If true, links to the reST sources are added to the pages. #html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. #html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. #html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. #html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). #html_file_suffix = None # Output file base name for HTML help builder. htmlhelp_basename = metadata.__package_name__ + '-doc' # -- Options for LaTeX output --------------------------------------------- latex_elements = { # The paper size ('letterpaper' or 'a4paper'). #'papersize': 'letterpaper', # The font size ('10pt', '11pt' or '12pt'). #'pointsize': '10pt', # Additional stuff for the LaTeX preamble. #'preamble': '', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [( 'index', '%s.tex' % metadata.__package_name__, u'%s Documentation' % metadata.__package_name__.replace('-', ' ').capitalize(), metadata.__author__, 'manual', )] # The name of an image file (relative to this directory) to place at the top of # the title page. #latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. #latex_use_parts = False # If true, show page references after internal links. #latex_show_pagerefs = False # If true, show URL addresses after external links. #latex_show_urls = False # Documents to append as an appendix to all manuals. #latex_appendices = [] # If false, no module index is generated. #latex_domain_indices = True # -- Options for manual page output --------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [( 'index', metadata.__package_name__, u'%s Documentation' % metadata.__package_name__.replace('-', ' ').capitalize(), [metadata.__author__], 1, )] # If true, show URL addresses after external links. #man_show_urls = False # -- Options for Texinfo output ------------------------------------------- # Grouping the document tree into Texinfo files. List of tuples # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [( 'index', metadata.__package_name__, u'%s Documentation' % metadata.__package_name__.replace('-', ' ').capitalize(), metadata.__author__, metadata.__package_name__, metadata.__description__, 'Miscellaneous', )] # Documents to append as an appendix to all manuals. #texinfo_appendices = [] # If false, no module index is generated. #texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. #texinfo_show_urls = 'footnote' # If true, do not generate a @detailmenu in the "Top" node's menu. #texinfo_no_detailmenu = False # -- Options for Epub output ---------------------------------------------- # Bibliographic Dublin Core info. epub_title = metadata.__package_name__.replace('-', ' ').capitalize() epub_author = metadata.__author__ epub_publisher = metadata.__author__ epub_copyright = copyright # The HTML theme for the epub output. Since the default themes are not optimized # for small screen space, using the same theme for HTML and epub output is # usually not wise. This defaults to 'epub', a theme designed to save visual # space. #epub_theme = 'epub' # The language of the text. It defaults to the language option # or en if the language is not set. #epub_language = '' # The scheme of the identifier. Typical schemes are ISBN or URL. #epub_scheme = '' # The unique identifier of the text. This can be a ISBN number # or the project homepage. #epub_identifier = '' # A unique identification for the text. #epub_uid = '' # A tuple containing the cover image and cover page html template filenames. #epub_cover = () # A sequence of (type, uri, title) tuples for the guide element of content.opf. #epub_guide = () # HTML files that should be inserted before the pages created by sphinx. # The format is a list of tuples containing the path and title. #epub_pre_files = [] # HTML files shat should be inserted after the pages created by sphinx. # The format is a list of tuples containing the path and title. #epub_post_files = [] # A list of files that should not be packed into the epub file. epub_exclude_files = ['search.html'] # The depth of the table of contents in toc.ncx. #epub_tocdepth = 3 # Allow duplicate toc entries. #epub_tocdup = True # Choose between 'default' and 'includehidden'. #epub_tocscope = 'default' # Fix unsupported image types using the PIL. #epub_fix_images = False # Scale large images. #epub_max_image_width = 0 # How to display URL addresses: 'footnote', 'no', or 'inline'. #epub_show_urls = 'inline' # If false, no index is generated. #epub_use_index = True # Example configuration for intersphinx: refer to the Python standard library. intersphinx_mapping = {'http://docs.python.org/': None} portalocker-1.1.0/docs/index.rst000066400000000000000000000004341304610407200166250ustar00rootroot00000000000000Welcome to portalocker's documentation! ======================================== .. include :: ../README.rst Contents: .. toctree:: :maxdepth: 4 portalocker changelog license Indices and tables ================== * :ref:`genindex` * :ref:`modindex` * :ref:`search` portalocker-1.1.0/docs/license.rst000066400000000000000000000000601304610407200171330ustar00rootroot00000000000000License ======= .. literalinclude:: ../LICENSE portalocker-1.1.0/docs/make.bat000066400000000000000000000117621304610407200163770ustar00rootroot00000000000000@ECHO OFF REM Command file for Sphinx documentation if "%SPHINXBUILD%" == "" ( set SPHINXBUILD=sphinx-build ) set BUILDDIR=_build set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . set I18NSPHINXOPTS=%SPHINXOPTS% . if NOT "%PAPER%" == "" ( set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% ) if "%1" == "" goto help if "%1" == "help" ( :help echo.Please use `make ^` where ^ is one of echo. html to make standalone HTML files echo. dirhtml to make HTML files named index.html in directories echo. singlehtml to make a single large HTML file echo. pickle to make pickle files echo. json to make JSON files echo. htmlhelp to make HTML files and a HTML help project echo. qthelp to make HTML files and a qthelp project echo. devhelp to make HTML files and a Devhelp project echo. epub to make an epub echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter echo. text to make text files echo. man to make manual pages echo. texinfo to make Texinfo files echo. gettext to make PO message catalogs echo. changes to make an overview over all changed/added/deprecated items echo. linkcheck to check all external links for integrity echo. doctest to run all doctests embedded in the documentation if enabled goto end ) if "%1" == "clean" ( for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i del /q /s %BUILDDIR%\* goto end ) if "%1" == "html" ( %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html if errorlevel 1 exit /b 1 echo. echo.Build finished. The HTML pages are in %BUILDDIR%/html. goto end ) if "%1" == "dirhtml" ( %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml if errorlevel 1 exit /b 1 echo. echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. goto end ) if "%1" == "singlehtml" ( %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml if errorlevel 1 exit /b 1 echo. echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. goto end ) if "%1" == "pickle" ( %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle if errorlevel 1 exit /b 1 echo. echo.Build finished; now you can process the pickle files. goto end ) if "%1" == "json" ( %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json if errorlevel 1 exit /b 1 echo. echo.Build finished; now you can process the JSON files. goto end ) if "%1" == "htmlhelp" ( %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp if errorlevel 1 exit /b 1 echo. echo.Build finished; now you can run HTML Help Workshop with the ^ .hhp project file in %BUILDDIR%/htmlhelp. goto end ) if "%1" == "qthelp" ( %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp if errorlevel 1 exit /b 1 echo. echo.Build finished; now you can run "qcollectiongenerator" with the ^ .qhcp project file in %BUILDDIR%/qthelp, like this: echo.^> qcollectiongenerator %BUILDDIR%\qthelp\PythonUtils.qhcp echo.To view the help file: echo.^> assistant -collectionFile %BUILDDIR%\qthelp\PythonUtils.ghc goto end ) if "%1" == "devhelp" ( %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp if errorlevel 1 exit /b 1 echo. echo.Build finished. goto end ) if "%1" == "epub" ( %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub if errorlevel 1 exit /b 1 echo. echo.Build finished. The epub file is in %BUILDDIR%/epub. goto end ) if "%1" == "latex" ( %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex if errorlevel 1 exit /b 1 echo. echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. goto end ) if "%1" == "text" ( %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text if errorlevel 1 exit /b 1 echo. echo.Build finished. The text files are in %BUILDDIR%/text. goto end ) if "%1" == "man" ( %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man if errorlevel 1 exit /b 1 echo. echo.Build finished. The manual pages are in %BUILDDIR%/man. goto end ) if "%1" == "texinfo" ( %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo if errorlevel 1 exit /b 1 echo. echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. goto end ) if "%1" == "gettext" ( %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale if errorlevel 1 exit /b 1 echo. echo.Build finished. The message catalogs are in %BUILDDIR%/locale. goto end ) if "%1" == "changes" ( %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes if errorlevel 1 exit /b 1 echo. echo.The overview file is in %BUILDDIR%/changes. goto end ) if "%1" == "linkcheck" ( %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck if errorlevel 1 exit /b 1 echo. echo.Link check complete; look for any errors in the above output ^ or in %BUILDDIR%/linkcheck/output.txt. goto end ) if "%1" == "doctest" ( %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest if errorlevel 1 exit /b 1 echo. echo.Testing of doctests in the sources finished, look at the ^ results in %BUILDDIR%/doctest/output.txt. goto end ) :end portalocker-1.1.0/docs/portalocker.rst000066400000000000000000000003211304610407200200360ustar00rootroot00000000000000Portalocker =========== .. automodule:: portalocker :members: :undoc-members: :show-inheritance: Tests ===== .. automodule:: tests.tests :members: :undoc-members: :show-inheritance: portalocker-1.1.0/portalocker/000077500000000000000000000000001304610407200163605ustar00rootroot00000000000000portalocker-1.1.0/portalocker/__about__.py000066400000000000000000000003471304610407200206440ustar00rootroot00000000000000__package_name__ = 'portalocker' __author__ = 'Rick van Hattem' __email__ = 'wolph@wol.ph' __version__ = '1.1.0' __description__ = '''Wraps the portalocker recipe for easy usage''' __url__ = 'https://github.com/WoLpH/portalocker' portalocker-1.1.0/portalocker/__init__.py000066400000000000000000000032431304610407200204730ustar00rootroot00000000000000from . import __about__ from . import constants from . import exceptions from . import portalocker from . import utils #: The package name on Pypi __package_name__ = __about__.__package_name__ #: Current author and maintainer, view the git history for the previous ones __author__ = __about__.__author__ #: Current author's email address __email__ = __about__.__email__ #: Version number __version__ = __about__.__version__ #: Package description for Pypi __description__ = __about__.__description__ #: Package homepage __url__ = __about__.__url__ #: Exception thrown when the file is already locked by someone else AlreadyLocked = exceptions.AlreadyLocked #: Exception thrown if an error occurred during locking LockException = exceptions.LockException #: Lock a file. Note that this is an advisory lock on Linux/Unix systems lock = portalocker.lock #: Unlock a file unlock = portalocker.unlock #: Place an exclusive lock. #: Only one process may hold an exclusive lock for a given file at a given #: time. LOCK_EX = constants.LOCK_EX #: Place a shared lock. #: More than one process may hold a shared lock for a given file at a given #: time. LOCK_SH = constants.LOCK_SH #: Acquire the lock in a non-blocking fashion. LOCK_NB = constants.LOCK_NB #: Remove an existing lock held by this process. LOCK_UN = constants.LOCK_UN #: Locking utility class to automatically handle opening with timeouts and #: context wrappers Lock = utils.Lock TemporaryFileLock = utils.TemporaryFileLock open_atomic = utils.open_atomic __all__ = [ 'lock', 'unlock', 'LOCK_EX', 'LOCK_SH', 'LOCK_NB', 'LOCK_UN', 'LockException', 'Lock', 'AlreadyLocked', 'open_atomic', ] portalocker-1.1.0/portalocker/constants.py000066400000000000000000000010521304610407200207440ustar00rootroot00000000000000import os # The actual tests will execute the code anyhow so the following code can # safely be ignored from the coverage tests if os.name == 'nt': # pragma: no cover import msvcrt LOCK_EX = 0x1 LOCK_SH = 0x2 LOCK_NB = 0x4 LOCK_UN = msvcrt.LK_UNLCK elif os.name == 'posix': # pragma: no cover import fcntl LOCK_EX = fcntl.LOCK_EX LOCK_SH = fcntl.LOCK_SH LOCK_NB = fcntl.LOCK_NB LOCK_UN = fcntl.LOCK_UN else: # pragma: no cover raise RuntimeError('PortaLocker only defined for nt and posix platforms') portalocker-1.1.0/portalocker/exceptions.py000066400000000000000000000003421304610407200211120ustar00rootroot00000000000000class BaseLockException(Exception): # Error codes: LOCK_FAILED = 1 class LockException(BaseLockException): pass class AlreadyLocked(BaseLockException): pass class FileToLarge(BaseLockException): pass portalocker-1.1.0/portalocker/portalocker.py000066400000000000000000000061221304610407200212600ustar00rootroot00000000000000import os from . import exceptions from . import constants if os.name == 'nt': # pragma: no cover import msvcrt def lock(file_, flags): if flags & constants.LOCK_SH: if flags & constants.LOCK_NB: mode = msvcrt.LK_NBRLCK else: mode = msvcrt.LK_RLOCK else: if flags & constants.LOCK_NB: mode = msvcrt.LK_NBLCK else: mode = msvcrt.LK_LOCK # windows locks byte ranges, so make sure to lock from file start try: savepos = file_.tell() file_.seek(0, os.SEEK_END) if file_.tell() > 0x7fffffff: raise exceptions.FileToLarge("Files larger than 2GB " "not supported on Windows") # [ ] test exclusive lock fails on seek here # [ ] test if shared lock passes this point file_.seek(0) try: # [x] check if 0 param locks entire file (not documented in # Python) # [x] just fails with "IOError: [Errno 13] Permission denied", # [x] -1 crashes on py3.5+ # [x] larger than 0x7fffffff gives OverflowError # [ ] writing past 2GB goes to unlocked space, should not # be a problem when only using portalocker, since it # always locks from the start msvcrt.locking(file_.fileno(), mode, 0x7fffffff) except IOError as exc_value: # [ ] be more specific here raise exceptions.LockException( exceptions.LockException.LOCK_FAILED, exc_value.strerror) finally: if savepos: file_.seek(savepos) except IOError as exc_value: raise exceptions.LockException( exceptions.LockException.LOCK_FAILED, exc_value.strerror) def unlock(file_): try: savepos = file_.tell() if savepos: file_.seek(0) try: msvcrt.locking(file_.fileno(), constants.LOCK_UN, 0x7fffffff) except IOError as exc_value: raise exceptions.LockException( exceptions.LockException.LOCK_FAILED, exc_value.strerror) finally: if savepos: file_.seek(savepos) except IOError as exc_value: raise exceptions.LockException( exceptions.LockException.LOCK_FAILED, exc_value.strerror) elif os.name == 'posix': # pragma: no cover import fcntl def lock(file_, flags): try: fcntl.flock(file_.fileno(), flags) except IOError as exc_value: # The exception code varies on different systems so we'll catch # every IO error raise exceptions.LockException(exc_value) def unlock(file_): fcntl.flock(file_.fileno(), constants.LOCK_UN) else: # pragma: no cover raise RuntimeError('PortaLocker only defined for nt and posix platforms') portalocker-1.1.0/portalocker/utils.py000066400000000000000000000143531304610407200201000ustar00rootroot00000000000000import os import time import atexit import tempfile import contextlib from . import exceptions from . import constants from . import portalocker current_time = getattr(time, "monotonic", time.time) DEFAULT_TIMEOUT = 5 DEFAULT_CHECK_INTERVAL = 0.25 LOCK_METHOD = constants.LOCK_EX | constants.LOCK_NB __all__ = [ 'Lock', 'open_atomic', ] @contextlib.contextmanager def open_atomic(filename, binary=True): '''Open a file for atomic writing. Instead of locking this method allows you to write the entire file and move it to the actual location. Note that this makes the assumption that a rename is atomic on your platform which is generally the case but not a guarantee. http://docs.python.org/library/os.html#os.rename >>> filename = 'test_file.txt' >>> if os.path.exists(filename): ... os.remove(filename) >>> with open_atomic(filename) as fh: ... written = fh.write(b'test') >>> assert os.path.exists(filename) >>> os.remove(filename) ''' assert not os.path.exists(filename), '%r exists' % filename path, name = os.path.split(filename) # Create the parent directory if it doesn't exist if path and not os.path.isdir(path): # pragma: no cover os.makedirs(path) temp_fh = tempfile.NamedTemporaryFile( mode=binary and 'wb' or 'w', dir=path, delete=False, ) yield temp_fh temp_fh.flush() os.fsync(temp_fh.fileno()) temp_fh.close() try: os.rename(temp_fh.name, filename) finally: try: os.remove(temp_fh.name) except Exception: pass class Lock(object): def __init__( self, filename, mode='a', timeout=DEFAULT_TIMEOUT, check_interval=DEFAULT_CHECK_INTERVAL, fail_when_locked=False, flags=LOCK_METHOD): '''Lock manager with build-in timeout filename -- filename mode -- the open mode, 'a' or 'ab' should be used for writing truncate -- use truncate to emulate 'w' mode, None is disabled, 0 is truncate to 0 bytes timeout -- timeout when trying to acquire a lock check_interval -- check interval while waiting fail_when_locked -- after the initial lock failed, return an error or lock the file fail_when_locked is useful when multiple threads/processes can race when creating a file. If set to true than the system will wait till the lock was acquired and then return an AlreadyLocked exception. Note that the file is opened first and locked later. So using 'w' as mode will result in truncate _BEFORE_ the lock is checked. ''' if 'w' in mode: truncate = True mode = mode.replace('w', 'a') else: truncate = False self.fh = None self.filename = filename self.mode = mode self.truncate = truncate self.timeout = timeout self.check_interval = check_interval self.fail_when_locked = fail_when_locked self.flags = flags def acquire( self, timeout=None, check_interval=None, fail_when_locked=None): '''Acquire the locked filehandle''' if timeout is None: timeout = self.timeout if timeout is None: timeout = 0 if check_interval is None: check_interval = self.check_interval if fail_when_locked is None: fail_when_locked = self.fail_when_locked # If we already have a filehandle, return it fh = self.fh if fh: return fh # Get a new filehandler fh = self._get_fh() try: # Try to lock fh = self._get_lock(fh) except exceptions.LockException as exception: # Try till the timeout has passed timeoutend = current_time() + timeout while timeoutend > current_time(): # Wait a bit time.sleep(check_interval) # Try again try: # We already tried to the get the lock # If fail_when_locked is true, then stop trying if fail_when_locked: raise exceptions.AlreadyLocked(exception) else: # pragma: no cover # We've got the lock fh = self._get_lock(fh) break except exceptions.LockException: pass else: # We got a timeout... reraising raise exceptions.LockException(exception) # Prepare the filehandle (truncate if needed) fh = self._prepare_fh(fh) self.fh = fh return fh def release(self): '''Releases the currently locked file handle''' if self.fh: self.fh.close() self.fh = None def _get_fh(self): '''Get a new filehandle''' return open(self.filename, self.mode) def _get_lock(self, fh): ''' Try to lock the given filehandle returns LockException if it fails''' portalocker.lock(fh, self.flags) return fh def _prepare_fh(self, fh): ''' Prepare the filehandle for usage If truncate is a number, the file will be truncated to that amount of bytes ''' if self.truncate: fh.seek(0) fh.truncate(0) return fh def __enter__(self): return self.acquire() def __exit__(self, type_, value, tb): self.release() def __delete__(self, instance): # pragma: no cover instance.release() class TemporaryFileLock(Lock): def __init__(self, filename='.lock', timeout=DEFAULT_TIMEOUT, check_interval=DEFAULT_CHECK_INTERVAL, fail_when_locked=True, flags=LOCK_METHOD): Lock.__init__(self, filename=filename, mode='w', timeout=timeout, check_interval=check_interval, fail_when_locked=fail_when_locked, flags=flags) atexit.register(self.release) def release(self): Lock.release(self) if os.path.isfile(self.filename): # pragma: no branch os.unlink(self.filename) portalocker-1.1.0/pytest.ini000066400000000000000000000005751304610407200160730ustar00rootroot00000000000000[pytest] python_files = tests/*.py addopts = --ignore setup.py --ignore portalocker/_*.py --doctest-modules --cov portalocker --cov-report term-missing --cov-report html --no-cov-on-fail --pep8 --flakes pep8ignore = *.py W391 runtests.py ALL docs/*.py ALL flakes-ignore = *.py W391 runtests.py ALL docs/*.py ALL portalocker-1.1.0/setup.cfg000066400000000000000000000003271304610407200156560ustar00rootroot00000000000000[metadata] description-file = README.rst [build_sphinx] source-dir = docs/ build-dir = docs/_build all_files = 1 [upload_sphinx] upload-dir = docs/_build/html [bdist_wheel] universal = 1 [aliases] test=pytest portalocker-1.1.0/setup.py000066400000000000000000000070401304610407200155460ustar00rootroot00000000000000from __future__ import print_function import re import os import setuptools # To prevent importing about and thereby breaking the coverage info we use this # exec hack about = {} with open('portalocker/__about__.py') as fp: exec(fp.read(), about) test_requirements_file = os.path.join('tests', 'requirements.txt') if os.path.isfile(test_requirements_file): with open(test_requirements_file) as fh: tests_require = fh.read().splitlines() else: tests_require = ['pytest>=3.0'] class Combine(setuptools.Command): description = 'Build single combined portalocker file' relative_import_re = re.compile(r'^from \. import (?P.+)$', re.MULTILINE) user_options = [ ('output-file=', 'o', 'Path to the combined output file'), ] def initialize_options(self): self.output_file = os.path.join( 'dist', '%(package_name)s_%(version)s.py' % dict( package_name=about['__package_name__'], version=about['__version__'].replace('.', '-'), )) def finalize_options(self): pass def run(self): dirname = os.path.dirname(self.output_file) if dirname and not os.path.isdir(dirname): os.makedirs(dirname) output = open(self.output_file, 'w') print("'''", file=output) with open('README.rst') as fh: output.write(fh.read().rstrip()) print('', file=output) print('', file=output) with open('LICENSE') as fh: output.write(fh.read().rstrip()) print('', file=output) print("'''", file=output) names = set() lines = [] for line in open('portalocker/__init__.py'): match = self.relative_import_re.match(line) if match: names.add(match.group('name')) with open('portalocker/%(name)s.py' % match.groupdict()) as fh: line = fh.read() line = self.relative_import_re.sub('', line) lines.append(line) import_attributes = re.compile(r'\b(%s)\.' % '|'.join(names)) for line in lines[:]: line = import_attributes.sub('', line) output.write(line) print('Wrote combined file to %r' % self.output_file) if __name__ == '__main__': setuptools.setup( name=about['__package_name__'], version=about['__version__'], description=about['__description__'], long_description=open('README.rst').read(), classifiers=[ 'Intended Audience :: Developers', 'Programming Language :: Python', 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: Implementation :: CPython', 'Programming Language :: Python :: Implementation :: PyPy', ], keywords='locking, locks, with statement, windows, linux, unix', author=about['__author__'], author_email=about['__email__'], url=about['__url__'], license='PSF', packages=setuptools.find_packages(exclude=['ez_setup', 'examples']), # zip_safe=False, platforms=['any'], cmdclass={ 'combine': Combine, }, setup_requires=[ 'pytest-runner', ], tests_require=tests_require, ) portalocker-1.1.0/tests/000077500000000000000000000000001304610407200151755ustar00rootroot00000000000000portalocker-1.1.0/tests/conftest.py000066400000000000000000000004411304610407200173730ustar00rootroot00000000000000import py import pytest @pytest.fixture def tmpfile(tmpdir_factory): tmpdir = tmpdir_factory.mktemp('temp') filename = tmpdir.join('tmpfile') yield str(filename) try: filename.remove(ignore_errors=True) except (py.error.EBUSY, py.error.ENOENT): pass portalocker-1.1.0/tests/requirements.txt000066400000000000000000000001161304610407200204570ustar00rootroot00000000000000pytest>=3.0 pytest-cache pytest-cov pytest-flakes pytest-pep8 Sphinx Pygments portalocker-1.1.0/tests/temporary_file_lock.py000066400000000000000000000004001304610407200215720ustar00rootroot00000000000000import os import portalocker def test_temporary_file_lock(tmpfile): with portalocker.TemporaryFileLock(tmpfile): pass assert not os.path.isfile(tmpfile) lock = portalocker.TemporaryFileLock(tmpfile) lock.acquire() del lock portalocker-1.1.0/tests/test_combined.py000066400000000000000000000005061304610407200203670ustar00rootroot00000000000000import sys def test_combined(tmpdir): from distutils import dist import setup output_file = tmpdir.join('combined.py') combine = setup.Combine(dist.Distribution()) combine.output_file = str(output_file) combine.run() sys.path.append(output_file.dirname) import combined assert combined portalocker-1.1.0/tests/tests.py000066400000000000000000000064101304610407200167120ustar00rootroot00000000000000from __future__ import print_function from __future__ import with_statement import pytest import portalocker def test_exceptions(tmpfile): # Open the file 2 times a = open(tmpfile, 'a') b = open(tmpfile, 'a') # Lock exclusive non-blocking lock_flags = portalocker.LOCK_EX | portalocker.LOCK_NB # First lock file a portalocker.lock(a, lock_flags) # Now see if we can lock file b with pytest.raises(portalocker.LockException): portalocker.lock(b, lock_flags) # Cleanup a.close() b.close() def test_with_timeout(tmpfile): # Open the file 2 times with pytest.raises(portalocker.AlreadyLocked): with portalocker.Lock(tmpfile, timeout=0.1) as fh: print('writing some stuff to my cache...', file=fh) with portalocker.Lock(tmpfile, timeout=0.1, mode='wb', fail_when_locked=True): pass print('writing more stuff to my cache...', file=fh) def test_without_timeout(tmpfile): # Open the file 2 times with pytest.raises(portalocker.LockException): with portalocker.Lock(tmpfile, timeout=None) as fh: print('writing some stuff to my cache...', file=fh) with portalocker.Lock(tmpfile, timeout=None, mode='w'): pass print('writing more stuff to my cache...', file=fh) def test_without_fail(tmpfile): # Open the file 2 times with pytest.raises(portalocker.LockException): with portalocker.Lock(tmpfile, timeout=0.1) as fh: print('writing some stuff to my cache...', file=fh) lock = portalocker.Lock(tmpfile, timeout=0.1) lock.acquire(check_interval=0.05, fail_when_locked=False) def test_simple(tmpfile): with open(tmpfile, 'w') as fh: fh.write('spam and eggs') fh = open(tmpfile, 'r+') portalocker.lock(fh, portalocker.LOCK_EX) fh.seek(13) fh.write('foo') # Make sure we didn't overwrite the original text fh.seek(0) assert fh.read(13) == 'spam and eggs' portalocker.unlock(fh) fh.close() def test_truncate(tmpfile): with open(tmpfile, 'w') as fh: fh.write('spam and eggs') with portalocker.Lock(tmpfile, mode='a+') as fh: # Make sure we didn't overwrite the original text fh.seek(0) assert fh.read(13) == 'spam and eggs' with portalocker.Lock(tmpfile, mode='w+') as fh: # Make sure we truncated the file assert fh.read() == '' def test_class(tmpfile): lock = portalocker.Lock(tmpfile) lock2 = portalocker.Lock(tmpfile, fail_when_locked=False, timeout=0.01) with lock: lock.acquire() with pytest.raises(portalocker.LockException): with lock2: pass with lock2: pass def test_acquire_release(tmpfile): lock = portalocker.Lock(tmpfile) lock2 = portalocker.Lock(tmpfile, fail_when_locked=False) lock.acquire() # acquire lock when nobody is using it with pytest.raises(portalocker.LockException): # another party should not be able to acquire the lock lock2.acquire(timeout=0.01) # re-acquire a held lock is a no-op lock.acquire() lock.release() # release the lock lock.release() # second release does nothing portalocker-1.1.0/tox.ini000066400000000000000000000002721304610407200153470ustar00rootroot00000000000000[tox] envlist = py26,py27,pypy,pypy3,py33,py34,py35 skip_missing_interpreters = True [testenv] deps = -r{toxinidir}/tests/requirements.txt commands = {envpython} setup.py test