././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1613869489.5335095 pyperclip-1.8.2/0000777000000000000000000000000000000000000010424 5ustar00././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1601854721.0 pyperclip-1.8.2/AUTHORS.txt0000666000000000000000000000360500000000000012316 0ustar00Here is an inevitably incomplete list of MUCH-APPRECIATED CONTRIBUTORS -- people who have submitted patches, reported bugs, added translations, helped answer newbie questions, and generally made Pyperclip that much better: Al Sweigart Alexander Cobleigh ‏@cblgh Andrea Scarpino https://github.com/ilpianista Aniket Pandey https://github.com/lordaniket06 Anton Yakutovich https://github.com/drakulavich Brian Levin https://github.com/bnice5000 Carvell Scott https://github.com/CarvellScott Cees Timmerman https://github.com/CTimmerman Chris Clark Christopher Lambert https://github.com/XN137 Chris Woerz https://github.com/erendrake Edd Barrett https://github.com/vext01 Eugene Yang https://github.com/eugene-yang Felix Yan https://github.com/felixonmars fthoma https://github.com/fthoma Greg Witt https://github.com/GoodGuyGregory hinlader https://github.com/hinlader Hugo https://github.com/hugovk Hynek Cernoch https://github.com/hynekcer Jason R. Coombs https://github.com/jaraco Jon Crall https://github.com/Erotemic Jonathan Slenders https://github.com/jonathanslenders JustAShoeMaker https://github.com/JustAShoeMaker Marcelo Glezer https://github.com/gato Maximilian Hils https://github.com/mhils Michał Górny https://github.com/mgorny Nikolaos-Digenis Karagiannis https://github.com/Digenis Nils Ohlmeier https://github.com/nils-ohlmeier Orson Peters https://github.com/orlp pgajdos https://github.com/pgajdos Six https://github.com/brbsix Stefan Devai https://github.com/stefandevai Stefan Scherfke https://github.com/sscherfke Steve Elam Tamir Bahar https://github.com/tmr232 Terrel Shumway https://github.com/lernisto Tim Cuthbertson https://github.com/timbertson Todd Leonhardt https://github.com/tleonhardt Troy Sankey https://github.com/pwnage101 utagawa kiki https://github.com/utgwkk Vince West https://github.com/dvincentwest ZEDGR https://github.com/ZEDGR ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1537830667.0 pyperclip-1.8.2/CHANGES.txt0000666000000000000000000000700300000000000012235 0ustar00v1.7.0, 2018/09/24 -- Added ability to read/write clipboard by running `python -m pyperclip` v1.6.5, 2018/09/24 -- Fix for issue #129, where unicode text caused exceptions on Python 2. v1.6.4, 2018/07/18 -- Adjusted setup.py to include the long description. v1.6.3, 2018/07/18 -- Adjusted setup.py to include the long description. v1.6.2, 2018/07/18 -- Adjusted setup.py to include the long description. v1.6.1, 2018/07/18 -- Adjusted setup.py to include the long description. v1.6.1, 2018/05/23 -- Added Windows subsystem for Linux support. v1.5.32, 2017/10/29 -- Added limited cygwin support. v1.5.31, 2017/10/29 -- Fixed another mistake where 'posix' was checked for OS X instead of 'mac' due to a mistaken merge. Added lazy loading. v1.5.30, 2017/10/29 -- Fixed the encoding that was set to "uft-8" v1.5.29, 2017/10/29 -- Pyperclip works with qtpy module, osx can use objc now, set pyqt as lower priority than xsel/xclip/klipper, add support for PyQt5 v1.5.28, 2017/10/28 -- Capture stderr of xclip subprocess, fixed issue #88 where emojii cut off the last character, allowed selection between PRIMARY and CLIPBOARD for xsel and xclip v1.5.27, 2016/03/14 -- Disable broken cygwin implementation until issue 55 can be fixed v1.5.26, 2016/01/20 -- Fix #51, Replace wcscpy_s with memmove for Windows XP. v1.5.25, 2015/12/13 -- Fix #53, PEP8 changes, STRING_FUNCTION rename v1.5.24, 2015/11/14 -- Fix for Import ctypes.wintypes on Linux issue. v1.5.23, 2015/11/14 -- v1.5.22, 2015/11/08 -- Fix segfault for PyQt4 copy/paste functions v1.5.21, 2015/11/04 -- Import fixes. v1.5.20, 2015/10/30 -- Big refactoring and testing additions from mhils. Thanks! v1.5.19, 2015/10/29 -- Updating setup.py to pull version info from __init__.py v1.5.18, 2015/10/29 -- Added _noCopy/_noPaste functions to raise NotImplementedError exceptions when called, instead of raising exceptions when Pyperclip is imported. v1.5.17, 2015/10/28 -- Refactoring to add determineFunctionSet() and setFunctions() functions. v1.5.16, 2015/10/28 -- Fix issue 31, Klipper adds newline to the end of the pasted text. v1.5.15, 2015/10/12 -- Removing _pyperclip.py file which accidentally got included in the PyPI package. v1.5.14, 2015/10/09 -- Fixed major Windows problems. v1.5.13, 2015/09/23 -- Added other python versions to the setup.py file. v1.5.12, 2015/09/18 -- Added _pasteKlipper() & _copyKlipper(). Thanks contrixed! v1.5.11, 2015/06/01 -- remove str() from _copy functions. Fix for ascii default encoding v1.5.10, 2015/05/22 -- Fixed pasting from xsel and on mac. v1.5.9, 2015/02/17 -- Refactoring for Python 2/3 compatibility. v1.5.8, 2015/02/05 -- Bug fixes. xsel: copy to clipboard, don't inherit fds, fds closes for xclip v1.5.7, 2014/12/07 -- Bug fix for issue 10 (calling OpenClipboard on Windows with wrong argument.) v1.5.6, 2014/12/05 -- Corrections for copying on Windows. v1.5.5, 2014/12/04 -- Bug fix for unicode on Windows. v1.5.4, 2014/09/09 -- Undoing OS X paste() bug fix because it requires 2.7, breaks pre2.7 versions. v1.5.3, 2014/09/05 -- Bug fix for OS X paste(). Thanks to sscherfke v1.5.2, 2014/08/24 -- Bug fix in xsel paste function. Thanks to Nikolaos-Digenis Karagiannis. v1.5.0, 2014/08/16 -- Refactored code to put it on PyPI. Also added support on Cygwin platforms and unit tests. v1.3.0, 2011/09/13 -- Changed ctypes.windll.user32.OpenClipboard(None) to ctypes.windll.user32.OpenClipboard(0), after some people ran into some TypeError v1.2.0, 2011/06/14 -- Use the platform module to help determine OS. ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1450065682.0 pyperclip-1.8.2/LICENSE.txt0000666000000000000000000000275200000000000012255 0ustar00Copyright (c) 2014, Al Sweigart All rights reserved. Redistribution and use in source and binary forms, 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. * Neither the name of the {organization} nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE 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 HOLDER 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 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1601856435.0 pyperclip-1.8.2/MANIFEST.in0000666000000000000000000000032700000000000012164 0ustar00include *.md include *.txt recursive-include docs *.bat recursive-include docs *.py recursive-include docs *.rst recursive-include docs Makefile recursive-include pyperclip *.py recursive-include tests *.py ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1613869489.5323513 pyperclip-1.8.2/PKG-INFO0000666000000000000000000000476100000000000011531 0ustar00Metadata-Version: 1.1 Name: pyperclip Version: 1.8.2 Summary: A cross-platform clipboard module for Python. (Only handles plain text for now.) Home-page: https://github.com/asweigart/pyperclip Author: Al Sweigart Author-email: al@inventwithpython.com License: BSD Description: Pyperclip is a cross-platform Python module for copy and paste clipboard functions. It works with Python 2 and 3. Install on Windows: `pip install pyperclip` Install on Linux/macOS: `pip3 install pyperclip` Al Sweigart al@inventwithpython.com BSD License Example Usage ============= >>> import pyperclip >>> pyperclip.copy('The text to be copied to the clipboard.') >>> pyperclip.paste() 'The text to be copied to the clipboard.' Currently only handles plaintext. On Windows, no additional modules are needed. On Mac, this module makes use of the pbcopy and pbpaste commands, which should come with the os. On Linux, this module makes use of the xclip or xsel commands, which should come with the os. Otherwise run "sudo apt-get install xclip" or "sudo apt-get install xsel" (Note: xsel does not always seem to work.) Otherwise on Linux, you will need the gtk or PyQt4 modules installed. Keywords: clipboard copy paste clip xsel xclip Platform: UNKNOWN Classifier: Development Status :: 5 - Production/Stable Classifier: Environment :: Win32 (MS Windows) Classifier: Environment :: X11 Applications Classifier: Environment :: MacOS X Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.1 Classifier: Programming Language :: Python :: 3.2 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 Classifier: Programming Language :: Python :: 3.6 Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: 3.9 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1601854670.0 pyperclip-1.8.2/README.md0000666000000000000000000000165600000000000011713 0ustar00Pyperclip is a cross-platform Python module for copy and paste clipboard functions. It works with Python 2 and 3. Install on Windows: `pip install pyperclip` Install on Linux/macOS: `pip3 install pyperclip` Al Sweigart al@inventwithpython.com BSD License Example Usage ============= >>> import pyperclip >>> pyperclip.copy('The text to be copied to the clipboard.') >>> pyperclip.paste() 'The text to be copied to the clipboard.' Currently only handles plaintext. On Windows, no additional modules are needed. On Mac, this module makes use of the pbcopy and pbpaste commands, which should come with the os. On Linux, this module makes use of the xclip or xsel commands, which should come with the os. Otherwise run "sudo apt-get install xclip" or "sudo apt-get install xsel" (Note: xsel does not always seem to work.) Otherwise on Linux, you will need the gtk or PyQt4 modules installed. ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1613869489.4252043 pyperclip-1.8.2/docs/0000777000000000000000000000000000000000000011354 5ustar00././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1450065682.0 pyperclip-1.8.2/docs/Makefile0000666000000000000000000001544700000000000013027 0ustar00# Makefile for Sphinx documentation # # You can set these variables from the command line. SPHINXOPTS = SPHINXBUILD = sphinx-build PAPER = BUILDDIR = _build # User-friendly check for sphinx-build ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) endif # 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 " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" @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 " xml to make Docutils-native XML files" @echo " pseudoxml to make pseudoxml-XML files for display purposes" @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/Pyperclip.qhcp" @echo "To view the help file:" @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/Pyperclip.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/Pyperclip" @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/Pyperclip" @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." latexpdfja: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo "Running LaTeX files through platex and dvipdfmx..." $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja @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." xml: $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml @echo @echo "Build finished. The XML files are in $(BUILDDIR)/xml." pseudoxml: $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml @echo @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1450065682.0 pyperclip-1.8.2/docs/conf.py0000666000000000000000000002035500000000000012660 0ustar00#!/usr/bin/env python3 # -*- coding: utf-8 -*- # # Pyperclip documentation build configuration file, created by # sphinx-quickstart on Fri Aug 15 22:34:37 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 sys import os # 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.abspath('.')) # -- 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 = [] # 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 = 'Pyperclip' copyright = '2014, Al Sweigart' # 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 = '1.5' # The full version, including alpha/beta/rc tags. release = '1.5' # 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 = 'default' # 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 = [] # 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 = 'Pyperclipdoc' # -- 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, or own class]). latex_documents = [ ('index', 'Pyperclip.tex', 'Pyperclip Documentation', 'Al Sweigart', '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', 'pyperclip', 'Pyperclip Documentation', ['Al Sweigart'], 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', 'Pyperclip', 'Pyperclip Documentation', 'Al Sweigart', 'Pyperclip', 'One line description of project.', '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 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1585440492.0 pyperclip-1.8.2/docs/index.rst0000666000000000000000000000527700000000000013230 0ustar00.. Pyperclip documentation master file, created by sphinx-quickstart on Fri Aug 15 22:34:37 2014. You can adapt this file completely to your liking, but it should at least contain the root `toctree` directive. .. default-role:: code Welcome to Pyperclip's documentation! ===================================== Pyperclip provides a cross-platform Python module for copying and pasting text to the clipboard. To copy text to the clipboard, pass a string to ``pyperclip.copy()``. To paste the text from the clipboard, call ``pyperclip.paste()`` and the text will be returned as a string value. .. code:: python >>> import pyperclip >>> pyperclip.copy('Hello, world!') >>> pyperclip.paste() 'Hello, world!' Pyperclip also has a `pyperclip.waitForPaste()` function, which blocks and doesn't return until a non-empty text string is on the clipboard. It then returns this string. The `pyperclip.waitForNewPaste()` blocks until the text on the clipboard has changed: .. code:: python >>> import pyperclip >>> pyperclip.waitForPaste() # Doesn't return until non-empty text is on the clipboard. 'Hello, world!' >>> pyperclip.copy('original text') >>> pyperclip.waitForNewPaste() # Doesn't return until the clipboard has something other than "original text". 'Hello, world!' These functions also have a `timeout` argument to specify a number of seconds to check. If the timeout elapses without returning, the functions raise a `PyperclipTimeoutException` exception: >>> import pyperclip >>> pyperclip.waitForNewPaste(5) Traceback (most recent call last): File "", line 1, in File "c:\github\pyperclip\src\pyperclip\__init__.py", line 689, in waitForNewPaste raise PyperclipTimeoutException('waitForNewPaste() timed out after ' + str(timeout) + ' seconds.') pyperclip.PyperclipTimeoutException: waitForNewPaste() timed out after 5 seconds. Not Implemented Error ===================== You may get an error message that says: "Pyperclip could not find a copy/paste mechanism for your system. Please see https://pyperclip.readthedocs.io/en/latest/introduction.html#not-implemented-error for how to fix this." In order to work equally well on Windows, Mac, and Linux, Pyperclip uses various mechanisms to do this. Currently, this error should only appear on Linux (not Windows or Mac). You can fix this by installing one of the copy/paste mechanisms: - ``sudo apt-get install xsel`` to install the xsel utility. - ``sudo apt-get install xclip`` to install the xclip utility. - ``pip install gtk`` to install the gtk Python module. - ``pip install PyQt4`` to install the PyQt4 Python module. ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1450065682.0 pyperclip-1.8.2/docs/make.bat0000777000000000000000000001506300000000000012771 0ustar00@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. xml to make Docutils-native XML files echo. pseudoxml to make pseudoxml-XML files for display purposes 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 ) %SPHINXBUILD% 2> nul if errorlevel 9009 ( echo. echo.The 'sphinx-build' command was not found. Make sure you have Sphinx echo.installed, then set the SPHINXBUILD environment variable to point echo.to the full path of the 'sphinx-build' executable. Alternatively you echo.may add the Sphinx directory to PATH. echo. echo.If you don't have Sphinx installed, grab it from echo.http://sphinx-doc.org/ exit /b 1 ) 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\Pyperclip.qhcp echo.To view the help file: echo.^> assistant -collectionFile %BUILDDIR%\qthelp\Pyperclip.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" == "latexpdf" ( %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex cd %BUILDDIR%/latex make all-pdf cd %BUILDDIR%/.. echo. echo.Build finished; the PDF files are in %BUILDDIR%/latex. goto end ) if "%1" == "latexpdfja" ( %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex cd %BUILDDIR%/latex make all-pdf-ja cd %BUILDDIR%/.. echo. echo.Build finished; the PDF 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 ) if "%1" == "xml" ( %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml if errorlevel 1 exit /b 1 echo. echo.Build finished. The XML files are in %BUILDDIR%/xml. goto end ) if "%1" == "pseudoxml" ( %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml if errorlevel 1 exit /b 1 echo. echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. goto end ) :end ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1613869489.5335095 pyperclip-1.8.2/setup.cfg0000666000000000000000000000005200000000000012242 0ustar00[egg_info] tag_build = tag_date = 0 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1602380259.0 pyperclip-1.8.2/setup.py0000666000000000000000000000374600000000000012150 0ustar00import re from setuptools import setup, find_packages # Load version from module (without loading the whole module) with open('src/pyperclip/__init__.py', 'r') as fd: version = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]', fd.read(), re.MULTILINE).group(1) # Read in the README.md for the long description. with open("README.md", "r") as fh: long_description = fh.read() # Dynamically calculate the version based on pyperclip.VERSION. setup( name='pyperclip', version=version, url='https://github.com/asweigart/pyperclip', author='Al Sweigart', author_email='al@inventwithpython.com', description=('A cross-platform clipboard module for Python. (Only handles plain text for now.)'), long_description=long_description, license='BSD', packages=find_packages(where='src'), package_dir={'': 'src'}, test_suite='tests', keywords="clipboard copy paste clip xsel xclip", classifiers=[ 'Development Status :: 5 - Production/Stable', 'Environment :: Win32 (MS Windows)', 'Environment :: X11 Applications', 'Environment :: MacOS X', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', 'Operating System :: OS Independent', 'Programming Language :: Python', 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.1', 'Programming Language :: Python :: 3.2', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', ], ) ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1613869489.204844 pyperclip-1.8.2/src/0000777000000000000000000000000000000000000011213 5ustar00././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1613869489.439213 pyperclip-1.8.2/src/pyperclip/0000777000000000000000000000000000000000000013222 5ustar00././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1613869448.0 pyperclip-1.8.2/src/pyperclip/__init__.py0000666000000000000000000006267300000000000015351 0ustar00""" Pyperclip A cross-platform clipboard module for Python, with copy & paste functions for plain text. By Al Sweigart al@inventwithpython.com BSD License Usage: import pyperclip pyperclip.copy('The text to be copied to the clipboard.') spam = pyperclip.paste() if not pyperclip.is_available(): print("Copy functionality unavailable!") On Windows, no additional modules are needed. On Mac, the pyobjc module is used, falling back to the pbcopy and pbpaste cli commands. (These commands should come with OS X.). On Linux, install xclip, xsel, or wl-clipboard (for "wayland" sessions) via package manager. For example, in Debian: sudo apt-get install xclip sudo apt-get install xsel sudo apt-get install wl-clipboard Otherwise on Linux, you will need the gtk or PyQt5/PyQt4 modules installed. gtk and PyQt4 modules are not available for Python 3, and this module does not work with PyGObject yet. Note: There seems to be a way to get gtk on Python 3, according to: https://askubuntu.com/questions/697397/python3-is-not-supporting-gtk-module Cygwin is currently not supported. Security Note: This module runs programs with these names: - which - where - pbcopy - pbpaste - xclip - xsel - wl-copy/wl-paste - klipper - qdbus A malicious user could rename or add programs with these names, tricking Pyperclip into running them with whatever permissions the Python process has. """ __version__ = '1.8.2' import contextlib import ctypes import os import platform import subprocess import sys import time import warnings from ctypes import c_size_t, sizeof, c_wchar_p, get_errno, c_wchar # `import PyQt4` sys.exit()s if DISPLAY is not in the environment. # Thus, we need to detect the presence of $DISPLAY manually # and not load PyQt4 if it is absent. HAS_DISPLAY = os.getenv("DISPLAY", False) EXCEPT_MSG = """ Pyperclip could not find a copy/paste mechanism for your system. For more information, please visit https://pyperclip.readthedocs.io/en/latest/index.html#not-implemented-error """ PY2 = sys.version_info[0] == 2 STR_OR_UNICODE = unicode if PY2 else str # For paste(): Python 3 uses str, Python 2 uses unicode. ENCODING = 'utf-8' try: from shutil import which as _executable_exists except ImportError: # The "which" unix command finds where a command is. if platform.system() == 'Windows': WHICH_CMD = 'where' else: WHICH_CMD = 'which' def _executable_exists(name): return subprocess.call([WHICH_CMD, name], stdout=subprocess.PIPE, stderr=subprocess.PIPE) == 0 # Exceptions class PyperclipException(RuntimeError): pass class PyperclipWindowsException(PyperclipException): def __init__(self, message): message += " (%s)" % ctypes.WinError() super(PyperclipWindowsException, self).__init__(message) class PyperclipTimeoutException(PyperclipException): pass def _stringifyText(text): if PY2: acceptedTypes = (unicode, str, int, float, bool) else: acceptedTypes = (str, int, float, bool) if not isinstance(text, acceptedTypes): raise PyperclipException('only str, int, float, and bool values can be copied to the clipboard, not %s' % (text.__class__.__name__)) return STR_OR_UNICODE(text) def init_osx_pbcopy_clipboard(): def copy_osx_pbcopy(text): text = _stringifyText(text) # Converts non-str values to str. p = subprocess.Popen(['pbcopy', 'w'], stdin=subprocess.PIPE, close_fds=True) p.communicate(input=text.encode(ENCODING)) def paste_osx_pbcopy(): p = subprocess.Popen(['pbpaste', 'r'], stdout=subprocess.PIPE, close_fds=True) stdout, stderr = p.communicate() return stdout.decode(ENCODING) return copy_osx_pbcopy, paste_osx_pbcopy def init_osx_pyobjc_clipboard(): def copy_osx_pyobjc(text): '''Copy string argument to clipboard''' text = _stringifyText(text) # Converts non-str values to str. newStr = Foundation.NSString.stringWithString_(text).nsstring() newData = newStr.dataUsingEncoding_(Foundation.NSUTF8StringEncoding) board = AppKit.NSPasteboard.generalPasteboard() board.declareTypes_owner_([AppKit.NSStringPboardType], None) board.setData_forType_(newData, AppKit.NSStringPboardType) def paste_osx_pyobjc(): "Returns contents of clipboard" board = AppKit.NSPasteboard.generalPasteboard() content = board.stringForType_(AppKit.NSStringPboardType) return content return copy_osx_pyobjc, paste_osx_pyobjc def init_gtk_clipboard(): global gtk import gtk def copy_gtk(text): global cb text = _stringifyText(text) # Converts non-str values to str. cb = gtk.Clipboard() cb.set_text(text) cb.store() def paste_gtk(): clipboardContents = gtk.Clipboard().wait_for_text() # for python 2, returns None if the clipboard is blank. if clipboardContents is None: return '' else: return clipboardContents return copy_gtk, paste_gtk def init_qt_clipboard(): global QApplication # $DISPLAY should exist # Try to import from qtpy, but if that fails try PyQt5 then PyQt4 try: from qtpy.QtWidgets import QApplication except: try: from PyQt5.QtWidgets import QApplication except: from PyQt4.QtGui import QApplication app = QApplication.instance() if app is None: app = QApplication([]) def copy_qt(text): text = _stringifyText(text) # Converts non-str values to str. cb = app.clipboard() cb.setText(text) def paste_qt(): cb = app.clipboard() return STR_OR_UNICODE(cb.text()) return copy_qt, paste_qt def init_xclip_clipboard(): DEFAULT_SELECTION='c' PRIMARY_SELECTION='p' def copy_xclip(text, primary=False): text = _stringifyText(text) # Converts non-str values to str. selection=DEFAULT_SELECTION if primary: selection=PRIMARY_SELECTION p = subprocess.Popen(['xclip', '-selection', selection], stdin=subprocess.PIPE, close_fds=True) p.communicate(input=text.encode(ENCODING)) def paste_xclip(primary=False): selection=DEFAULT_SELECTION if primary: selection=PRIMARY_SELECTION p = subprocess.Popen(['xclip', '-selection', selection, '-o'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) stdout, stderr = p.communicate() # Intentionally ignore extraneous output on stderr when clipboard is empty return stdout.decode(ENCODING) return copy_xclip, paste_xclip def init_xsel_clipboard(): DEFAULT_SELECTION='-b' PRIMARY_SELECTION='-p' def copy_xsel(text, primary=False): text = _stringifyText(text) # Converts non-str values to str. selection_flag = DEFAULT_SELECTION if primary: selection_flag = PRIMARY_SELECTION p = subprocess.Popen(['xsel', selection_flag, '-i'], stdin=subprocess.PIPE, close_fds=True) p.communicate(input=text.encode(ENCODING)) def paste_xsel(primary=False): selection_flag = DEFAULT_SELECTION if primary: selection_flag = PRIMARY_SELECTION p = subprocess.Popen(['xsel', selection_flag, '-o'], stdout=subprocess.PIPE, close_fds=True) stdout, stderr = p.communicate() return stdout.decode(ENCODING) return copy_xsel, paste_xsel def init_wl_clipboard(): PRIMARY_SELECTION = "-p" def copy_wl(text, primary=False): text = _stringifyText(text) # Converts non-str values to str. args = ["wl-copy"] if primary: args.append(PRIMARY_SELECTION) if not text: args.append('--clear') subprocess.check_call(args, close_fds=True) else: pass p = subprocess.Popen(args, stdin=subprocess.PIPE, close_fds=True) p.communicate(input=text.encode(ENCODING)) def paste_wl(primary=False): args = ["wl-paste", "-n"] if primary: args.append(PRIMARY_SELECTION) p = subprocess.Popen(args, stdout=subprocess.PIPE, close_fds=True) stdout, _stderr = p.communicate() return stdout.decode(ENCODING) return copy_wl, paste_wl def init_klipper_clipboard(): def copy_klipper(text): text = _stringifyText(text) # Converts non-str values to str. p = subprocess.Popen( ['qdbus', 'org.kde.klipper', '/klipper', 'setClipboardContents', text.encode(ENCODING)], stdin=subprocess.PIPE, close_fds=True) p.communicate(input=None) def paste_klipper(): p = subprocess.Popen( ['qdbus', 'org.kde.klipper', '/klipper', 'getClipboardContents'], stdout=subprocess.PIPE, close_fds=True) stdout, stderr = p.communicate() # Workaround for https://bugs.kde.org/show_bug.cgi?id=342874 # TODO: https://github.com/asweigart/pyperclip/issues/43 clipboardContents = stdout.decode(ENCODING) # even if blank, Klipper will append a newline at the end assert len(clipboardContents) > 0 # make sure that newline is there assert clipboardContents.endswith('\n') if clipboardContents.endswith('\n'): clipboardContents = clipboardContents[:-1] return clipboardContents return copy_klipper, paste_klipper def init_dev_clipboard_clipboard(): def copy_dev_clipboard(text): text = _stringifyText(text) # Converts non-str values to str. if text == '': warnings.warn('Pyperclip cannot copy a blank string to the clipboard on Cygwin. This is effectively a no-op.') if '\r' in text: warnings.warn('Pyperclip cannot handle \\r characters on Cygwin.') fo = open('/dev/clipboard', 'wt') fo.write(text) fo.close() def paste_dev_clipboard(): fo = open('/dev/clipboard', 'rt') content = fo.read() fo.close() return content return copy_dev_clipboard, paste_dev_clipboard def init_no_clipboard(): class ClipboardUnavailable(object): def __call__(self, *args, **kwargs): raise PyperclipException(EXCEPT_MSG) if PY2: def __nonzero__(self): return False else: def __bool__(self): return False return ClipboardUnavailable(), ClipboardUnavailable() # Windows-related clipboard functions: class CheckedCall(object): def __init__(self, f): super(CheckedCall, self).__setattr__("f", f) def __call__(self, *args): ret = self.f(*args) if not ret and get_errno(): raise PyperclipWindowsException("Error calling " + self.f.__name__) return ret def __setattr__(self, key, value): setattr(self.f, key, value) def init_windows_clipboard(): global HGLOBAL, LPVOID, DWORD, LPCSTR, INT, HWND, HINSTANCE, HMENU, BOOL, UINT, HANDLE from ctypes.wintypes import (HGLOBAL, LPVOID, DWORD, LPCSTR, INT, HWND, HINSTANCE, HMENU, BOOL, UINT, HANDLE) windll = ctypes.windll msvcrt = ctypes.CDLL('msvcrt') safeCreateWindowExA = CheckedCall(windll.user32.CreateWindowExA) safeCreateWindowExA.argtypes = [DWORD, LPCSTR, LPCSTR, DWORD, INT, INT, INT, INT, HWND, HMENU, HINSTANCE, LPVOID] safeCreateWindowExA.restype = HWND safeDestroyWindow = CheckedCall(windll.user32.DestroyWindow) safeDestroyWindow.argtypes = [HWND] safeDestroyWindow.restype = BOOL OpenClipboard = windll.user32.OpenClipboard OpenClipboard.argtypes = [HWND] OpenClipboard.restype = BOOL safeCloseClipboard = CheckedCall(windll.user32.CloseClipboard) safeCloseClipboard.argtypes = [] safeCloseClipboard.restype = BOOL safeEmptyClipboard = CheckedCall(windll.user32.EmptyClipboard) safeEmptyClipboard.argtypes = [] safeEmptyClipboard.restype = BOOL safeGetClipboardData = CheckedCall(windll.user32.GetClipboardData) safeGetClipboardData.argtypes = [UINT] safeGetClipboardData.restype = HANDLE safeSetClipboardData = CheckedCall(windll.user32.SetClipboardData) safeSetClipboardData.argtypes = [UINT, HANDLE] safeSetClipboardData.restype = HANDLE safeGlobalAlloc = CheckedCall(windll.kernel32.GlobalAlloc) safeGlobalAlloc.argtypes = [UINT, c_size_t] safeGlobalAlloc.restype = HGLOBAL safeGlobalLock = CheckedCall(windll.kernel32.GlobalLock) safeGlobalLock.argtypes = [HGLOBAL] safeGlobalLock.restype = LPVOID safeGlobalUnlock = CheckedCall(windll.kernel32.GlobalUnlock) safeGlobalUnlock.argtypes = [HGLOBAL] safeGlobalUnlock.restype = BOOL wcslen = CheckedCall(msvcrt.wcslen) wcslen.argtypes = [c_wchar_p] wcslen.restype = UINT GMEM_MOVEABLE = 0x0002 CF_UNICODETEXT = 13 @contextlib.contextmanager def window(): """ Context that provides a valid Windows hwnd. """ # we really just need the hwnd, so setting "STATIC" # as predefined lpClass is just fine. hwnd = safeCreateWindowExA(0, b"STATIC", None, 0, 0, 0, 0, 0, None, None, None, None) try: yield hwnd finally: safeDestroyWindow(hwnd) @contextlib.contextmanager def clipboard(hwnd): """ Context manager that opens the clipboard and prevents other applications from modifying the clipboard content. """ # We may not get the clipboard handle immediately because # some other application is accessing it (?) # We try for at least 500ms to get the clipboard. t = time.time() + 0.5 success = False while time.time() < t: success = OpenClipboard(hwnd) if success: break time.sleep(0.01) if not success: raise PyperclipWindowsException("Error calling OpenClipboard") try: yield finally: safeCloseClipboard() def copy_windows(text): # This function is heavily based on # http://msdn.com/ms649016#_win32_Copying_Information_to_the_Clipboard text = _stringifyText(text) # Converts non-str values to str. with window() as hwnd: # http://msdn.com/ms649048 # If an application calls OpenClipboard with hwnd set to NULL, # EmptyClipboard sets the clipboard owner to NULL; # this causes SetClipboardData to fail. # => We need a valid hwnd to copy something. with clipboard(hwnd): safeEmptyClipboard() if text: # http://msdn.com/ms649051 # If the hMem parameter identifies a memory object, # the object must have been allocated using the # function with the GMEM_MOVEABLE flag. count = wcslen(text) + 1 handle = safeGlobalAlloc(GMEM_MOVEABLE, count * sizeof(c_wchar)) locked_handle = safeGlobalLock(handle) ctypes.memmove(c_wchar_p(locked_handle), c_wchar_p(text), count * sizeof(c_wchar)) safeGlobalUnlock(handle) safeSetClipboardData(CF_UNICODETEXT, handle) def paste_windows(): with clipboard(None): handle = safeGetClipboardData(CF_UNICODETEXT) if not handle: # GetClipboardData may return NULL with errno == NO_ERROR # if the clipboard is empty. # (Also, it may return a handle to an empty buffer, # but technically that's not empty) return "" return c_wchar_p(handle).value return copy_windows, paste_windows def init_wsl_clipboard(): def copy_wsl(text): text = _stringifyText(text) # Converts non-str values to str. p = subprocess.Popen(['clip.exe'], stdin=subprocess.PIPE, close_fds=True) p.communicate(input=text.encode(ENCODING)) def paste_wsl(): p = subprocess.Popen(['powershell.exe', '-command', 'Get-Clipboard'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) stdout, stderr = p.communicate() # WSL appends "\r\n" to the contents. return stdout[:-2].decode(ENCODING) return copy_wsl, paste_wsl # Automatic detection of clipboard mechanisms and importing is done in deteremine_clipboard(): def determine_clipboard(): ''' Determine the OS/platform and set the copy() and paste() functions accordingly. ''' global Foundation, AppKit, gtk, qtpy, PyQt4, PyQt5 # Setup for the CYGWIN platform: if 'cygwin' in platform.system().lower(): # Cygwin has a variety of values returned by platform.system(), such as 'CYGWIN_NT-6.1' # FIXME: pyperclip currently does not support Cygwin, # see https://github.com/asweigart/pyperclip/issues/55 if os.path.exists('/dev/clipboard'): warnings.warn('Pyperclip\'s support for Cygwin is not perfect, see https://github.com/asweigart/pyperclip/issues/55') return init_dev_clipboard_clipboard() # Setup for the WINDOWS platform: elif os.name == 'nt' or platform.system() == 'Windows': return init_windows_clipboard() if platform.system() == 'Linux' and os.path.isfile('/proc/version'): with open('/proc/version', 'r') as f: if "microsoft" in f.read().lower(): return init_wsl_clipboard() # Setup for the MAC OS X platform: if os.name == 'mac' or platform.system() == 'Darwin': try: import Foundation # check if pyobjc is installed import AppKit except ImportError: return init_osx_pbcopy_clipboard() else: return init_osx_pyobjc_clipboard() # Setup for the LINUX platform: if HAS_DISPLAY: try: import gtk # check if gtk is installed except ImportError: pass # We want to fail fast for all non-ImportError exceptions. else: return init_gtk_clipboard() if ( os.environ.get("WAYLAND_DISPLAY") and _executable_exists("wl-copy") ): return init_wl_clipboard() if _executable_exists("xsel"): return init_xsel_clipboard() if _executable_exists("xclip"): return init_xclip_clipboard() if _executable_exists("klipper") and _executable_exists("qdbus"): return init_klipper_clipboard() try: # qtpy is a small abstraction layer that lets you write applications using a single api call to either PyQt or PySide. # https://pypi.python.org/pypi/QtPy import qtpy # check if qtpy is installed except ImportError: # If qtpy isn't installed, fall back on importing PyQt4. try: import PyQt5 # check if PyQt5 is installed except ImportError: try: import PyQt4 # check if PyQt4 is installed except ImportError: pass # We want to fail fast for all non-ImportError exceptions. else: return init_qt_clipboard() else: return init_qt_clipboard() else: return init_qt_clipboard() return init_no_clipboard() def set_clipboard(clipboard): ''' Explicitly sets the clipboard mechanism. The "clipboard mechanism" is how the copy() and paste() functions interact with the operating system to implement the copy/paste feature. The clipboard parameter must be one of: - pbcopy - pbobjc (default on Mac OS X) - gtk - qt - xclip - xsel - klipper - windows (default on Windows) - no (this is what is set when no clipboard mechanism can be found) ''' global copy, paste clipboard_types = { "pbcopy": init_osx_pbcopy_clipboard, "pyobjc": init_osx_pyobjc_clipboard, "gtk": init_gtk_clipboard, "qt": init_qt_clipboard, # TODO - split this into 'qtpy', 'pyqt4', and 'pyqt5' "xclip": init_xclip_clipboard, "xsel": init_xsel_clipboard, "wl-clipboard": init_wl_clipboard, "klipper": init_klipper_clipboard, "windows": init_windows_clipboard, "no": init_no_clipboard, } if clipboard not in clipboard_types: raise ValueError('Argument must be one of %s' % (', '.join([repr(_) for _ in clipboard_types.keys()]))) # Sets pyperclip's copy() and paste() functions: copy, paste = clipboard_types[clipboard]() def lazy_load_stub_copy(text): ''' A stub function for copy(), which will load the real copy() function when called so that the real copy() function is used for later calls. This allows users to import pyperclip without having determine_clipboard() automatically run, which will automatically select a clipboard mechanism. This could be a problem if it selects, say, the memory-heavy PyQt4 module but the user was just going to immediately call set_clipboard() to use a different clipboard mechanism. The lazy loading this stub function implements gives the user a chance to call set_clipboard() to pick another clipboard mechanism. Or, if the user simply calls copy() or paste() without calling set_clipboard() first, will fall back on whatever clipboard mechanism that determine_clipboard() automatically chooses. ''' global copy, paste copy, paste = determine_clipboard() return copy(text) def lazy_load_stub_paste(): ''' A stub function for paste(), which will load the real paste() function when called so that the real paste() function is used for later calls. This allows users to import pyperclip without having determine_clipboard() automatically run, which will automatically select a clipboard mechanism. This could be a problem if it selects, say, the memory-heavy PyQt4 module but the user was just going to immediately call set_clipboard() to use a different clipboard mechanism. The lazy loading this stub function implements gives the user a chance to call set_clipboard() to pick another clipboard mechanism. Or, if the user simply calls copy() or paste() without calling set_clipboard() first, will fall back on whatever clipboard mechanism that determine_clipboard() automatically chooses. ''' global copy, paste copy, paste = determine_clipboard() return paste() def is_available(): return copy != lazy_load_stub_copy and paste != lazy_load_stub_paste # Initially, copy() and paste() are set to lazy loading wrappers which will # set `copy` and `paste` to real functions the first time they're used, unless # set_clipboard() or determine_clipboard() is called first. copy, paste = lazy_load_stub_copy, lazy_load_stub_paste def waitForPaste(timeout=None): """This function call blocks until a non-empty text string exists on the clipboard. It returns this text. This function raises PyperclipTimeoutException if timeout was set to a number of seconds that has elapsed without non-empty text being put on the clipboard.""" startTime = time.time() while True: clipboardText = paste() if clipboardText != '': return clipboardText time.sleep(0.01) if timeout is not None and time.time() > startTime + timeout: raise PyperclipTimeoutException('waitForPaste() timed out after ' + str(timeout) + ' seconds.') def waitForNewPaste(timeout=None): """This function call blocks until a new text string exists on the clipboard that is different from the text that was there when the function was first called. It returns this text. This function raises PyperclipTimeoutException if timeout was set to a number of seconds that has elapsed without non-empty text being put on the clipboard.""" startTime = time.time() originalText = paste() while True: currentText = paste() if currentText != originalText: return currentText time.sleep(0.01) if timeout is not None and time.time() > startTime + timeout: raise PyperclipTimeoutException('waitForNewPaste() timed out after ' + str(timeout) + ' seconds.') __all__ = ['copy', 'paste', 'waitForPaste', 'waitForNewPaste', 'set_clipboard', 'determine_clipboard'] ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1601854378.0 pyperclip-1.8.2/src/pyperclip/__main__.py0000666000000000000000000000137500000000000015322 0ustar00import pyperclip import sys if len(sys.argv) > 1 and sys.argv[1] in ('-c', '--copy'): if len(sys.argv) > 2: pyperclip.copy(sys.argv[2]) else: pyperclip.copy(sys.stdin.read()) elif len(sys.argv) > 1 and sys.argv[1] in ('-p', '--paste'): sys.stdout.write(pyperclip.paste()) else: print('Usage: python -m pyperclip [-c | --copy] [text_to_copy] | [-p | --paste]') print() print('If a text_to_copy argument is provided, it is copied to the') print('clipboard. Otherwise, the stdin stream is copied to the') print('clipboard. (If reading this in from the keyboard, press') print('CTRL-Z on Windows or CTRL-D on Linux/macOS to stop.') print('When pasting, the clipboard will be written to stdout.')././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1613869489.5029213 pyperclip-1.8.2/src/pyperclip.egg-info/0000777000000000000000000000000000000000000014714 5ustar00././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1613869488.0 pyperclip-1.8.2/src/pyperclip.egg-info/PKG-INFO0000666000000000000000000000476100000000000016021 0ustar00Metadata-Version: 1.1 Name: pyperclip Version: 1.8.2 Summary: A cross-platform clipboard module for Python. (Only handles plain text for now.) Home-page: https://github.com/asweigart/pyperclip Author: Al Sweigart Author-email: al@inventwithpython.com License: BSD Description: Pyperclip is a cross-platform Python module for copy and paste clipboard functions. It works with Python 2 and 3. Install on Windows: `pip install pyperclip` Install on Linux/macOS: `pip3 install pyperclip` Al Sweigart al@inventwithpython.com BSD License Example Usage ============= >>> import pyperclip >>> pyperclip.copy('The text to be copied to the clipboard.') >>> pyperclip.paste() 'The text to be copied to the clipboard.' Currently only handles plaintext. On Windows, no additional modules are needed. On Mac, this module makes use of the pbcopy and pbpaste commands, which should come with the os. On Linux, this module makes use of the xclip or xsel commands, which should come with the os. Otherwise run "sudo apt-get install xclip" or "sudo apt-get install xsel" (Note: xsel does not always seem to work.) Otherwise on Linux, you will need the gtk or PyQt4 modules installed. Keywords: clipboard copy paste clip xsel xclip Platform: UNKNOWN Classifier: Development Status :: 5 - Production/Stable Classifier: Environment :: Win32 (MS Windows) Classifier: Environment :: X11 Applications Classifier: Environment :: MacOS X Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.1 Classifier: Programming Language :: Python :: 3.2 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 Classifier: Programming Language :: Python :: 3.6 Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: 3.9 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1613869488.0 pyperclip-1.8.2/src/pyperclip.egg-info/SOURCES.txt0000666000000000000000000000053200000000000016600 0ustar00AUTHORS.txt CHANGES.txt LICENSE.txt MANIFEST.in README.md setup.py docs/Makefile docs/conf.py docs/index.rst docs/make.bat src/pyperclip/__init__.py src/pyperclip/__main__.py src/pyperclip.egg-info/PKG-INFO src/pyperclip.egg-info/SOURCES.txt src/pyperclip.egg-info/dependency_links.txt src/pyperclip.egg-info/top_level.txt tests/test_pyperclip.py././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1613869488.0 pyperclip-1.8.2/src/pyperclip.egg-info/dependency_links.txt0000666000000000000000000000000100000000000020762 0ustar00 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1613869488.0 pyperclip-1.8.2/src/pyperclip.egg-info/top_level.txt0000666000000000000000000000001200000000000017437 0ustar00pyperclip ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1613869489.5190964 pyperclip-1.8.2/tests/0000777000000000000000000000000000000000000011566 5ustar00././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1601856435.0 pyperclip-1.8.2/tests/test_pyperclip.py0000666000000000000000000001265100000000000015213 0ustar00# coding: utf-8 import string import unittest import random import os import platform #import sys #sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) from pyperclip import _executable_exists, HAS_DISPLAY from pyperclip import (init_osx_pbcopy_clipboard, init_osx_pyobjc_clipboard, init_dev_clipboard_clipboard, init_gtk_clipboard, init_qt_clipboard, init_xclip_clipboard, init_xsel_clipboard, init_wl_clipboard, init_klipper_clipboard, init_no_clipboard) from pyperclip import init_windows_clipboard from pyperclip import init_wsl_clipboard from pyperclip import PyperclipException random.seed(42) # Make the "random" tests reproducible. class _TestClipboard(unittest.TestCase): clipboard = None supports_unicode = True @property def copy(self): return self.clipboard[0] @property def paste(self): return self.clipboard[1] def setUp(self): if not self.clipboard: self.skipTest("Clipboard not supported.") def test_copy_simple(self): self.copy("pyper\r\nclip") def test_copy_paste_simple(self): msg = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(1000)) self.copy(msg) self.assertEqual(self.paste(), msg) def test_copy_paste_whitespace(self): msg = ''.join(random.choice(string.whitespace) for _ in range(1000)) self.copy(msg) self.assertEqual(self.paste(), msg) def test_copy_blank(self): self.copy('TEST') self.copy('') self.assertEqual(self.paste(), '') def test_copy_unicode(self): if not self.supports_unicode: raise unittest.SkipTest() self.copy(u"ಠ_ಠ") def test_copy_unicode_emoji(self): if not self.supports_unicode: raise unittest.SkipTest() self.copy(u"🙆") def test_copy_paste_unicode(self): if not self.supports_unicode: raise unittest.SkipTest() msg = u"ಠ_ಠ" self.copy(msg) self.assertEqual(self.paste(), msg) def test_copy_paste_unicode_emoji(self): if not self.supports_unicode: raise unittest.SkipTest() msg = u"🙆" self.copy(msg) self.assertEqual(self.paste(), msg) def test_non_str(self): # Test copying an int. self.copy(42) self.assertEqual(self.paste(), '42') self.copy(-1) self.assertEqual(self.paste(), '-1') # Test copying a float. self.copy(3.141592) self.assertEqual(self.paste(), '3.141592') # Test copying bools. self.copy(True) self.assertEqual(self.paste(), 'True') self.copy(False) self.assertEqual(self.paste(), 'False') # All other non-str values raise an exception. with self.assertRaises(PyperclipException): self.copy(None) with self.assertRaises(PyperclipException): self.copy([2, 4, 6, 8]) class TestCygwin(_TestClipboard): if 'cygwin' in platform.system().lower(): clipboard = init_dev_clipboard_clipboard() class TestWindows(_TestClipboard): if os.name == 'nt' or platform.system() == 'Windows': clipboard = init_windows_clipboard() class TestWSL(_TestClipboard): if platform.system() == 'Linux': with open('/proc/version', 'r') as f: if "Microsoft" in f.read(): clipboard = init_wsl_clipboard() class TestOSX(_TestClipboard): if os.name == 'mac' or platform.system() == 'Darwin': try: import Foundation # check if pyobjc is installed import AppKit except ImportError: clipboard = init_osx_pbcopy_clipboard() # TODO else: clipboard = init_osx_pyobjc_clipboard() class TestGtk(_TestClipboard): if HAS_DISPLAY: try: import gtk except ImportError: pass else: clipboard = init_gtk_clipboard() class TestQt(_TestClipboard): if HAS_DISPLAY: try: import PyQt5.QtWidgets except ImportError: try: import PyQt4.QtGui except ImportError: pass else: clipboard = init_qt_clipboard() else: clipboard = init_qt_clipboard() class TestXClip(_TestClipboard): if _executable_exists("xclip"): clipboard = init_xclip_clipboard() class TestXSel(_TestClipboard): if _executable_exists("xsel"): clipboard = init_xsel_clipboard() class TestWlClipboard(_TestClipboard): if _executable_exists("wl-copy"): clipboard = init_wl_clipboard() class TestKlipper(_TestClipboard): if _executable_exists("klipper") and _executable_exists("qdbus"): clipboard = init_klipper_clipboard() class TestNoClipboard(unittest.TestCase): copy, paste = init_no_clipboard() def test_copy(self): with self.assertRaises(RuntimeError): self.copy("foo") def test_paste(self): with self.assertRaises(RuntimeError): self.paste() if __name__ == '__main__': unittest.main()