MCPcopy
hub / github.com/asweigart/pyperclip / init_xclip_clipboard

Function init_xclip_clipboard

src/pyperclip/__init__.py:158–183  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

156
157
158def init_xclip_clipboard():
159 DEFAULT_SELECTION='c'
160 PRIMARY_SELECTION='p'
161
162 def copy_xclip(text, primary=False):
163 text = _PYTHON_STR_TYPE(text) # Converts non-str values to str.
164 selection=DEFAULT_SELECTION
165 if primary:
166 selection=PRIMARY_SELECTION
167 p = subprocess.Popen(['xclip', '-selection', selection],
168 stdin=subprocess.PIPE, close_fds=True)
169 p.communicate(input=text.encode(ENCODING))
170
171 def paste_xclip(primary=False):
172 selection=DEFAULT_SELECTION
173 if primary:
174 selection=PRIMARY_SELECTION
175 p = subprocess.Popen(['xclip', '-selection', selection, '-o'],
176 stdout=subprocess.PIPE,
177 stderr=subprocess.PIPE,
178 close_fds=True)
179 stdout, stderr = p.communicate()
180 # Intentionally ignore extraneous output on stderr when clipboard is empty
181 return stdout.decode(ENCODING)
182
183 return copy_xclip, paste_xclip
184
185
186def init_xsel_clipboard():

Callers 2

TestXClipClass · 0.90
determine_clipboardFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…