<s> import subprocess <EOL> import os <EOL> import platform <EOL> from locale import getpreferredencoding <EOL> class CopyFailed ( Exception ) : <EOL> pass <EOL> class XClipboard ( object ) : <EOL> """<STR_LIT>""" <EOL> def copy ( self , content ) : <EOL> process = subprocess . Popen ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> stdin = subprocess . PIPE ) <EOL> process . communicate ( content . encode ( getpreferredencoding ( ) ) ) <EOL> if process . returncode != <NUM_LIT:0> : <EOL> raise CopyFailed ( ) <EOL> class OSXClipboard ( object ) : <EOL> """<STR_LIT>""" <EOL> def copy ( self , content ) : <EOL> process = subprocess . Popen ( [ '<STR_LIT>' , '<STR_LIT:w>' ] , stdin = subprocess . PIPE ) <EOL> process . communicate ( content . encode ( getpreferredencoding ( ) ) ) <EOL> if process . returncode != <NUM_LIT:0> : <EOL> raise CopyFailed ( ) <EOL> def command_exists ( command ) : <EOL> process = subprocess . Popen ( [ '<STR_LIT>' , command ] , stderr = subprocess . STDOUT , <EOL> stdout = subprocess . PIPE ) <EOL> process . communicate ( ) <EOL> return process . returncode == <NUM_LIT:0> <EOL> def get_clipboard ( ) : <EOL> """<STR_LIT>""" <EOL> if platform . system ( ) == '<STR_LIT>' : <EOL> if command_exists ( '<STR_LIT>' ) : <EOL> return OSXClipboard ( ) <EOL> if ( platform . system ( ) in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) and <EOL> os . getenv ( '<STR_LIT>' ) is not None ) : <EOL> if command_exists ( '<STR_LIT>' ) : <EOL> return XClipboard ( ) <EOL> return None </s>
