This file is indexed.

/usr/lib/python2.7/dist-packages/xdo/__init__.py is in python-xdo 0.4-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# -*- coding: utf-8 -*-

import ctypes
import os

from six.moves import range

from ._xdo import libxdo as _libxdo
from ._xdo import libc as _libc
from ._xdo import charcodemap_ptr as _charcodemap_ptr
from ._xdo import window_t as _window_t
from ._xdo import CURRENTWINDOW
from datetime import timedelta
import warnings
import codecs
 
def deprecated(func):
    '''This is a decorator which can be used to mark functions
    as deprecated. It will result in a warning being emitted
    when the function is used.'''
    def new_func(*args, **kwargs):
        warnings.warn("Call to deprecated function {}.".format(func.__name__),
                      category=DeprecationWarning)
        return func(*args, **kwargs)
    new_func.__name__ = func.__name__
    new_func.__doc__ = func.__doc__
    new_func.__dict__.update(func.__dict__)
    return new_func

def version():
    return _libxdo.xdo_version()

class xdo(object):
    def __init__(self, display=None):
        if display is None:
            display = os.environ.get('DISPLAY', '')
        display = display.encode('utf-8')
        self._xdo = _libxdo.xdo_new(display)
        if self._xdo is None:
            raise SystemError("Could not initialize libxdo")


    def enter_text_window(self, string, clearmodifiers=True,
                          delay=timedelta(microseconds=12000),
                          window=CURRENTWINDOW):
        """
        Type a string to the specified window.

        If you want to send a specific key or key sequence, such as
        "alt+l", you want instead the ``send_keysequence_window(...)``
        function.

        :param string:
            The string to type, like "Hello world!"
        :param delay:
            The delay between keystrokes as a datetime.timedelta. default: 12 milliseconds.
            If passed as an int, it will be treated as microseconds
        :param window:
            The window you want to send keystrokes to or (by default) xdo.CURRENTWINDOW
        :param clearmodifiers:
            Whether to clear any current modifier keys before sending
            the text (defaults to True).
        """
        if type(delay) == timedelta:
            delay_int = int(delay.total_seconds() * 1000000)
        elif type(delay) == int:
            delay_int = delay
        else:
            raise TypeError("delay parameter should be either a timedelta or an int")

        if type(string) != type(b''):
            # FIXME: is it right to assume that we're going to encode
            # in UTF-8?  if the sender wants to emit a bytestring,
            # they can just send it as a bytestring in the first
            # place.
            string = codecs.encode(string, 'utf-8')

        if clearmodifiers:
            active_mods_n = ctypes.c_int(0)
            active_mods = _charcodemap_ptr()
            _libxdo.xdo_get_active_modifiers(self._xdo, ctypes.byref(active_mods),
                                             ctypes.byref(active_mods_n))
            _libxdo.xdo_clear_active_modifiers(self._xdo, window, active_mods,
                                               active_mods_n)
        ret = _libxdo.xdo_enter_text_window(self._xdo, window, string,
                                            delay_int)
        if clearmodifiers:
            _libxdo.xdo_set_active_modifiers(self._xdo, window, active_mods,
                                             active_mods_n)
            _libc.free(active_mods)
            
        return ret

    def send_keysequence_window(self, keysequence, clearmodifiers=True,
                                delay=timedelta(microseconds=12000),
                                window=CURRENTWINDOW):
        """
        Send a keysequence to the specified window.

        This allows you to send keysequences by symbol name. Any combination
        of X11 KeySym names separated by '+' are valid. Single KeySym names
        are valid, too.

        Examples:
          "l"
          "semicolon"
          "alt+Return"
          "Alt_L+Tab"

        If you want to type a string, such as "Hello world." you want to instead
        use xdo_enter_text_window.

        :param window:
            The window you want to send the keysequence to or CURRENTWINDOW
        :param keysequence:
            The string keysequence to send.
        :param delay:
            The delay between keystrokes as a datetime.timedelta. default: 12 milliseconds.
            If passed as an int, it will be treated as microseconds
        :param clearmodifiers:
            Whether to clear any current modifier keys before sending
            the keysequence (defaults to True).
        """
        if type(delay) == timedelta:
            delay_int = int(delay.total_seconds() * 1000000)
        elif type(delay) == int:
            delay_int = delay
        else:
            raise TypeError("delay parameter should be either a timedelta or an int")

        if type(keysequence) != type(b''):
            # FIXME: is it right to assume that we're going to encode
            # in UTF-8?  if the sender wants to send a keysequence as
            # a bytestring, they can just send it as a bytestring in
            # the first place.
            keysequence = codecs.encode(keysequence, 'utf-8')

        if clearmodifiers:
            active_mods_n = ctypes.c_int(0)
            active_mods = _charcodemap_ptr()
            _libxdo.xdo_get_active_modifiers(self._xdo, ctypes.byref(active_mods),
                                             ctypes.byref(active_mods_n))
            _libxdo.xdo_clear_active_modifiers(self._xdo, window, active_mods,
                                               active_mods_n)
        ret = _libxdo.xdo_send_keysequence_window(self._xdo, window, keysequence,
                                                  delay_int)
        if clearmodifiers:
            _libxdo.xdo_set_active_modifiers(self._xdo, window, active_mods,
                                             active_mods_n)
            _libc.free(active_mods)

        return ret

    @deprecated
    def type(self, string, clearmodifiers=True, delay=12000, window=CURRENTWINDOW):
        """
        Please use enter_text_window() instead of type()!  note that the delay
        parameter for enter_text_window expects a datetime.timedelta
        """
        if type(delay) == int:
            delay = timedelta(microseconds=delay)
        return self.enter_text_window(string, clearmodifiers=clearmodifiers,
                                      delay=delay, window=window)

    def focus_window(self, window=CURRENTWINDOW):
        """
        Focus a window.

        :param wid: the window to focus.
        """
        _libxdo.xdo_focus_window(self._xdo, window)

    def get_focused_window(self):
        """
        Get the window currently having focus.

        :returns window:
        identifier for the currently-focused window
        """
        window_ret = _window_t(0)
        _libxdo.xdo_get_focused_window(self._xdo, ctypes.byref(window_ret))
        return window_ret.value

    def wait_for_window_focus(self, window, want_focus=True):
        """
        Wait for a window to have or lose focus.

        :param window: The window to wait on
        :param want_focus: If True, wait for focus. If False, wait for loss of focus. (default: True)
        """
        _libxdo.xdo_wait_for_window_focus(self._xdo, window, 1 if want_focus else 0)