Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 27 lines (20 sloc) 0.664 kb
b750823 Kenneth Reitz Linux support.
kennethreitz authored
1 # -*- coding: utf-8 -*-
2
3 """ Copy + Paste in Linux
4 """
5
6 import subprocess
ebc3a3e startling Change imports to explicit relative imports.
startling authored
7 from .base import *
b750823 Kenneth Reitz Linux support.
kennethreitz authored
8
9
10 def copy(string):
11 """Copy given string into system clipboard."""
12 try:
13 _cmd = ["xclip", "-selection", "clipboard"]
8bf6fdc startling Use `bytes/str.decode` and `str.encode` rather than str(unicode()).
startling authored
14 subprocess.Popen(_cmd, stdin=subprocess.PIPE).communicate(
15 string.encode('utf-8'))
b750823 Kenneth Reitz Linux support.
kennethreitz authored
16 return
6dfbdf6 startling Catch OSError rather than general Exception!
startling authored
17 except OSError as why:
b750823 Kenneth Reitz Linux support.
kennethreitz authored
18 raise XclipNotFound
19
20 def paste():
21 """Returns system clipboard contents."""
22 try:
a143bc8 startling Fixed a silly syntax error in `linux.py`.
startling authored
23 return subprocess.Popen(["xclip", "-selection", "clipboard", "-o"], stdout=subprocess.PIPE).communicate()[0].decode("utf-8")
6dfbdf6 startling Catch OSError rather than general Exception!
startling authored
24 except OSError as why:
b750823 Kenneth Reitz Linux support.
kennethreitz authored
25 raise XclipNotFound
26
Something went wrong with that request. Please try again.