51
51
import os
52
52
from subprocess import call , Popen , PIPE
53
53
54
- PY2 = '2' == platform .python_version_tuple ()[0 ]
55
- text_type = unicode if PY2 else str
54
+ from pandas .compat import bytes_to_str , str_to_bytes , text_type
56
55
57
56
58
57
class NoClipboardProgramError (OSError ):
@@ -117,13 +116,13 @@ def _copyCygwin(text):
117
116
118
117
def _copyOSX (text ):
119
118
p = Popen (['pbcopy' , 'w' ], stdin = PIPE , close_fds = True )
120
- p .communicate (input = text . encode ( 'utf-8' ))
119
+ p .communicate (input = str_to_bytes ( text , 'utf-8' ))
121
120
122
121
123
122
def _pasteOSX ():
124
123
p = Popen (['pbpaste' , 'r' ], stdout = PIPE , close_fds = True )
125
124
stdout , stderr = p .communicate ()
126
- return stdout . decode ( 'utf-8' )
125
+ return bytes_to_str ( stdout , 'utf-8' )
127
126
128
127
129
128
def _pasteGtk ():
@@ -147,29 +146,29 @@ def _copyQt(text):
147
146
148
147
def _copyXclip (text ):
149
148
p = Popen (['xclip' , '-selection' , 'c' ], stdin = PIPE , close_fds = True )
150
- p .communicate (input = text . encode ( 'utf-8' ))
149
+ p .communicate (input = str_to_bytes ( text , 'utf-8' ))
151
150
152
151
153
152
def _pasteXclip ():
154
153
p = Popen (['xclip' , '-selection' , 'c' , '-o' ], stdout = PIPE , close_fds = True )
155
154
stdout , stderr = p .communicate ()
156
- return stdout . decode ( 'utf-8' )
155
+ return bytes_to_str ( stdout , 'utf-8' )
157
156
158
157
159
158
def _copyXsel (text ):
160
159
p = Popen (['xsel' , '-b' , '-i' ], stdin = PIPE , close_fds = True )
161
- p .communicate (input = text . encode ( 'utf-8' ))
160
+ p .communicate (input = str_to_bytes ( text , 'utf-8' ))
162
161
163
162
164
163
def _pasteXsel ():
165
164
p = Popen (['xsel' , '-b' , '-o' ], stdout = PIPE , close_fds = True )
166
165
stdout , stderr = p .communicate ()
167
- return stdout . decode ( 'utf-8' )
166
+ return bytes_to_str ( stdout , 'utf-8' )
168
167
169
168
170
169
def _copyKlipper (text ):
171
170
p = Popen (['qdbus' , 'org.kde.klipper' , '/klipper' ,
172
- 'setClipboardContents' , text . encode ( 'utf-8' )],
171
+ 'setClipboardContents' , str_to_bytes ( text , 'utf-8' )],
173
172
stdin = PIPE , close_fds = True )
174
173
p .communicate (input = None )
175
174
@@ -178,7 +177,7 @@ def _pasteKlipper():
178
177
p = Popen (['qdbus' , 'org.kde.klipper' , '/klipper' ,
179
178
'getClipboardContents' ], stdout = PIPE , close_fds = True )
180
179
stdout , stderr = p .communicate ()
181
- return stdout . decode ( 'utf-8' )
180
+ return bytes_to_str ( stdout , 'utf-8' )
182
181
183
182
184
183
# Determine the OS/platform and set the copy() and paste() functions
0 commit comments