<s> '''<STR_LIT>''' <EOL> from ctypes import * <EOL> from pyglet import window <EOL> from pyglet . window . xlib import xlib <EOL> XA_PRIMARY = xlib . Atom ( <NUM_LIT:1> ) <EOL> XA_STRING = xlib . Atom ( <NUM_LIT> ) <EOL> CurrentTime = <NUM_LIT:0> <EOL> AnyPropertyType = <NUM_LIT:0> <EOL> class XlibClipboard ( object ) : <EOL> def get_text ( self ) : <EOL> display = window . get_platform ( ) . get_default_display ( ) . _display <EOL> owner = xlib . XGetSelectionOwner ( display , XA_PRIMARY ) <EOL> if not owner : return '<STR_LIT>' <EOL> xlib . XConvertSelection ( display , XA_PRIMARY , XA_STRING , <NUM_LIT:0> , owner , <EOL> CurrentTime ) <EOL> xlib . XFlush ( display ) <EOL> type = xlib . Atom ( ) <EOL> format = c_int ( ) <EOL> len = c_ulong ( ) <EOL> bytes_left = c_ulong ( ) <EOL> data = POINTER ( c_ubyte ) ( ) <EOL> xlib . XGetWindowProperty ( display , owner , XA_STRING , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <EOL> AnyPropertyType , byref ( type ) , byref ( format ) , byref ( len ) , <EOL> byref ( bytes_left ) , byref ( data ) ) <EOL> length = int ( bytes_left . value ) <EOL> if not length : <EOL> return '<STR_LIT>' <EOL> dummy = c_ulong ( ) <EOL> xlib . XGetWindowProperty ( display , owner , XA_STRING , <NUM_LIT:0> , <EOL> length , <NUM_LIT:0> , AnyPropertyType , byref ( type ) , byref ( format ) , <EOL> byref ( len ) , byref ( dummy ) , byref ( data ) ) <EOL> s = '<STR_LIT>' . join ( chr ( c ) for c in data [ : len . value ] ) <EOL> xlib . XFree ( data ) <EOL> return s <EOL> def set_text ( self , text ) : <EOL> pass <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> cb = XlibClipboard ( ) <EOL> print '<STR_LIT>' , ` cb . get_text ( ) ` <EOL> s = "<STR_LIT>" <EOL> cb . set_text ( s ) <EOL> assert s == cb . get_text ( ) </s>
