Current File : /home/mmdealscpanel/yummmdeals.com/slip.tar
__init__.py000064400000000000150501260640006642 0ustar00dbus/__init__.py000064400000000336150501260640007613 0ustar00# -*- coding: utf-8 -*-

from __future__ import absolute_import

from . import bus
from .bus import SessionBus, SystemBus, StarterBus
from . import proxies
from . import service
from . import polkit
from . import mainloop
dbus/polkit.py000064400000022111150501260720007350 0ustar00# -*- coding: utf-8 -*-

# slip.dbus.polkit -- convenience decorators and functions for using PolicyKit
# with dbus services and clients
#
# Copyright © 2008, 2009, 2012, 2013, 2015 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
# Nils Philippsen <nils@redhat.com>

"""This module contains convenience decorators and functions for using
PolicyKit with dbus services and clients."""

from __future__ import absolute_import

import collections
import dbus
from decorator import decorator
from functools import reduce

from .constants import method_call_no_timeout

__all__ = ["require_auth", "enable_proxy", "AUTHFAIL_DONTCATCH",
           "NotAuthorizedException", "AreAuthorizationsObtainable",
           "IsSystemBusNameAuthorizedAsync"]


def require_auth(polkit_auth):
    """Decorator for DBus service methods.

    Specify that a user needs a specific PolicyKit authorization `polkit_auth´
    to execute it."""

    def require_auth_decorator(method):
        assert hasattr(method, "_dbus_is_method")

        setattr(method, "_slip_polkit_auth_required", polkit_auth)
        return method

    return require_auth_decorator


AUTH_EXC_PREFIX = \
    "org.fedoraproject.slip.dbus.service.PolKit.NotAuthorizedException."


class AUTHFAIL_DONTCATCH(object):
    pass


def enable_proxy(
    func=None, authfail_result=AUTHFAIL_DONTCATCH, authfail_exception=None,
    authfail_callback=None):

    """Decorator for DBus proxy methods.

    Let's you (optionally) specify either a result value or an exception type
    and a callback which is returned, thrown or called respectively if a
    PolicyKit authorization doesn't exist or can't be obtained in the DBus
    mechanism, i.e. an appropriate DBus exception is thrown.

    An exception constructor may and a callback must accept an `action_id´
    parameter which will be set to the id of the PolicyKit action for which
    authorization could not be obtained.

    Examples:

    1) Return `False´ in the event of an authorization problem, and call
    `error_handler´:

        def error_handler(action_id=None):
            print "Authorization problem:", action_id

        class MyProxy(object):
            @polkit.enable_proxy(authfail_result=False,
                                 authfail_callback=error_handler)
            def some_method(self, ...):
                ...

    2) Throw a `MyAuthError´ instance in the event of an authorization problem:

        class MyAuthError(Exception):
            def __init__(self, *args, **kwargs):
                action_id = kwargs.pop("action_id")
                super(MyAuthError, self).__init__(*args, **kwargs)
                self.action_id = action_id

        class MyProxy(object):
            @polkit.enable_proxy(authfail_exception=MyAuthError)
            def some_method(self, ...):
                ..."""

    assert(func is None or isinstance(func, collections.Callable))

    assert(
        authfail_result in (None, AUTHFAIL_DONTCATCH) or
        authfail_exception is None)
    assert(
        authfail_callback is None or
        isinstance(authfail_callback, collections.Callable))
    assert(
        authfail_exception is None or
        issubclass(authfail_exception, Exception))

    def _enable_proxy(func, *p, **k):

        try:
            return func(*p, **k)
        except dbus.DBusException as e:
            exc_name = e.get_dbus_name()

            if not exc_name.startswith(AUTH_EXC_PREFIX):
                raise

            action_id = exc_name[len(AUTH_EXC_PREFIX):]

            if authfail_callback is not None:
                authfail_callback(action_id=action_id)

            if authfail_exception is not None:
                try:
                    af_exc = authfail_exception(action_id=action_id)
                except:
                    af_exc = authfail_exception()
                raise af_exc

            if authfail_result is AUTHFAIL_DONTCATCH:
                raise

            return authfail_result

    if func is not None:
        return decorator(_enable_proxy, func)
    else:
        def decorate(func):
            return decorator(_enable_proxy, func)
        return decorate


class NotAuthorizedException(dbus.DBusException):

    """Exception which a DBus service method throws if an authorization
    required for executing it can't be obtained."""

    _dbus_error_name = \
        "org.fedoraproject.slip.dbus.service.PolKit.NotAuthorizedException"

    def __init__(self, action_id, *p, **k):

        self._dbus_error_name = self.__class__._dbus_error_name + "." +\
            action_id
        super(NotAuthorizedException, self).__init__(*p, **k)


class PolKit(object):

    """Convenience wrapper around polkit."""

    _dbus_name = 'org.freedesktop.PolicyKit1'
    _dbus_path = '/org/freedesktop/PolicyKit1/Authority'
    _dbus_interface = 'org.freedesktop.PolicyKit1.Authority'

    __interface = None
    __bus = None
    __bus_name = None
    __signal_receiver = None

    @classmethod
    def _on_name_owner_changed(cls, name, old_owner, new_owner):
        if name == cls._dbus_name and PolKit.__bus:
            PolKit.__bus.remove_signal_receiver(PolKit.__signal_receiver)
            PolKit.__bus = None
            PolKit.__signal_receiver = None
            PolKit.__interface = None

    @property
    def _bus(self):
        if not PolKit.__bus:
            PolKit.__bus = dbus.SystemBus()
            PolKit.__signal_receiver = PolKit.__bus.add_signal_receiver(
                handler_function=self._on_name_owner_changed,
                signal_name='NameOwnerChanged',
                dbus_interface='org.freedesktop.DBus',
                arg0=self._dbus_name)
        return PolKit.__bus

    @property
    def _bus_name(self):
        if not PolKit.__bus_name:
            PolKit.__bus_name = self._bus.get_unique_name()
        return PolKit.__bus_name

    @property
    def _interface(self):
        if not PolKit.__interface:
            try:
                PolKit.__interface = dbus.Interface(self._bus.get_object(
                    self._dbus_name, self._dbus_path),
                    self._dbus_interface)
            except dbus.DBusException:
                pass
        return PolKit.__interface

    @property
    def _polkit_present(self):
        return bool(self._interface)

    def __dbus_system_bus_name_uid(self, system_bus_name):
        bus_object = self._bus.get_object(
            'org.freedesktop.DBus', '/org/freedesktop/DBus')
        bus_interface = dbus.Interface(bus_object, 'org.freedesktop.DBus')
        try:
            uid = bus_interface.GetConnectionUnixUser(system_bus_name)
        except:
            uid = None
        return uid

    def __authorization_is_obtainable(self, authorization):
        if not self._polkit_present:
            return True

        (is_authorized, is_challenge, details) = \
            self._interface.CheckAuthorization(
                ("system-bus-name", {"name": self._bus_name}),
                authorization, {}, 0, "")

        return is_authorized or is_challenge

    def AreAuthorizationsObtainable(self, authorizations):
        if not self._polkit_present:
            return True

        if not isinstance(authorizations, (tuple, list, set)):
            authorizations = (authorizations,)

        obtainable = \
            reduce(
                lambda x, y: x and self.__authorization_is_obtainable(y),
                authorizations, True)

        return obtainable

    def IsSystemBusNameAuthorizedAsync(
        self, system_bus_name, action_id, reply_handler, error_handler,
        challenge=True, details={}):

        if not self._polkit_present:
            return reply_handler(action_id is None or
                self.__dbus_system_bus_name_uid(system_bus_name) == 0)

        flags = 0
        if challenge:
            flags |= 0x1

        def reply_cb(args):
            (is_authorized, is_challenge, details) = args
            reply_handler(is_authorized)

        self._interface.CheckAuthorization(
            ("system-bus-name", {"name": system_bus_name}),
            action_id, details, flags, "",
            reply_handler=reply_cb, error_handler=error_handler,
            timeout=method_call_no_timeout)


__polkit = PolKit()


def AreAuthorizationsObtainable(authorizations):
    return __polkit.AreAuthorizationsObtainable(authorizations)


def IsSystemBusNameAuthorizedAsync(
    system_bus_name, action_id, reply_handler, error_handler, challenge=True,
    details={}):

    return __polkit.IsSystemBusNameAuthorizedAsync(
        system_bus_name, action_id, reply_handler, error_handler, challenge,
        details)
dbus/introspection.py000064400000010330150501260770010753 0ustar00# -*- coding: utf-8 -*-

# slip.dbus.introspection -- access dbus introspection data
#
# Copyright © 2011 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
# Nils Philippsen <nils@redhat.com>

"""Classes and functions to easily access DBus introspection data."""

from __future__ import absolute_import

from xml.etree.ElementTree import ElementTree
from io import StringIO
from six import with_metaclass


class IElemMeta(type):
    """Metaclass for introspection elements.

    Sets elemname class member automatically from class name if not set
    explicitly. Registers classes for their element names."""

    elemnames_to_classes = {}

    @classmethod
    def clsname_to_elemname(cls, clsname):
        elemname = ""
        for c in clsname:
            c_lower = c.lower()
            if c_lower != c:
                if len(elemname):
                    elemname += "_"
            elemname += c_lower
        return elemname

    def __new__(cls, name, bases, dct):
        if name == "IElem":
            return type.__new__(cls, name, bases, dct)

        if 'elemname' not in dct:
            if not name.startswith("IElem"):
                raise TypeError(
                    "Class '%s' needs to set elemname (or be called "
                    "'IElem...'))" % name)
            dct['elemname'] = IElemMeta.clsname_to_elemname(name[5:])

        elemname = dct['elemname']

        if elemname in IElemMeta.elemnames_to_classes:
            raise TypeError(
                "Class '%s' tries to register duplicate elemname '%s'" %
                (name, elemname))

        kls = type.__new__(cls, name, bases, dct)

        IElemMeta.elemnames_to_classes[elemname] = kls

        return kls


class IElem(with_metaclass(IElemMeta, object)):
    """Base class for introspection elements."""

    def __new__(cls, elem, parent=None):
        kls = IElemMeta.elemnames_to_classes.get(
            elem.tag, IElemMeta.elemnames_to_classes[None])
        return super(IElem, cls).__new__(kls, elem, parent)

    def __init__(self, elem, parent=None):
        self.elem = elem
        self.parent = parent
        self.child_elements = [IElem(c, parent=self) for c in elem]

    def __str__(self):
        s = "%s %r" % (self.elemname if self.elemname else "unknown:%s" %
            self.elem.tag, self.attrib)
        for c in self.child_elements:
            for cc in str(c).split("\n"):
                s += "\n  %s" % (cc)
        return s

    @property
    def attrib(self):
        return self.elem.attrib


class IElemUnknown(IElem):
    """Catch-all for unknown introspection elements."""

    elemname = None


class IElemNameMixin(object):
    """Mixin for introspection elements with names."""

    @property
    def name(self):
        return self.attrib['name']


class IElemNode(IElem, IElemNameMixin):
    """Introspection node."""

    def __init__(self, elem, parent=None):
        super(IElemNode, self).__init__(elem, parent)

        self.child_nodes = [
            c for c in self.child_elements if isinstance(c, IElemNode)]


class IElemInterface(IElem):
    """Introspection interface."""


class IElemMethod(IElem):
    """Introspection interface method."""


class IElemArg(IElem):
    """Introspection method argument."""


class IElemSignal(IElem, IElemNameMixin):
    """Introspection interface signal."""


def introspect(string_or_file):
    tree = ElementTree()
    # assume string if read() method doesn't exist, works for string, unicode,
    # dbus.String
    if not hasattr(string_or_file, "read"):
        string_or_file = StringIO(string_or_file)
    xml_root = tree.parse(string_or_file)
    elem_root = IElem(xml_root)
    return elem_root
dbus/__pycache__/mainloop.cpython-36.pyc000064400000006142150501261040014152 0ustar003

�uAc#
�@s@dZddlmZd
ZGdd�de�ZGdd�de�Zdd�Zd	S)zVThis module contains mainloop wrappers.

Currently only glib main loops are supported.�)�absolute_import�MainLoop�set_typecsXeZdZdZdZ�fdd�Zedd��Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Z�Z
S)raAn abstract main loop wrapper class and factory.

    Use MainLoop() to get a main loop wrapper object for a main loop type
    previously registered with set_type(). Defaults to glib main loops.

    Actual main loop wrapper classes are derived from this class.Ncs.tjdkrtjd�tt|�jtjf|�|�S)N�glib)rZ_mainloop_classr�super�__new__�_MainLoop__mainloop_class)�cls�args�kwargs)�	__class__��/usr/lib/python3.6/mainloop.pyr*s


zMainLoop.__new__cCsHtjdk	rtd��dti}||kr.||t_ntd|dj|�f��dS)zxSet a main loop type for non-blocking interfaces.

        mltype: "glib" (currently only glib main loops are supported)Nz(The main loop type can only be set once.rz0'%s' is not one of the valid main loop types:
%sz, )rr�RuntimeError�GlibMainLoop�
ValueError�join)r	�mltypeZ
ml_type_classr
r
rr1s
zMainLoop.set_typecCs
t��dS)z$Returns if there are pending events.N)�NotImplementedError)�selfr
r
r�pendingCszMainLoop.pendingcCs
t��dS)z Iterates over one pending event.N)r)rr
r
r�iterateHszMainLoop.iteratecCsx|j�r|j�qWdS)z!Iterates over all pending events.N)rr)rr
r
r�iterate_over_pending_eventsMs
z$MainLoop.iterate_over_pending_eventscCs
t��dS)zRuns the main loop.N)r)rr
r
r�runSszMainLoop.runcCs
t��dS)zQuits the main loop.N)r)rr
r
r�quitXsz
MainLoop.quit)�__name__�
__module__�__qualname__�__doc__rr�classmethodrrrrrr�
__classcell__r
r
)rrr sc@seZdZdd�ZdS)rcCsFddlm}|j�}|j�}||_|j|_|j|_|j|_|j	|_	dS)N�)�_glib)
Z	_wrappersr"rZget_contextZ	_mainlooprZ	iterationrrr)rr"ZmlZctxr
r
r�__init__`szGlibMainLoop.__init__N)rrrr#r
r
r
rr^srcCs$ddlm}|dt�tj|�dS)z�Set a main loop type for non-blocking interfaces.

    mltype: "glib" (currently only glib main loops are supported)

    Deprecated, use MainLoop.set_type() instead.r)�warnzuse MainLoop.set_type() insteadN)�warningsr$�DeprecationWarningrr)rr$r
r
rrls
N)rr)rZ
__future__r�__all__�objectrrrr
r
r
r�<module>s
>dbus/__pycache__/bus.cpython-36.pyc000064400000001322150501261110013116 0ustar003

�uAcY�@sXdZddlmZddlZddlmZddlmZx"d
D]Zedee	ej
d��q6WdS)zQThis module contains functions which create monkey-patched/augmented D-Bus
buses.�)�absolute_importN�)�proxies)�	constants�Bus�	SystemBus�
SessionBus�
StarterBusz�def %(name)s(*args, **kwargs):
    busobj = dbus.%(name)s(*args, **kwargs)
    busobj.ProxyObjectClass = proxies.ProxyObject
    busobj.default_timeout = %(default_timeout)s
    return busobj
)�name�modnameZdefault_timeout)rrrr	)�__doc__Z
__future__rZdbus�rrr
�exec�__name__Zmethod_call_no_timeout�rr�/usr/lib/python3.6/bus.py�<module>s
dbus/__pycache__/polkit.cpython-36.pyc000064400000017503150501261160013644 0ustar003

�uAcI$�@s�dZddlmZddlZddlZddlmZddlmZddlm	Z	dd	d
ddd
gZ
dd�ZdZGdd
�d
e
�Zdeddfdd	�ZGdd�dej�ZGdd�de
�Ze�Zdd�Zdifdd
�ZdS)zmThis module contains convenience decorators and functions for using
PolicyKit with dbus services and clients.�)�absolute_importN)�	decorator)�reduce�)�method_call_no_timeout�require_auth�enable_proxy�AUTHFAIL_DONTCATCH�NotAuthorizedException�AreAuthorizationsObtainable�IsSystemBusNameAuthorizedAsynccs�fdd�}|S)u�Decorator for DBus service methods.

    Specify that a user needs a specific PolicyKit authorization `polkit_auth´
    to execute it.cst|d�st�t|d��|S)NZ_dbus_is_methodZ_slip_polkit_auth_required)�hasattr�AssertionError�setattr)�method)�polkit_auth��/usr/lib/python3.6/polkit.py�require_auth_decorator/sz,require_auth.<locals>.require_auth_decoratorr)rrr)rrr)szBorg.fedoraproject.slip.dbus.service.PolKit.NotAuthorizedException.c@seZdZdS)r	N)�__name__�
__module__�__qualname__rrrrr	<scs�|dkst|tj�st��dtfks0�dks0t��dksHt�tj�sHt��dks^t�t�s^t����fdd��|dk	r�t�|�S�fdd�}|SdS)u�Decorator for DBus proxy methods.

    Let's you (optionally) specify either a result value or an exception type
    and a callback which is returned, thrown or called respectively if a
    PolicyKit authorization doesn't exist or can't be obtained in the DBus
    mechanism, i.e. an appropriate DBus exception is thrown.

    An exception constructor may and a callback must accept an `action_id´
    parameter which will be set to the id of the PolicyKit action for which
    authorization could not be obtained.

    Examples:

    1) Return `False´ in the event of an authorization problem, and call
    `error_handler´:

        def error_handler(action_id=None):
            print "Authorization problem:", action_id

        class MyProxy(object):
            @polkit.enable_proxy(authfail_result=False,
                                 authfail_callback=error_handler)
            def some_method(self, ...):
                ...

    2) Throw a `MyAuthError´ instance in the event of an authorization problem:

        class MyAuthError(Exception):
            def __init__(self, *args, **kwargs):
                action_id = kwargs.pop("action_id")
                super(MyAuthError, self).__init__(*args, **kwargs)
                self.action_id = action_id

        class MyProxy(object):
            @polkit.enable_proxy(authfail_exception=MyAuthError)
            def some_method(self, ...):
                ...Ncs�y
|||�Stjk
r�}zr|j�}|jt�s2�|tt�d�}�dk	rT�|d��dk	r�y�|d�}Wn��}YnX|��tkr���Sd}~XnXdS)N)�	action_id)�dbus�
DBusExceptionZ
get_dbus_name�
startswith�AUTH_EXC_PREFIX�lenr	)�func�p�k�eZexc_namerZaf_exc)�authfail_callback�authfail_exception�authfail_resultrr�
_enable_proxyvs$


z#enable_proxy.<locals>._enable_proxycs
t�|�S)N)r)r)r%rr�decorate�szenable_proxy.<locals>.decorate)�
isinstance�collections�Callablerr	�
issubclass�	Exceptionr)rr$r#r"r&r)r%r"r#r$rr@s*
cs$eZdZdZdZ�fdd�Z�ZS)r
zqException which a DBus service method throws if an authorization
    required for executing it can't be obtained.zAorg.fedoraproject.slip.dbus.service.PolKit.NotAuthorizedExceptioncs(|jjd||_tt|�j||�dS)N�.)�	__class__�_dbus_error_name�superr
�__init__)�selfrrr )r-rrr0�s
zNotAuthorizedException.__init__)rrr�__doc__r.r0�
__classcell__rr)r-rr
�sc@s�eZdZdZdZdZdZdZdZdZ	dZ
edd��Ze
dd	��Ze
d
d��Ze
dd
��Ze
dd��Zdd�Zdd�Zdd�Zdifdd�ZdS)�PolKitz"Convenience wrapper around polkit.zorg.freedesktop.PolicyKit1z%/org/freedesktop/PolicyKit1/Authorityz$org.freedesktop.PolicyKit1.AuthorityNcCs4||jkr0tjr0tjjtj�dt_dt_dt_dS)N)�
_dbus_namer4�_PolKit__busZremove_signal_receiver�_PolKit__signal_receiver�_PolKit__interface)�cls�nameZ	old_ownerZ	new_ownerrrr�_on_name_owner_changed�s
zPolKit._on_name_owner_changedcCs0tjs*tj�t_tjj|jdd|jd�t_tjS)NZNameOwnerChangedzorg.freedesktop.DBus)Zhandler_functionZsignal_nameZdbus_interfaceZarg0)r4r6rZ	SystemBusZadd_signal_receiverr;r5r7)r1rrr�_bus�s
zPolKit._buscCstjs|jj�t_tjS)N)r4�_PolKit__bus_namer<Zget_unique_name)r1rrr�	_bus_name�szPolKit._bus_namecCsFtjs@y"tj|jj|j|j�|j�t_Wntj	k
r>YnXtjS)N)
r4r8r�	Interfacer<�
get_objectr5�
_dbus_path�_dbus_interfacer)r1rrr�
_interface�s

zPolKit._interfacecCs
t|j�S)N)�boolrC)r1rrr�_polkit_present�szPolKit._polkit_presentc	Cs>|jjdd�}tj|d�}y|j|�}Wnd}YnX|S)Nzorg.freedesktop.DBusz/org/freedesktop/DBus)r<r@rr?ZGetConnectionUnixUser)r1�system_bus_nameZ
bus_objectZ
bus_interfaceZuidrrrZ__dbus_system_bus_name_uid�s
z!PolKit.__dbus_system_bus_name_uidcCs6|js
dS|jjdd|jif|idd�\}}}|p4|S)NTzsystem-bus-namer:r�)rErC�CheckAuthorizationr>)r1Z
authorization�
is_authorized�is_challenge�detailsrrrZ__authorization_is_obtainable�sz$PolKit.__authorization_is_obtainablecs8�js
dSt|tttf�s |f}t�fdd�|d�}|S)NTcs|o�j|�S)N)�$_PolKit__authorization_is_obtainable)�x�y)r1rr�<lambda>�sz4PolKit.AreAuthorizationsObtainable.<locals>.<lambda>)rEr'�tuple�list�setr)r1�authorizationsZ
obtainabler)r1rr�s
z"PolKit.AreAuthorizationsObtainableTc	
sd|js �|dkp|j|�dk�Sd}|r0|dO}�fdd�}|jjdd|if|||d||td�dS)	Nrrcs|\}}}�|�dS)Nr)�argsrIrJrK)�
reply_handlerrr�reply_cbs
z7PolKit.IsSystemBusNameAuthorizedAsync.<locals>.reply_cbzsystem-bus-namer:rG)rU�
error_handlerZtimeout)rE�!_PolKit__dbus_system_bus_name_uidrCrHr)	r1rFrrUrW�	challengerK�flagsrVr)rUrrs

z%PolKit.IsSystemBusNameAuthorizedAsync)rrrr2r5rArBr8r6r=r7�classmethodr;�propertyr<r>rCrErXrLrrrrrrr4�s"
r4cCs
tj|�S)N)�__polkitr)rSrrrrsTcCstj||||||�S)N)r]r)rFrrUrWrYrKrrrrs
)r2Z
__future__rr(rr�	functoolsrZ	constantsr�__all__rr�objectr	rrr
r4r]rrrrrr�<module>s(Wodbus/__pycache__/constants.cpython-36.opt-1.pyc000064400000000335150501261230015306 0ustar003

�uAc��@sdZdZdS)z*This module contains some constant values.i���g@�@Ng`���Mb@A)�__doc__Zmethod_call_no_timeout�rr�/usr/lib/python3.6/constants.py�<module>sdbus/__pycache__/service.cpython-36.opt-1.pyc000064400000012352150501261300014732 0ustar003

�uAc��@s�dZddlmZddlZddlZddlmZddlmZ	ddl
mZd	d
dgZda
dd
�Zeadd�Zdd�Zdd�Zdadadd�ZGdd
�d
ejj�ZGdd	�d	eeejj��ZdS)zMThis module contains convenience functions for using dbus-activated services.�)�absolute_importN)�with_metaclass�)�_glib�)�polkit�Object�
InterfaceType�set_mainloopcCstj�dS)N)�__mainloop__�quit�r
r
�/usr/lib/python3.6/service.py�__glib_quit_cb__)srcCs|adS)N)r)Zmainloopr
r
rr
4scCs|adS)N)�__quit_cb__)�quit_cbr
r
r�set_quit_cb9srcCs
t�dS)N)rr
r
r
rr>srZ__slip_dbus_service_sender__�__slip_dbus_service_reply_cb__�__slip_dbus_service_error_cb__cs��jdk	r�j�d�nt�d��jdk	r4�j�d�nt�d���������fdd�}xLdd�t��D�D]6}|dkr��|_ql|dkr��|_qlt||t�|��qlW�j|_|S)	NFTcs��j��}|dk	rV��d���d��r4��=�rL��d=��d=�j|�t�	dt�dd���|dk	r��r�����	�
���fdd�}��fdd�}tj|�||d	�n�	�f����}�j�|SdS)
NrrZ_slip_polkit_auth_required�default_polkit_auth_requiredcs�|r��r��f����q�d}y��f����}Wn&tk
rX}z
|}WYdd}~XnX|rh�|�q�|dkrx��q��|�n�tj����j�dS)N)�	ExceptionrZNotAuthorizedException�timeout_restart)Zis_auth�error�result�e)�	action_id�error_cb�k�method�method_is_async�p�reply_cb�selfr
r�
reply_handlerqs

z:wrap_method.<locals>.wrapped_method.<locals>.reply_handlercs�|��j�dS)N)r)r)rr"r
r�
error_handler�sz:wrap_method.<locals>.wrapped_method.<locals>.error_handler)r#r$)�get�sender_seen�getattrrZIsSystemBusNameAuthorizedAsyncr)r"r r�senderr#r$Zretval)�async_callbacks�hide_async_callbacks�hide_sender_keywordrr�sender_keyword)rrrr r!r"r�wrapped_method[s,



"z#wrap_method.<locals>.wrapped_methodcss"|]}|dd�dkr|VqdS)N�Z_dbus_r
)�.0�xr
r
r�	<genexpr>�szwrap_method.<locals>.<genexpr>�_dbus_sender_keyword�_dbus_async_callbacks)r2�SENDER_KEYWORDr3�ASYNC_CALLBACKS�dir�setattrr'�__name__)rr-�attrr
)r)r*r+rrr,r�wrap_methodHs(

Er:cseZdZ�fdd�Z�ZS)r	csDx,|j�D] \}}t|dd�r
t|�||<q
Wtt|�j||||�S)NZ_dbus_is_methodF)�itemsr'r:�superr	�__new__)�cls�name�basesZdctZattrnamer9)�	__class__r
rr=�szInterfaceType.__new__)r8�
__module__�__qualname__r=�
__classcell__r
r
)rArr	�scsbeZdZdZdZeZdZe�ZiZ	iZ
dZd�fdd�	Zdd�Z
dd	�Zdd
d�Zdd
�Z�ZS)rF�Ncs2tt|�j|||�|dkr(|jj|_n||_dS)N)r<r�__init__rA�
persistent)r"�connZobject_pathZbus_namerG)rAr
rrF�szObject.__init__cCs2|jr ttj�dkr t�dSdt_|jt_dS)NrF)rG�lenr�sendersr�current_source�default_duration�duration)r"r
r
r�_timeout_cb�szObject._timeout_cbcCs�|j}|r�||ftjkr�tjj||f�tj|j|�ttj|�dkrjtj|j�tj|=tj|=|jr�ttj�dkr�tjdkr�t	�dS)Nr)
�
connectionrrJ�remove�connections_sendersrI�connections_smobjsrGrKr)r"r?Z	old_ownerZ	new_ownerrHr
r
r�_name_owner_changed�s
zObject._name_owner_changedcCsf|s|jj}tjs|tjkr$|t_|js:ttj�dkrbtjrLtj	tj�tj
tjd|j�t_dS)Nri�)rArLrrMrGrIrJrK�GLibZ
source_removeZtimeout_addrN)r"rMr
r
rr�szObject.timeout_restartcCsp||jftjkrltjj||jf�|jtjkrZt�tj|j<|jj|jdd|d�tj|j<tj|jj|�dS)NZNameOwnerChangedzorg.freedesktop.DBus)Zhandler_functionZsignal_nameZdbus_interfaceZarg1)	rOrrJ�addrQ�setZadd_signal_receiverrSrR)r"r(r
r
rr&�szObject.sender_seen)NNNN)N)r8rBrCrGrLrMrKrVrJrQrRrrFrNrSrr&rDr
r
)rArr�s

)rr)�__doc__Z
__future__rZdbusZdbus.serviceZsixrZ	_wrappersrrT�r�__all__rrrr
rrr4r5r:Zservicer	rr
r
r
r�<module>s&
g
dbus/__pycache__/proxies.cpython-36.opt-1.pyc000064400000002345150501261350014771 0ustar003

�uAc`�@sPdZddlmZddlZddlmZGdd�dejj�ZGdd	�d	ejj	�Z	dS)
z{This module contains D-Bus proxy classes which implement the default
timeout of the augmented bus classes in slip.dbus.bus.�)�absolute_importN�)�	constantsc@s$eZdZiZedd��Zdd�ZdS)�_ProxyMethodcCsB|j|jkr6t|jjdd�}|dkr*tj}||j|j<|j|jS)N�default_timeout)Z_connection�_connections_default_timeouts�getattr�_proxyZ_busrZmethod_call_no_timeout)�selfZdt�r�/usr/lib/python3.6/proxies.pyr&sz_ProxyMethod.default_timeoutcOs.|jd�dkr|j|d<tjjj|f|�|�S)NZtimeout)�getr�dbus�proxiesr�__call__)r
�args�kwargsrrrr/s
z_ProxyMethod.__call__N)�__name__�
__module__�__qualname__r�propertyrrrrrrr"s	rc@seZdZeZdS)�ProxyObjectN)rrrrZProxyMethodClassrrrrr6sr)
�__doc__Z
__future__rZdbus.proxiesr�rrrrrrrr�<module>s
dbus/__pycache__/polkit.cpython-36.opt-1.pyc000064400000017150150501261430014601 0ustar003

�uAcI$�@s�dZddlmZddlZddlZddlmZddlmZddlm	Z	dd	d
ddd
gZ
dd�ZdZGdd
�d
e
�Zdeddfdd	�ZGdd�dej�ZGdd�de
�Ze�Zdd�Zdifdd
�ZdS)zmThis module contains convenience decorators and functions for using
PolicyKit with dbus services and clients.�)�absolute_importN)�	decorator)�reduce�)�method_call_no_timeout�require_auth�enable_proxy�AUTHFAIL_DONTCATCH�NotAuthorizedException�AreAuthorizationsObtainable�IsSystemBusNameAuthorizedAsynccs�fdd�}|S)u�Decorator for DBus service methods.

    Specify that a user needs a specific PolicyKit authorization `polkit_auth´
    to execute it.cst|d��|S)NZ_slip_polkit_auth_required)�setattr)�method)�polkit_auth��/usr/lib/python3.6/polkit.py�require_auth_decorator/sz,require_auth.<locals>.require_auth_decoratorr)rrr)rrr)szBorg.fedoraproject.slip.dbus.service.PolKit.NotAuthorizedException.c@seZdZdS)r	N)�__name__�
__module__�__qualname__rrrrr	<scs6���fdd��|dk	r"t�|�S�fdd�}|SdS)u�Decorator for DBus proxy methods.

    Let's you (optionally) specify either a result value or an exception type
    and a callback which is returned, thrown or called respectively if a
    PolicyKit authorization doesn't exist or can't be obtained in the DBus
    mechanism, i.e. an appropriate DBus exception is thrown.

    An exception constructor may and a callback must accept an `action_id´
    parameter which will be set to the id of the PolicyKit action for which
    authorization could not be obtained.

    Examples:

    1) Return `False´ in the event of an authorization problem, and call
    `error_handler´:

        def error_handler(action_id=None):
            print "Authorization problem:", action_id

        class MyProxy(object):
            @polkit.enable_proxy(authfail_result=False,
                                 authfail_callback=error_handler)
            def some_method(self, ...):
                ...

    2) Throw a `MyAuthError´ instance in the event of an authorization problem:

        class MyAuthError(Exception):
            def __init__(self, *args, **kwargs):
                action_id = kwargs.pop("action_id")
                super(MyAuthError, self).__init__(*args, **kwargs)
                self.action_id = action_id

        class MyProxy(object):
            @polkit.enable_proxy(authfail_exception=MyAuthError)
            def some_method(self, ...):
                ...cs�y
|||�Stjk
r�}zr|j�}|jt�s2�|tt�d�}�dk	rT�|d��dk	r�y�|d�}Wn��}YnX|��tkr���Sd}~XnXdS)N)�	action_id)�dbus�
DBusExceptionZ
get_dbus_name�
startswith�AUTH_EXC_PREFIX�lenr	)�func�p�k�eZexc_namerZaf_exc)�authfail_callback�authfail_exception�authfail_resultrr�
_enable_proxyvs$


z#enable_proxy.<locals>._enable_proxyNcs
t�|�S)N)r)r)r#rr�decorate�szenable_proxy.<locals>.decorate)r)rr"r!r r$r)r#r r!r"rr@s
6
cs$eZdZdZdZ�fdd�Z�ZS)r
zqException which a DBus service method throws if an authorization
    required for executing it can't be obtained.zAorg.fedoraproject.slip.dbus.service.PolKit.NotAuthorizedExceptioncs(|jjd||_tt|�j||�dS)N�.)�	__class__�_dbus_error_name�superr
�__init__)�selfrrr)r&rrr)�s
zNotAuthorizedException.__init__)rrr�__doc__r'r)�
__classcell__rr)r&rr
�sc@s�eZdZdZdZdZdZdZdZdZ	dZ
edd��Ze
dd	��Ze
d
d��Ze
dd
��Ze
dd��Zdd�Zdd�Zdd�Zdifdd�ZdS)�PolKitz"Convenience wrapper around polkit.zorg.freedesktop.PolicyKit1z%/org/freedesktop/PolicyKit1/Authorityz$org.freedesktop.PolicyKit1.AuthorityNcCs4||jkr0tjr0tjjtj�dt_dt_dt_dS)N)�
_dbus_namer-�_PolKit__busZremove_signal_receiver�_PolKit__signal_receiver�_PolKit__interface)�cls�nameZ	old_ownerZ	new_ownerrrr�_on_name_owner_changed�s
zPolKit._on_name_owner_changedcCs0tjs*tj�t_tjj|jdd|jd�t_tjS)NZNameOwnerChangedzorg.freedesktop.DBus)Zhandler_functionZsignal_nameZdbus_interfaceZarg0)r-r/rZ	SystemBusZadd_signal_receiverr4r.r0)r*rrr�_bus�s
zPolKit._buscCstjs|jj�t_tjS)N)r-�_PolKit__bus_namer5Zget_unique_name)r*rrr�	_bus_name�szPolKit._bus_namecCsFtjs@y"tj|jj|j|j�|j�t_Wntj	k
r>YnXtjS)N)
r-r1r�	Interfacer5�
get_objectr.�
_dbus_path�_dbus_interfacer)r*rrr�
_interface�s

zPolKit._interfacecCs
t|j�S)N)�boolr<)r*rrr�_polkit_present�szPolKit._polkit_presentc	Cs>|jjdd�}tj|d�}y|j|�}Wnd}YnX|S)Nzorg.freedesktop.DBusz/org/freedesktop/DBus)r5r9rr8ZGetConnectionUnixUser)r*�system_bus_nameZ
bus_objectZ
bus_interfaceZuidrrrZ__dbus_system_bus_name_uid�s
z!PolKit.__dbus_system_bus_name_uidcCs6|js
dS|jjdd|jif|idd�\}}}|p4|S)NTzsystem-bus-namer3r�)r>r<�CheckAuthorizationr7)r*Z
authorization�
is_authorized�is_challenge�detailsrrrZ__authorization_is_obtainable�sz$PolKit.__authorization_is_obtainablecs8�js
dSt|tttf�s |f}t�fdd�|d�}|S)NTcs|o�j|�S)N)�$_PolKit__authorization_is_obtainable)�x�y)r*rr�<lambda>�sz4PolKit.AreAuthorizationsObtainable.<locals>.<lambda>)r>�
isinstance�tuple�list�setr)r*�authorizationsZ
obtainabler)r*rr�s
z"PolKit.AreAuthorizationsObtainableTc	
sd|js �|dkp|j|�dk�Sd}|r0|dO}�fdd�}|jjdd|if|||d||td�dS)	Nrrcs|\}}}�|�dS)Nr)�argsrBrCrD)�
reply_handlerrr�reply_cbs
z7PolKit.IsSystemBusNameAuthorizedAsync.<locals>.reply_cbzsystem-bus-namer3r@)rO�
error_handlerZtimeout)r>�!_PolKit__dbus_system_bus_name_uidr<rAr)	r*r?rrOrQ�	challengerD�flagsrPr)rOrrs

z%PolKit.IsSystemBusNameAuthorizedAsync)rrrr+r.r:r;r1r/r6r0�classmethodr4�propertyr5r7r<r>rRrErrrrrrr-�s"
r-cCs
tj|�S)N)�__polkitr)rMrrrrsTcCstj||||||�S)N)rWr)r?rrOrQrSrDrrrrs
)r+Z
__future__r�collectionsrr�	functoolsrZ	constantsr�__all__rr�objectr	rrr
r-rWrrrrrr�<module>s(Wodbus/__pycache__/introspection.cpython-36.pyc000064400000011116150501261500015232 0ustar003

�uAc��@s�dZddlmZddlmZddlmZddlmZGdd�de	�Z
Gdd	�d	ee
e��ZGd
d�de�Z
Gdd
�d
e�ZGdd�dee�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�dee�Zdd�ZdS)z?Classes and functions to easily access DBus introspection data.�)�absolute_import)�ElementTree)�StringIO)�with_metaclassc@s(eZdZdZiZedd��Zdd�ZdS)�	IElemMetaz�Metaclass for introspection elements.

    Sets elemname class member automatically from class name if not set
    explicitly. Registers classes for their element names.cCs>d}x4|D],}|j�}||kr.t|�r.|d7}||7}q
W|S)N��_)�lower�len)�clsZclsname�elemname�cZc_lower�r�#/usr/lib/python3.6/introspection.py�clsname_to_elemname(s
zIElemMeta.clsname_to_elemnamecCs�|dkrtj||||�Sd|krL|jd�s6td|��tj|dd��|d<|d}|tjkrntd||f��tj||||�}|tj|<|S)N�IElemrz;Class '%s' needs to set elemname (or be called 'IElem...'))�z4Class '%s' tries to register duplicate elemname '%s')�type�__new__�
startswith�	TypeErrorrr�elemnames_to_classes)r�name�basesZdctr�klsrrrr3s 


zIElemMeta.__new__N)�__name__�
__module__�__qualname__�__doc__r�classmethodrrrrrrr srcs@eZdZdZd�fdd�	Zddd�Zdd�Zed	d
��Z�Z	S)
rz&Base class for introspection elements.Ncs*tjj|jtjd�}tt|�j|||�S)N)rr�get�tag�superrr)r�elem�parentr)�	__class__rrrOsz
IElem.__new__cs$|�_|�_�fdd�|D��_dS)Ncsg|]}t|�d��qS))r$)r)�.0r
)�selfrr�
<listcomp>Wsz"IElem.__init__.<locals>.<listcomp>)r#r$�child_elements)r'r#r$r)r'r�__init__TszIElem.__init__cCsZd|jr|jn
d|jj|jf}x2|jD](}x"t|�jd�D]}|d|7}q>Wq*W|S)Nz%s %rz
unknown:%s�
z
  %s)rr#r!�attribr)�str�split)r'�sr
Zccrrr�__str__Ysz
IElem.__str__cCs|jjS)N)r#r,)r'rrrr,aszIElem.attrib)N)N)
rrrrrr*r0�propertyr,�
__classcell__rr)r%rrLs

rc@seZdZdZdZdS)�IElemUnknownz-Catch-all for unknown introspection elements.N)rrrrrrrrrr3fsr3c@seZdZdZedd��ZdS)�IElemNameMixinz,Mixin for introspection elements with names.cCs
|jdS)Nr)r,)r'rrrroszIElemNameMixin.nameN)rrrrr1rrrrrr4lsr4cs"eZdZdZd�fdd�	Z�ZS)�	IElemNodezIntrospection node.Ncs(tt|�j||�dd�|jD�|_dS)NcSsg|]}t|t�r|�qSr)�
isinstancer5)r&r
rrrr({sz&IElemNode.__init__.<locals>.<listcomp>)r"r5r*r)Zchild_nodes)r'r#r$)r%rrr*wszIElemNode.__init__)N)rrrrr*r2rr)r%rr5tsr5c@seZdZdZdS)�IElemInterfacezIntrospection interface.N)rrrrrrrrr7~sr7c@seZdZdZdS)�IElemMethodzIntrospection interface method.N)rrrrrrrrr8�sr8c@seZdZdZdS)�IElemArgzIntrospection method argument.N)rrrrrrrrr9�sr9c@seZdZdZdS)�IElemSignalzIntrospection interface signal.N)rrrrrrrrr:�sr:cCs.t�}t|d�st|�}|j|�}t|�}|S)N�read)r�hasattrr�parser)Zstring_or_fileZtreeZxml_rootZ	elem_rootrrr�
introspect�s

r>N)rZ
__future__rZxml.etree.ElementTreer�iorZsixrrr�objectrr3r4r5r7r8r9r:r>rrrr�<module>s,
dbus/__pycache__/service.cpython-36.pyc000064400000012352150501261550014002 0ustar003

�uAc��@s�dZddlmZddlZddlZddlmZddlmZ	ddl
mZd	d
dgZda
dd
�Zeadd�Zdd�Zdd�Zdadadd�ZGdd
�d
ejj�ZGdd	�d	eeejj��ZdS)zMThis module contains convenience functions for using dbus-activated services.�)�absolute_importN)�with_metaclass�)�_glib�)�polkit�Object�
InterfaceType�set_mainloopcCstj�dS)N)�__mainloop__�quit�r
r
�/usr/lib/python3.6/service.py�__glib_quit_cb__)srcCs|adS)N)r)Zmainloopr
r
rr
4scCs|adS)N)�__quit_cb__)�quit_cbr
r
r�set_quit_cb9srcCs
t�dS)N)rr
r
r
rr>srZ__slip_dbus_service_sender__�__slip_dbus_service_reply_cb__�__slip_dbus_service_error_cb__cs��jdk	r�j�d�nt�d��jdk	r4�j�d�nt�d���������fdd�}xLdd�t��D�D]6}|dkr��|_ql|dkr��|_qlt||t�|��qlW�j|_|S)	NFTcs��j��}|dk	rV��d���d��r4��=�rL��d=��d=�j|�t�	dt�dd���|dk	r��r�����	�
���fdd�}��fdd�}tj|�||d	�n�	�f����}�j�|SdS)
NrrZ_slip_polkit_auth_required�default_polkit_auth_requiredcs�|r��r��f����q�d}y��f����}Wn&tk
rX}z
|}WYdd}~XnX|rh�|�q�|dkrx��q��|�n�tj����j�dS)N)�	ExceptionrZNotAuthorizedException�timeout_restart)Zis_auth�error�result�e)�	action_id�error_cb�k�method�method_is_async�p�reply_cb�selfr
r�
reply_handlerqs

z:wrap_method.<locals>.wrapped_method.<locals>.reply_handlercs�|��j�dS)N)r)r)rr"r
r�
error_handler�sz:wrap_method.<locals>.wrapped_method.<locals>.error_handler)r#r$)�get�sender_seen�getattrrZIsSystemBusNameAuthorizedAsyncr)r"r r�senderr#r$Zretval)�async_callbacks�hide_async_callbacks�hide_sender_keywordrr�sender_keyword)rrrr r!r"r�wrapped_method[s,



"z#wrap_method.<locals>.wrapped_methodcss"|]}|dd�dkr|VqdS)N�Z_dbus_r
)�.0�xr
r
r�	<genexpr>�szwrap_method.<locals>.<genexpr>�_dbus_sender_keyword�_dbus_async_callbacks)r2�SENDER_KEYWORDr3�ASYNC_CALLBACKS�dir�setattrr'�__name__)rr-�attrr
)r)r*r+rrr,r�wrap_methodHs(

Er:cseZdZ�fdd�Z�ZS)r	csDx,|j�D] \}}t|dd�r
t|�||<q
Wtt|�j||||�S)NZ_dbus_is_methodF)�itemsr'r:�superr	�__new__)�cls�name�basesZdctZattrnamer9)�	__class__r
rr=�szInterfaceType.__new__)r8�
__module__�__qualname__r=�
__classcell__r
r
)rArr	�scsbeZdZdZdZeZdZe�ZiZ	iZ
dZd�fdd�	Zdd�Z
dd	�Zdd
d�Zdd
�Z�ZS)rF�Ncs2tt|�j|||�|dkr(|jj|_n||_dS)N)r<r�__init__rA�
persistent)r"�connZobject_pathZbus_namerG)rAr
rrF�szObject.__init__cCs2|jr ttj�dkr t�dSdt_|jt_dS)NrF)rG�lenr�sendersr�current_source�default_duration�duration)r"r
r
r�_timeout_cb�szObject._timeout_cbcCs�|j}|r�||ftjkr�tjj||f�tj|j|�ttj|�dkrjtj|j�tj|=tj|=|jr�ttj�dkr�tjdkr�t	�dS)Nr)
�
connectionrrJ�remove�connections_sendersrI�connections_smobjsrGrKr)r"r?Z	old_ownerZ	new_ownerrHr
r
r�_name_owner_changed�s
zObject._name_owner_changedcCsf|s|jj}tjs|tjkr$|t_|js:ttj�dkrbtjrLtj	tj�tj
tjd|j�t_dS)Nri�)rArLrrMrGrIrJrK�GLibZ
source_removeZtimeout_addrN)r"rMr
r
rr�szObject.timeout_restartcCsp||jftjkrltjj||jf�|jtjkrZt�tj|j<|jj|jdd|d�tj|j<tj|jj|�dS)NZNameOwnerChangedzorg.freedesktop.DBus)Zhandler_functionZsignal_nameZdbus_interfaceZarg1)	rOrrJ�addrQ�setZadd_signal_receiverrSrR)r"r(r
r
rr&�szObject.sender_seen)NNNN)N)r8rBrCrGrLrMrKrVrJrQrRrrFrNrSrr&rDr
r
)rArr�s

)rr)�__doc__Z
__future__rZdbusZdbus.serviceZsixrZ	_wrappersrrT�r�__all__rrrr
rrr4r5r:Zservicer	rr
r
r
r�<module>s&
g
dbus/__pycache__/introspection.cpython-36.opt-1.pyc000064400000011116150501261620016174 0ustar003

�uAc��@s�dZddlmZddlmZddlmZddlmZGdd�de	�Z
Gdd	�d	ee
e��ZGd
d�de�Z
Gdd
�d
e�ZGdd�dee�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�dee�Zdd�ZdS)z?Classes and functions to easily access DBus introspection data.�)�absolute_import)�ElementTree)�StringIO)�with_metaclassc@s(eZdZdZiZedd��Zdd�ZdS)�	IElemMetaz�Metaclass for introspection elements.

    Sets elemname class member automatically from class name if not set
    explicitly. Registers classes for their element names.cCs>d}x4|D],}|j�}||kr.t|�r.|d7}||7}q
W|S)N��_)�lower�len)�clsZclsname�elemname�cZc_lower�r�#/usr/lib/python3.6/introspection.py�clsname_to_elemname(s
zIElemMeta.clsname_to_elemnamecCs�|dkrtj||||�Sd|krL|jd�s6td|��tj|dd��|d<|d}|tjkrntd||f��tj||||�}|tj|<|S)N�IElemrz;Class '%s' needs to set elemname (or be called 'IElem...'))�z4Class '%s' tries to register duplicate elemname '%s')�type�__new__�
startswith�	TypeErrorrr�elemnames_to_classes)r�name�basesZdctr�klsrrrr3s 


zIElemMeta.__new__N)�__name__�
__module__�__qualname__�__doc__r�classmethodrrrrrrr srcs@eZdZdZd�fdd�	Zddd�Zdd�Zed	d
��Z�Z	S)
rz&Base class for introspection elements.Ncs*tjj|jtjd�}tt|�j|||�S)N)rr�get�tag�superrr)r�elem�parentr)�	__class__rrrOsz
IElem.__new__cs$|�_|�_�fdd�|D��_dS)Ncsg|]}t|�d��qS))r$)r)�.0r
)�selfrr�
<listcomp>Wsz"IElem.__init__.<locals>.<listcomp>)r#r$�child_elements)r'r#r$r)r'r�__init__TszIElem.__init__cCsZd|jr|jn
d|jj|jf}x2|jD](}x"t|�jd�D]}|d|7}q>Wq*W|S)Nz%s %rz
unknown:%s�
z
  %s)rr#r!�attribr)�str�split)r'�sr
Zccrrr�__str__Ysz
IElem.__str__cCs|jjS)N)r#r,)r'rrrr,aszIElem.attrib)N)N)
rrrrrr*r0�propertyr,�
__classcell__rr)r%rrLs

rc@seZdZdZdZdS)�IElemUnknownz-Catch-all for unknown introspection elements.N)rrrrrrrrrr3fsr3c@seZdZdZedd��ZdS)�IElemNameMixinz,Mixin for introspection elements with names.cCs
|jdS)Nr)r,)r'rrrroszIElemNameMixin.nameN)rrrrr1rrrrrr4lsr4cs"eZdZdZd�fdd�	Z�ZS)�	IElemNodezIntrospection node.Ncs(tt|�j||�dd�|jD�|_dS)NcSsg|]}t|t�r|�qSr)�
isinstancer5)r&r
rrrr({sz&IElemNode.__init__.<locals>.<listcomp>)r"r5r*r)Zchild_nodes)r'r#r$)r%rrr*wszIElemNode.__init__)N)rrrrr*r2rr)r%rr5tsr5c@seZdZdZdS)�IElemInterfacezIntrospection interface.N)rrrrrrrrr7~sr7c@seZdZdZdS)�IElemMethodzIntrospection interface method.N)rrrrrrrrr8�sr8c@seZdZdZdS)�IElemArgzIntrospection method argument.N)rrrrrrrrr9�sr9c@seZdZdZdS)�IElemSignalzIntrospection interface signal.N)rrrrrrrrr:�sr:cCs.t�}t|d�st|�}|j|�}t|�}|S)N�read)r�hasattrr�parser)Zstring_or_fileZtreeZxml_rootZ	elem_rootrrr�
introspect�s

r>N)rZ
__future__rZxml.etree.ElementTreer�iorZsixrrr�objectrr3r4r5r7r8r9r:r>rrrr�<module>s,
dbus/__pycache__/constants.cpython-36.pyc000064400000000335150501261670014357 0ustar003

�uAc��@sdZdZdS)z*This module contains some constant values.i���g@�@Ng`���Mb@A)�__doc__Zmethod_call_no_timeout�rr�/usr/lib/python3.6/constants.py�<module>sdbus/__pycache__/__init__.cpython-36.pyc000064400000000606150501261670014103 0ustar003

�uAc��@s`ddlmZddlmZddlmZmZmZddlmZddlmZddlm	Z	ddlm
Z
d	S)
�)�absolute_import�)�bus)�
SessionBus�	SystemBus�
StarterBus)�proxies)�service)�polkit)�mainloopN)Z
__future__r�rrrrrr	r
r�r
r
�/usr/lib/python3.6/__init__.py�<module>sdbus/__pycache__/__init__.cpython-36.opt-1.pyc000064400000000606150501261740015040 0ustar003

�uAc��@s`ddlmZddlmZddlmZmZmZddlmZddlmZddlm	Z	ddlm
Z
d	S)
�)�absolute_import�)�bus)�
SessionBus�	SystemBus�
StarterBus)�proxies)�service)�polkit)�mainloopN)Z
__future__r�rrrrrr	r
r�r
r
�/usr/lib/python3.6/__init__.py�<module>sdbus/__pycache__/proxies.cpython-36.pyc000064400000002345150501262010014024 0ustar003

�uAc`�@sPdZddlmZddlZddlmZGdd�dejj�ZGdd	�d	ejj	�Z	dS)
z{This module contains D-Bus proxy classes which implement the default
timeout of the augmented bus classes in slip.dbus.bus.�)�absolute_importN�)�	constantsc@s$eZdZiZedd��Zdd�ZdS)�_ProxyMethodcCsB|j|jkr6t|jjdd�}|dkr*tj}||j|j<|j|jS)N�default_timeout)Z_connection�_connections_default_timeouts�getattr�_proxyZ_busrZmethod_call_no_timeout)�selfZdt�r�/usr/lib/python3.6/proxies.pyr&sz_ProxyMethod.default_timeoutcOs.|jd�dkr|j|d<tjjj|f|�|�S)NZtimeout)�getr�dbus�proxiesr�__call__)r
�args�kwargsrrrr/s
z_ProxyMethod.__call__N)�__name__�
__module__�__qualname__r�propertyrrrrrrr"s	rc@seZdZeZdS)�ProxyObjectN)rrrrZProxyMethodClassrrrrr6sr)
�__doc__Z
__future__rZdbus.proxiesr�rrrrrrrr�<module>s
dbus/__pycache__/bus.cpython-36.opt-1.pyc000064400000001322150501262010014055 0ustar003

�uAcY�@sXdZddlmZddlZddlmZddlmZx"d
D]Zedee	ej
d��q6WdS)zQThis module contains functions which create monkey-patched/augmented D-Bus
buses.�)�absolute_importN�)�proxies)�	constants�Bus�	SystemBus�
SessionBus�
StarterBusz�def %(name)s(*args, **kwargs):
    busobj = dbus.%(name)s(*args, **kwargs)
    busobj.ProxyObjectClass = proxies.ProxyObject
    busobj.default_timeout = %(default_timeout)s
    return busobj
)�name�modnameZdefault_timeout)rrrr	)�__doc__Z
__future__rZdbus�rrr
�exec�__name__Zmethod_call_no_timeout�rr�/usr/lib/python3.6/bus.py�<module>s
dbus/__pycache__/mainloop.cpython-36.opt-1.pyc000064400000006142150501262060015114 0ustar003

�uAc#
�@s@dZddlmZd
ZGdd�de�ZGdd�de�Zdd�Zd	S)zVThis module contains mainloop wrappers.

Currently only glib main loops are supported.�)�absolute_import�MainLoop�set_typecsXeZdZdZdZ�fdd�Zedd��Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Z�Z
S)raAn abstract main loop wrapper class and factory.

    Use MainLoop() to get a main loop wrapper object for a main loop type
    previously registered with set_type(). Defaults to glib main loops.

    Actual main loop wrapper classes are derived from this class.Ncs.tjdkrtjd�tt|�jtjf|�|�S)N�glib)rZ_mainloop_classr�super�__new__�_MainLoop__mainloop_class)�cls�args�kwargs)�	__class__��/usr/lib/python3.6/mainloop.pyr*s


zMainLoop.__new__cCsHtjdk	rtd��dti}||kr.||t_ntd|dj|�f��dS)zxSet a main loop type for non-blocking interfaces.

        mltype: "glib" (currently only glib main loops are supported)Nz(The main loop type can only be set once.rz0'%s' is not one of the valid main loop types:
%sz, )rr�RuntimeError�GlibMainLoop�
ValueError�join)r	�mltypeZ
ml_type_classr
r
rr1s
zMainLoop.set_typecCs
t��dS)z$Returns if there are pending events.N)�NotImplementedError)�selfr
r
r�pendingCszMainLoop.pendingcCs
t��dS)z Iterates over one pending event.N)r)rr
r
r�iterateHszMainLoop.iteratecCsx|j�r|j�qWdS)z!Iterates over all pending events.N)rr)rr
r
r�iterate_over_pending_eventsMs
z$MainLoop.iterate_over_pending_eventscCs
t��dS)zRuns the main loop.N)r)rr
r
r�runSszMainLoop.runcCs
t��dS)zQuits the main loop.N)r)rr
r
r�quitXsz
MainLoop.quit)�__name__�
__module__�__qualname__�__doc__rr�classmethodrrrrrr�
__classcell__r
r
)rrr sc@seZdZdd�ZdS)rcCsFddlm}|j�}|j�}||_|j|_|j|_|j|_|j	|_	dS)N�)�_glib)
Z	_wrappersr"rZget_contextZ	_mainlooprZ	iterationrrr)rr"ZmlZctxr
r
r�__init__`szGlibMainLoop.__init__N)rrrr#r
r
r
rr^srcCs$ddlm}|dt�tj|�dS)z�Set a main loop type for non-blocking interfaces.

    mltype: "glib" (currently only glib main loops are supported)

    Deprecated, use MainLoop.set_type() instead.r)�warnzuse MainLoop.set_type() insteadN)�warningsr$�DeprecationWarningrr)rr$r
r
rrls
N)rr)rZ
__future__r�__all__�objectrrrr
r
r
r�<module>s
>dbus/proxies.py000064400000003540150501262060007543 0ustar00# -*- coding: utf-8 -*-

# slip.dbus.proxies -- slightly augmented dbus proxy classes
#
# Copyright © 2005-2007 Collabora Ltd. <http://www.collabora.co.uk/>
# Copyright © 2009, 2011 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
# Nils Philippsen <nils@redhat.com>

"""This module contains D-Bus proxy classes which implement the default
timeout of the augmented bus classes in slip.dbus.bus."""

from __future__ import absolute_import

import dbus.proxies

from . import constants


class _ProxyMethod(dbus.proxies._ProxyMethod):

    _connections_default_timeouts = {}

    @property
    def default_timeout(self):
        if self._connection not in self._connections_default_timeouts:
            dt = getattr(self._proxy._bus, "default_timeout", None)
            if dt is None:
                dt = constants.method_call_no_timeout
            self._connections_default_timeouts[self._connection] = dt
        return self._connections_default_timeouts[self._connection]

    def __call__(self, *args, **kwargs):
        if kwargs.get('timeout') is None:
            kwargs["timeout"] = self.default_timeout

        return dbus.proxies._ProxyMethod.__call__(self, *args, **kwargs)


class ProxyObject(dbus.proxies.ProxyObject):

    ProxyMethodClass = _ProxyMethod
dbus/bus.py000064400000002531150501262140006641 0ustar00# -*- coding: utf-8 -*-

# slip.dbus.bus -- augmented dbus buses
#
# Copyright © 2009, 2011 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
# Nils Philippsen <nils@redhat.com>

"""This module contains functions which create monkey-patched/augmented D-Bus
buses."""

from __future__ import absolute_import

import dbus
from . import proxies
from . import constants

for name in ("Bus", "SystemBus", "SessionBus", "StarterBus"):
    exec(
        """def %(name)s(*args, **kwargs):
    busobj = dbus.%(name)s(*args, **kwargs)
    busobj.ProxyObjectClass = proxies.ProxyObject
    busobj.default_timeout = %(default_timeout)s
    return busobj
""" % {
        "name": name, "modname": __name__,
        "default_timeout": constants.method_call_no_timeout})
dbus/mainloop.py000064400000006443150501262210007672 0ustar00# -*- coding: utf-8 -*-

# slip.dbus.mainloop -- mainloop wrappers
#
# Copyright © 2009, 2012 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
# Nils Philippsen <nils@redhat.com>

"""This module contains mainloop wrappers.

Currently only glib main loops are supported."""

from __future__ import absolute_import

__all__ = ("MainLoop", "set_type")


class MainLoop(object):
    """An abstract main loop wrapper class and factory.

    Use MainLoop() to get a main loop wrapper object for a main loop type
    previously registered with set_type(). Defaults to glib main loops.

    Actual main loop wrapper classes are derived from this class."""

    __mainloop_class = None

    def __new__(cls, *args, **kwargs):
        global _mainloop_class
        if MainLoop._mainloop_class is None:
            MainLoop.set_type("glib")
        return super(MainLoop, cls).__new__(
            MainLoop.__mainloop_class, *args, **kwargs)

    @classmethod
    def set_type(cls, mltype):
        """Set a main loop type for non-blocking interfaces.

        mltype: "glib" (currently only glib main loops are supported)"""

        if MainLoop.__mainloop_class is not None:
            raise RuntimeError("The main loop type can only be set once.")

        ml_type_class = {"glib": GlibMainLoop}

        if mltype in ml_type_class:
            MainLoop.__mainloop_class = ml_type_class[mltype]
        else:
            raise ValueError(
                "'%s' is not one of the valid main loop types:\n%s" %
                (mltype, ", ".join(ml_type_class)))

    def pending(self):
        """Returns if there are pending events."""

        raise NotImplementedError()

    def iterate(self):
        """Iterates over one pending event."""

        raise NotImplementedError()

    def iterate_over_pending_events(self):
        """Iterates over all pending events."""

        while self.pending():
            self.iterate()

    def run(self):
        """Runs the main loop."""

        raise NotImplementedError()

    def quit(self):
        """Quits the main loop."""

        raise NotImplementedError()


class GlibMainLoop(MainLoop):

    def __init__(self):
        from .._wrappers import _glib
        ml = _glib.MainLoop()
        ctx = ml.get_context()

        self._mainloop = ml
        self.pending = ctx.pending
        self.iterate = ctx.iteration
        self.run = ml.run
        self.quit = ml.quit


def set_type(mltype):
    """Set a main loop type for non-blocking interfaces.

    mltype: "glib" (currently only glib main loops are supported)

    Deprecated, use MainLoop.set_type() instead."""

    from warnings import warn

    warn("use MainLoop.set_type() instead", DeprecationWarning)

    MainLoop.set_type(mltype)
dbus/constants.py000064400000002700150501262260010065 0ustar00# -*- coding: utf-8 -*-

# slip.dbus.constants -- constant values
#
# Copyright © 2011 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
# Nils Philippsen <nils@redhat.com>

"""This module contains some constant values."""

# The maximum value of a 32bit signed integer is the magic value to indicate an
# infinite timeout for dbus. Unlike the C interface which deals with
# milliseconds as integers, the python interface uses seconds as floats for the
# timeout. Therefore we need to use the Python float (C double) value that
# gives 0x7FFFFFFF if multiplied by 1000.0 and cast into an integer.
#
# This calculation should be precise enough to get a value of 0x7FFFFFFF on the
# C side. If not, it will still amount to a very long time (not quite 25 days)
# which should be enough for all intents and purposes.
method_call_no_timeout = 0x7FFFFFFF / 1000.0
dbus/service.py000064400000017640150501262330007520 0ustar00# -*- coding: utf-8 -*-

# slip.dbus.service -- convenience functions for using dbus-activated
# services
#
# Copyright © 2008, 2009, 2015 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
# Nils Philippsen <nils@redhat.com>

"This module contains convenience functions for using dbus-activated services."

from __future__ import absolute_import

import dbus
import dbus.service
from six import with_metaclass

from .._wrappers import _glib as GLib

from . import polkit

__all__ = ["Object", "InterfaceType", "set_mainloop"]

__mainloop__ = None


def __glib_quit_cb__():
    global __mainloop__

    # assume a Glib mainloop

    __mainloop__.quit()


__quit_cb__ = __glib_quit_cb__


def set_mainloop(mainloop):
    global __mainloop__
    __mainloop__ = mainloop


def set_quit_cb(quit_cb):
    global __quit_cb__
    __quit_cb__ = quit_cb


def quit_cb():
    global __quit_cb__
    __quit_cb__()


SENDER_KEYWORD = "__slip_dbus_service_sender__"
ASYNC_CALLBACKS = ("__slip_dbus_service_reply_cb__",
                   "__slip_dbus_service_error_cb__")


def wrap_method(method):
    global SENDER_KEYWORD
    global ASYNC_CALLBACKS

    if method._dbus_sender_keyword is not None:
        sender_keyword = method._dbus_sender_keyword
        hide_sender_keyword = False
    else:
        sender_keyword = SENDER_KEYWORD
        hide_sender_keyword = True

    if method._dbus_async_callbacks is not None:
        async_callbacks = method._dbus_async_callbacks
        method_is_async = True
    else:
        async_callbacks = ASYNC_CALLBACKS
        method_is_async = False
    hide_async_callbacks = not method_is_async

    def wrapped_method(self, *p, **k):
        sender = k.get(sender_keyword)
        if sender is not None:
            # i.e. called over the bus, not locally
            reply_cb = k[async_callbacks[0]]
            error_cb = k[async_callbacks[1]]

            if hide_sender_keyword:
                del k[sender_keyword]

            if hide_async_callbacks:
                del k[async_callbacks[0]]
                del k[async_callbacks[1]]

            self.sender_seen(sender)

        action_id = getattr(method, "_slip_polkit_auth_required",
                            getattr(self, "default_polkit_auth_required",
                                    None))

        if sender is not None and action_id:

            def reply_handler(is_auth):
                if is_auth:
                    if method_is_async:

                        # k contains async callbacks, simply pass on reply_cb
                        # and error_cb

                        method(self, *p, **k)
                    else:

                        # execute the synchronous method ...

                        error = None
                        try:
                            result = method(self, *p, **k)
                        except Exception as e:
                            error = e

                        # ... and call the reply or error callback

                        if error:
                            error_cb(error)
                        else:

                            # reply_cb((None,)) != reply_cb()

                            if result is None:
                                reply_cb()
                            else:
                                reply_cb(result)
                else:
                    error_cb(polkit.NotAuthorizedException(action_id))
                self.timeout_restart()

            def error_handler(error):
                error_cb(error)
                self.timeout_restart()

            polkit.IsSystemBusNameAuthorizedAsync(
                sender, action_id,
                reply_handler=reply_handler, error_handler=error_handler)
        else:
            # no action id, or run locally, no need to do anything fancy
            retval = method(self, *p, **k)
            self.timeout_restart()
            return retval

    for attr in (x for x in dir(method) if x[:6] == "_dbus_"):
        if attr == "_dbus_sender_keyword":
            wrapped_method._dbus_sender_keyword = sender_keyword
        elif attr == "_dbus_async_callbacks":
            wrapped_method._dbus_async_callbacks = async_callbacks
        else:
            setattr(wrapped_method, attr, getattr(method, attr))

        # delattr (method, attr)

    wrapped_method.__name__ = method.__name__

    return wrapped_method


class InterfaceType(dbus.service.InterfaceType):

    def __new__(cls, name, bases, dct):

        for (attrname, attr) in dct.items():
            if getattr(attr, "_dbus_is_method", False):
                dct[attrname] = wrap_method(attr)
        return super(InterfaceType, cls).__new__(cls, name, bases, dct)


class Object(with_metaclass(InterfaceType, dbus.service.Object)):

    # timeout & persistence

    persistent = False
    default_duration = 5
    duration = default_duration
    current_source = None
    senders = set()
    connections_senders = {}
    connections_smobjs = {}

    # PolicyKit

    default_polkit_auth_required = None

    def __init__(
        self, conn=None, object_path=None, bus_name=None, persistent=None):

        super(Object, self).__init__(conn, object_path, bus_name)
        if persistent is None:
            self.persistent = self.__class__.persistent
        else:
            self.persistent = persistent

    def _timeout_cb(self):
        if not self.persistent and len(Object.senders) == 0:
            quit_cb()
            return False

        Object.current_source = None
        Object.duration = self.default_duration

        return False

    def _name_owner_changed(self, name, old_owner, new_owner):

        conn = self.connection

        if not new_owner and (old_owner, conn) in Object.senders:
            Object.senders.remove((old_owner, conn))
            Object.connections_senders[conn].remove(old_owner)

            if len(Object.connections_senders[conn]) == 0:
                Object.connections_smobjs[conn].remove()
                del Object.connections_senders[conn]
                del Object.connections_smobjs[conn]

            if not self.persistent and len(Object.senders) == 0 and \
                    Object.current_source is None:
                quit_cb()

    def timeout_restart(self, duration=None):
        if not duration:
            duration = self.__class__.default_duration
        if not Object.duration or duration > Object.duration:
            Object.duration = duration
        if not self.persistent or len(Object.senders) == 0:
            if Object.current_source:
                GLib.source_remove(Object.current_source)
            Object.current_source = \
                GLib.timeout_add(Object.duration * 1000,
                                    self._timeout_cb)

    def sender_seen(self, sender):
        if (sender, self.connection) not in Object.senders:
            Object.senders.add((sender, self.connection))
            if self.connection not in Object.connections_senders:
                Object.connections_senders[self.connection] = set()
                Object.connections_smobjs[self.connection] = \
                    self.connection.add_signal_receiver(
                        handler_function=self._name_owner_changed,
                        signal_name='NameOwnerChanged',
                        dbus_interface='org.freedesktop.DBus',
                        arg1=sender)
            Object.connections_senders[self.connection].add(sender)
__pycache__/__init__.cpython-36.pyc000064400000000161150501262400013132 0ustar003

�uAc�@sdS)N�rrr�/usr/lib/python3.6/__init__.py�<module>s__pycache__/__init__.cpython-36.opt-1.pyc000064400000000161150501262450014076 0ustar003

�uAc�@sdS)N�rrr�/usr/lib/python3.6/__init__.py�<module>sutil/__init__.py000064400000000154150501262450007632 0ustar00# -*- coding: utf-8 -*-

from __future__ import absolute_import

from . import hookable
from . import files
util/__pycache__/hookable.cpython-36.pyc000064400000013577150501262520014156 0ustar003

�uAc^�@sldZddlZddlmZddgZGdd�de�ZGdd	�d	e�ZGd
d�deee��Z	Gdd�de
e	�ZdS)z[This module contains variants of certain base types which call registered
hooks on changes.�N)�with_metaclass�Hookable�HookableSetc@s eZdZdd�Zedd��ZdS)�HookableTypec
Cs�d|kr�y|d}WnJtk
r^d}x0dd�|D�D]}|rRtdt|���q8|}q8WYnXx |dD]}tj||�||<qjWtj||||�S)N�_hookable_change_methodsZ_hookable_base_classcss|]}|tkr|VqdS)N)r)�.0�x�r	�/usr/lib/python3.6/hookable.py�	<genexpr>)sz'HookableType.__new__.<locals>.<genexpr>ztoo many base classes: %s)�KeyError�	TypeError�strr�wrap_method�type�__new__)�cls�name�basesZdct�baseZbase_candidate�
methodnamer	r	r
r"szHookableType.__new__cs t||���fdd�}||_|S)Ncs�|f|�|�}|j�|S)N)�
_run_hooks)�self�p�kZretval)�funcr	r
�
methodwrapper9sz/HookableType.wrap_method.<locals>.methodwrapper)�getattr�__name__)rrrrr	)rr
r5s
zHookableType.wrap_methodN)r�
__module__�__qualname__r�classmethodrr	r	r	r
r src@s6eZdZddd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�
_HookEntryNcCs�t|tj�st�t|t�st�xFt|�D]:\}}yt|�Wq(tk
r`td||f��Yq(Xq(WxF|j�D]:\}}yt|�Wqptk
r�td||f��YqpXqpWt|t	�s�t	|�}||_
||_||_||_
d|_dS)Nz*Positional argument %d is not hashable: %rz'Keyword argument %r is not hashable: %r)�
isinstance�collections�Callable�AssertionErrorr�	enumerate�hashr
�items�tuple�_HookEntry__hook�_HookEntry__args�_HookEntry__kwargs�_HookEntry__hookable�_HookEntry__hash)r�hook�args�kwargs�hookable�nrrr	r	r
�__init__Ds.
z_HookEntry.__init__cCs$|j|jko"|j|jko"|j|jkS)N)r+r,r-)r�objr	r	r
�__cmp__csz_HookEntry.__cmp__cCs|js|j�|_|jS)N)r/�
_compute_hash)rr	r	r
�__hash__is
z_HookEntry.__hash__cCs>t|j�}t|�t|j�A}t|�ttt|jj����A}|S)N)r(r+r,r*�sortedr-r))r�	hashvaluer	r	r
r8ns

z_HookEntry._compute_hashcCs4|jr |j|jf|j�|j�n|j|j|j�dS)N)r.r+r,r-)rr	r	r
�runusz_HookEntry.run)N)rrr r5r7r9r8r<r	r	r	r
r"Bs

r"c@s�eZdZdZedd��Zdd�Zdd�Zeee�Zdd	�Z	d
d�Z
ee	e
�Zdd
�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�ZdS)rz2An object which calls registered hooks on changes.cOst|d�st�|_|jS)N�__real_hooks__)�hasattr�setr=)rrrr	r	r
�	__hooks__�s
zHookable.__hooks__cCst|d�sd|_|jS)N�__hooks_enabled__T)r>rA)rr	r	r
�_get_hooks_enabled�s
zHookable._get_hooks_enabledcCs
||_dS)N)rA)rZenabledr	r	r
�_set_hooks_enabled�szHookable._set_hooks_enabledcCst|d�sd|_|jS)N�__hooks_frozen__F)r>rD)rr	r	r
�_get_hooks_frozen�s
zHookable._get_hooks_frozencCsB||jkrdS||_|r"t�|_nx|jD]}|j�q*W|`dS)N)�hooks_frozenrDr?�__hooks_frozen_entries__r<)rZfreeze�	hookentryr	r	r
�_set_hooks_frozen�s

zHookable._set_hooks_frozencCs
d|_dS)NT)rF)rr	r	r
�freeze_hooks�szHookable.freeze_hookscCs
d|_dS)NF)rF)rr	r	r
�
thaw_hooks�szHookable.thaw_hookscOs|j|df|�|�dS)N)�_Hookable__add_hook)rr0r1r2r	r	r
�add_hook�szHookable.add_hookcOs|j||f|�|�dS)N)rL)rr0r1r2r	r	r
�add_hook_hookable�szHookable.add_hook_hookablecOs>t|tj�st�t|t�st�t||||d�}|jj|�dS)N)r3)r#r$r%r&rr"r@�add)rr0Z	_hookabler1r2rHr	r	r
Z
__add_hook�szHookable.__add_hookcOs|jjt|||��dS)N)r@�remover")rr0r1r2r	r	r
�remove_hook�szHookable.remove_hookcCs8|jr4|js&x&|jD]}|j�qWn|jj|j�dS)N)�
hooks_enabledrFr@r<rG�update)rrHr	r	r
r�s
zHookable._run_hooksN)rrr �__doc__�propertyr@rBrCrRrErIrFrJrKrMrNrLrQrr	r	r	r
r|s

c	@seZdZdZdZdd�Zd
S)rz5A set object which calls registered hooks on changes.rO�clear�difference_update�discard�intersection_update�poprP�symmetric_difference_updaterScCstj|�}t�|_|S)N)r?�copyr=)rr6r	r	r
r\�s
zHookableSet.copyN)	rOrVrWrXrYrZrPr[rS)rrr rTrr\r	r	r	r
r�s)rTr$Zsixr�__all__rr�objectr"rr?rr	r	r	r
�<module>s":Gutil/__pycache__/hookable.cpython-36.opt-1.pyc000064400000013376150501262570015117 0ustar003

�uAc^�@sldZddlZddlmZddgZGdd�de�ZGdd	�d	e�ZGd
d�deee��Z	Gdd�de
e	�ZdS)z[This module contains variants of certain base types which call registered
hooks on changes.�N)�with_metaclass�Hookable�HookableSetc@s eZdZdd�Zedd��ZdS)�HookableTypec
Cs�d|kr�y|d}WnJtk
r^d}x0dd�|D�D]}|rRtdt|���q8|}q8WYnXx |dD]}tj||�||<qjWtj||||�S)N�_hookable_change_methodsZ_hookable_base_classcss|]}|tkr|VqdS)N)r)�.0�x�r	�/usr/lib/python3.6/hookable.py�	<genexpr>)sz'HookableType.__new__.<locals>.<genexpr>ztoo many base classes: %s)�KeyError�	TypeError�strr�wrap_method�type�__new__)�cls�name�basesZdct�baseZbase_candidate�
methodnamer	r	r
r"szHookableType.__new__cs t||���fdd�}||_|S)Ncs�|f|�|�}|j�|S)N)�
_run_hooks)�self�p�kZretval)�funcr	r
�
methodwrapper9sz/HookableType.wrap_method.<locals>.methodwrapper)�getattr�__name__)rrrrr	)rr
r5s
zHookableType.wrap_methodN)r�
__module__�__qualname__r�classmethodrr	r	r	r
r src@s6eZdZddd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�
_HookEntryNcCs�xFt|�D]:\}}yt|�Wq
tk
rBtd||f��Yq
Xq
WxF|j�D]:\}}yt|�WqRtk
r�td||f��YqRXqRWt|t�s�t|�}||_||_||_||_	d|_
dS)Nz*Positional argument %d is not hashable: %rz'Keyword argument %r is not hashable: %r)�	enumerate�hashr
�items�
isinstance�tuple�_HookEntry__hook�_HookEntry__args�_HookEntry__kwargs�_HookEntry__hookable�_HookEntry__hash)r�hook�args�kwargs�hookable�nrrr	r	r
�__init__Ds*
z_HookEntry.__init__cCs$|j|jko"|j|jko"|j|jkS)N)r(r)r*)r�objr	r	r
�__cmp__csz_HookEntry.__cmp__cCs|js|j�|_|jS)N)r,�
_compute_hash)rr	r	r
�__hash__is
z_HookEntry.__hash__cCs>t|j�}t|�t|j�A}t|�ttt|jj����A}|S)N)r$r(r)r'�sortedr*r%)r�	hashvaluer	r	r
r5ns

z_HookEntry._compute_hashcCs4|jr |j|jf|j�|j�n|j|j|j�dS)N)r+r(r)r*)rr	r	r
�runusz_HookEntry.run)N)rrr r2r4r6r5r9r	r	r	r
r"Bs

r"c@s�eZdZdZedd��Zdd�Zdd�Zeee�Zdd	�Z	d
d�Z
ee	e
�Zdd
�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�ZdS)rz2An object which calls registered hooks on changes.cOst|d�st�|_|jS)N�__real_hooks__)�hasattr�setr:)rrrr	r	r
�	__hooks__�s
zHookable.__hooks__cCst|d�sd|_|jS)N�__hooks_enabled__T)r;r>)rr	r	r
�_get_hooks_enabled�s
zHookable._get_hooks_enabledcCs
||_dS)N)r>)rZenabledr	r	r
�_set_hooks_enabled�szHookable._set_hooks_enabledcCst|d�sd|_|jS)N�__hooks_frozen__F)r;rA)rr	r	r
�_get_hooks_frozen�s
zHookable._get_hooks_frozencCsB||jkrdS||_|r"t�|_nx|jD]}|j�q*W|`dS)N)�hooks_frozenrAr<�__hooks_frozen_entries__r9)rZfreeze�	hookentryr	r	r
�_set_hooks_frozen�s

zHookable._set_hooks_frozencCs
d|_dS)NT)rC)rr	r	r
�freeze_hooks�szHookable.freeze_hookscCs
d|_dS)NF)rC)rr	r	r
�
thaw_hooks�szHookable.thaw_hookscOs|j|df|�|�dS)N)�_Hookable__add_hook)rr-r.r/r	r	r
�add_hook�szHookable.add_hookcOs|j||f|�|�dS)N)rI)rr-r.r/r	r	r
�add_hook_hookable�szHookable.add_hook_hookablecOs t||||d�}|jj|�dS)N)r0)r"r=�add)rr-Z	_hookabler.r/rEr	r	r
Z
__add_hook�szHookable.__add_hookcOs|jjt|||��dS)N)r=�remover")rr-r.r/r	r	r
�remove_hook�szHookable.remove_hookcCs8|jr4|js&x&|jD]}|j�qWn|jj|j�dS)N)�
hooks_enabledrCr=r9rD�update)rrEr	r	r
r�s
zHookable._run_hooksN)rrr �__doc__�propertyr=r?r@rOrBrFrCrGrHrJrKrIrNrr	r	r	r
r|s

c	@seZdZdZdZdd�Zd
S)rz5A set object which calls registered hooks on changes.rL�clear�difference_update�discard�intersection_update�poprM�symmetric_difference_updaterPcCstj|�}t�|_|S)N)r<�copyr:)rr3r	r	r
rY�s
zHookableSet.copyN)	rLrSrTrUrVrWrMrXrP)rrr rQrrYr	r	r	r
r�s)rQ�collectionsZsixr�__all__rr�objectr"rr<rr	r	r	r
�<module>s":Gutil/__pycache__/files.cpython-36.pyc000064400000011525150501262640013466 0ustar003

�uAc��@s�dZddlmZdee�kr eZdddddgZdd	lZdd	l	Z	dd	l
Z
dd	lZdd	lZd
Z
dd�Zgfd
d�Zdd�Zddd�Zddd�Zddd�Zddd�Zd	S)z=This module contains helper functions for dealing with files.�)�absolute_import�xrange�
issamefile�linkfile�copyfile�linkorcopyfile�overwrite_safelyNicCs"tj|�}tj|�}tjj||�S)N)�os�stat�path�samestat)�path1�path2�s1�s2�r�/usr/lib/python3.6/files.py�_issamefile+s

rcCs0|dkrt}y
t||�S|k
r*dSXdS)zECheck whether two paths point to the same file (i.e. are hardlinked).TFN)�	Exceptionr)r
r�catch_stat_exceptionsrrrr2s
cCs�t||td�rdStjj|�}tjj|�}tjj|�}d}xpttj	�D]b}tj
|tj|d�}ytj||�Wn2tk
r�}z|j
t
jkr�n�WYdd}~XqFXd}PqFW|r�tj||�dS)zUHardlink srcpath to dstpath.

    Attempt to atomically replace dstpath if it exists.)rNF)�prefix�dirT)r�OSErrorr	r�abspath�dirname�basename�range�tempfile�TMP_MAX�mktemp�extsep�link�errno�EEXIST�rename)�srcpath�dstpath�dstdname�dstbnameZ
hardlinked�attempt�_dsttmp�errrr>s$Tc
Cs8t||td�rdStjj|�}tjj|�}tjj|�}t|d�}tj	|tjj
|dd�}tj|�}|r�ytj|�}Wntk
r�YnXtj|j
�tj|j��d}	xP|	dkr�|jt�}	y|j|	�Wq�|j�|j�tj|j��Yq�Xq�W|j�|j�tj|j|�|�r4tj�dk�r4tj|�dS)z�Copy srcpath to dstpath.

    Abort operation if e.g. not enough space is available.  Attempt to
    atomically replace dstpath if it exists.)rN�rbF)rr�delete�r)rrr	rrrr�openrZNamedTemporaryFiler r
�fchmod�fileno�S_IMODE�st_mode�read�	BLOCKSIZE�write�close�unlink�namer$�selinux�is_selinux_enabled�
restorecon)
r%r&�copy_mode_from_dst�run_restoreconr'r(ZsrcfileZ
dsttmpfile�s�datarrrr_s<



cCs^yt||�dStk
rJ}z |jtjtjtjfkr:�nWYdd}~XnXt||||�dS)ztFirst attempt to hardlink srcpath to dstpath, if hardlinking isn't
    possible, attempt copying srcpath to dstpath.N)rrr"ZEMLINKZEPERMZEXDEVr)r%r&r=r>r+rrrr�s
Fc
Cs�tjj|�}tjj|�}d}d}|r6tj�dkr6d}n^y&tj|�\}}|dkrZtd|��Wn6tk
r�}	z|	j	t	j
kr�d}n�WYdd}	~	XnX|s�tj||�|r�tj|�n�d}
xtt
tj�D]f}tj|tj|d�}ytj||�Wn6tk
�r"}	z|	j	t	jk�rwĂWYdd}	~	Xq�X|}
Pq�W|
dk�rDtt	jd��|�r^|�r^tj|
|�ytj|
|�Wntj|
��YnX|�r�tj|�dS)zpCreate a symlink, optionally replacing dstpath atomically, optionally
    setting or preserving SELinux context.FNrzgetfilecon(%r) failedT)rrz/No suitable temporary symlink could be created.)r	rrrr:r;Zlgetfilecon�RuntimeErrorrr"�ENOENT�symlinkr<rrrrr r#�IOErrorZlsetfileconr$�remove)
r%r&�force�preserve_contextr'r(r>�ctx�retr+Zdsttmpr)r*rrr�symlink_atomically�sV

rJcCs~tjj|�}tjj|�}tjj|�}d}d}d}	tjj|�}
|rPtj�dkrPd}z�tj	|tjj
|d�\}}	|
r�tj|�}|r�tj||j
|j�|r�tj|tj|j��|r�tj|�\}}
|dkr�td|��tj|d�}d}|j|�|j�d}tj|	|�|�r$|
�rtj||
�n
tj|�Wd|�r8|j�n|�rHtj|�|	�rxtjj|	��rxytj|	�WnYnXXdS)z�Safely overwrite a file by creating a temporary file in the same
    directory, writing it, moving it over the original file, eventually
    preserving file mode, SELinux context and ownership.NrF)rrzgetfilecon(%r) failed�w)r	r�realpathrr�existsr:r;rZmkstempr r
�fchown�st_uid�st_gidr0r2r3Z
getfileconrA�fdopenr6r7r$Z
setfileconr<�isfiler8)rZcontentZ
preserve_moderGZpreserve_ownershipZdir_�base�fd�fZtmpnamerMr?rIrHrrrr�sR



)TT)TT)FT)TTT)�__doc__Z
__future__rr�__builtins__rr�__all__r	r:rr"r
r5rrrrrrJrrrrr�<module>s&!
5

?util/__pycache__/files.cpython-36.opt-1.pyc000064400000011525150501262720014424 0ustar003

�uAc��@s�dZddlmZdee�kr eZdddddgZdd	lZdd	l	Z	dd	l
Z
dd	lZdd	lZd
Z
dd�Zgfd
d�Zdd�Zddd�Zddd�Zddd�Zddd�Zd	S)z=This module contains helper functions for dealing with files.�)�absolute_import�xrange�
issamefile�linkfile�copyfile�linkorcopyfile�overwrite_safelyNicCs"tj|�}tj|�}tjj||�S)N)�os�stat�path�samestat)�path1�path2�s1�s2�r�/usr/lib/python3.6/files.py�_issamefile+s

rcCs0|dkrt}y
t||�S|k
r*dSXdS)zECheck whether two paths point to the same file (i.e. are hardlinked).TFN)�	Exceptionr)r
r�catch_stat_exceptionsrrrr2s
cCs�t||td�rdStjj|�}tjj|�}tjj|�}d}xpttj	�D]b}tj
|tj|d�}ytj||�Wn2tk
r�}z|j
t
jkr�n�WYdd}~XqFXd}PqFW|r�tj||�dS)zUHardlink srcpath to dstpath.

    Attempt to atomically replace dstpath if it exists.)rNF)�prefix�dirT)r�OSErrorr	r�abspath�dirname�basename�range�tempfile�TMP_MAX�mktemp�extsep�link�errno�EEXIST�rename)�srcpath�dstpath�dstdname�dstbnameZ
hardlinked�attempt�_dsttmp�errrr>s$Tc
Cs8t||td�rdStjj|�}tjj|�}tjj|�}t|d�}tj	|tjj
|dd�}tj|�}|r�ytj|�}Wntk
r�YnXtj|j
�tj|j��d}	xP|	dkr�|jt�}	y|j|	�Wq�|j�|j�tj|j��Yq�Xq�W|j�|j�tj|j|�|�r4tj�dk�r4tj|�dS)z�Copy srcpath to dstpath.

    Abort operation if e.g. not enough space is available.  Attempt to
    atomically replace dstpath if it exists.)rN�rbF)rr�delete�r)rrr	rrrr�openrZNamedTemporaryFiler r
�fchmod�fileno�S_IMODE�st_mode�read�	BLOCKSIZE�write�close�unlink�namer$�selinux�is_selinux_enabled�
restorecon)
r%r&�copy_mode_from_dst�run_restoreconr'r(ZsrcfileZ
dsttmpfile�s�datarrrr_s<



cCs^yt||�dStk
rJ}z |jtjtjtjfkr:�nWYdd}~XnXt||||�dS)ztFirst attempt to hardlink srcpath to dstpath, if hardlinking isn't
    possible, attempt copying srcpath to dstpath.N)rrr"ZEMLINKZEPERMZEXDEVr)r%r&r=r>r+rrrr�s
Fc
Cs�tjj|�}tjj|�}d}d}|r6tj�dkr6d}n^y&tj|�\}}|dkrZtd|��Wn6tk
r�}	z|	j	t	j
kr�d}n�WYdd}	~	XnX|s�tj||�|r�tj|�n�d}
xtt
tj�D]f}tj|tj|d�}ytj||�Wn6tk
�r"}	z|	j	t	jk�rwĂWYdd}	~	Xq�X|}
Pq�W|
dk�rDtt	jd��|�r^|�r^tj|
|�ytj|
|�Wntj|
��YnX|�r�tj|�dS)zpCreate a symlink, optionally replacing dstpath atomically, optionally
    setting or preserving SELinux context.FNrzgetfilecon(%r) failedT)rrz/No suitable temporary symlink could be created.)r	rrrr:r;Zlgetfilecon�RuntimeErrorrr"�ENOENT�symlinkr<rrrrr r#�IOErrorZlsetfileconr$�remove)
r%r&�force�preserve_contextr'r(r>�ctx�retr+Zdsttmpr)r*rrr�symlink_atomically�sV

rJcCs~tjj|�}tjj|�}tjj|�}d}d}d}	tjj|�}
|rPtj�dkrPd}z�tj	|tjj
|d�\}}	|
r�tj|�}|r�tj||j
|j�|r�tj|tj|j��|r�tj|�\}}
|dkr�td|��tj|d�}d}|j|�|j�d}tj|	|�|�r$|
�rtj||
�n
tj|�Wd|�r8|j�n|�rHtj|�|	�rxtjj|	��rxytj|	�WnYnXXdS)z�Safely overwrite a file by creating a temporary file in the same
    directory, writing it, moving it over the original file, eventually
    preserving file mode, SELinux context and ownership.NrF)rrzgetfilecon(%r) failed�w)r	r�realpathrr�existsr:r;rZmkstempr r
�fchown�st_uid�st_gidr0r2r3Z
getfileconrA�fdopenr6r7r$Z
setfileconr<�isfiler8)rZcontentZ
preserve_moderGZpreserve_ownershipZdir_�base�fd�fZtmpnamerMr?rIrHrrrr�sR



)TT)TT)FT)TTT)�__doc__Z
__future__rr�__builtins__rr�__all__r	r:rr"r
r5rrrrrrJrrrrr�<module>s&!
5

?util/__pycache__/__init__.cpython-36.pyc000064400000000345150501262770014125 0ustar003

�uAcl�@s(ddlmZddlmZddlmZdS)�)�absolute_import�)�hookable)�filesN)Z
__future__r�rr�rr�/usr/lib/python3.6/__init__.py�<module>sutil/__pycache__/__init__.cpython-36.opt-1.pyc000064400000000345150501263040015053 0ustar003

�uAcl�@s(ddlmZddlmZddlmZdS)�)�absolute_import�)�hookable)�filesN)Z
__future__r�rr�rr�/usr/lib/python3.6/__init__.py�<module>sutil/hookable.py000064400000014136150501263110007656 0ustar00# -*- coding: utf-8 -*-

# slip.util.hookable -- run hooks on changes in objects
#
# Copyright © 2008 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
# Nils Philippsen <nils@redhat.com>

"""This module contains variants of certain base types which call registered
hooks on changes."""

import collections
from six import with_metaclass

__all__ = ["Hookable", "HookableSet"]


class HookableType(type):

    def __new__(cls, name, bases, dct):

        if '_hookable_change_methods' in dct:
            try:
                base = dct["_hookable_base_class"]
            except KeyError:
                base = None
                for base_candidate in (x for x in bases if x != Hookable):
                    if base:
                        raise TypeError(
                            "too many base classes: %s" % str(bases))
                    else:
                        base = base_candidate

            for methodname in dct["_hookable_change_methods"]:
                dct[methodname] = HookableType.wrap_method(base, methodname)

        return type.__new__(cls, name, bases, dct)

    @classmethod
    def wrap_method(cls, base, methodname):
        func = getattr(base, methodname)

        def methodwrapper(self, *p, **k):
            retval = func(self, *p, **k)
            self._run_hooks()
            return retval

        methodwrapper.__name__ = methodname
        return methodwrapper


class _HookEntry(object):

    def __init__(self, hook, args, kwargs, hookable=None):

        assert(isinstance(hook, collections.Callable))
        assert(isinstance(hookable, Hookable))

        for n, x in enumerate(args):
            try:
                hash(x)
            except TypeError:
                raise TypeError(
                        "Positional argument %d is not hashable: %r" %
                        (n, x))

        for k, x in kwargs.items():
            try:
                hash(x)
            except TypeError:
                raise TypeError(
                        "Keyword argument %r is not hashable: %r" %
                        (k, x))

        if not isinstance(args, tuple):
            args = tuple(args)

        self.__hook = hook
        self.__args = args
        self.__kwargs = kwargs
        self.__hookable = hookable

        self.__hash = None

    def __cmp__(self, obj):
        return (
            self.__hook == obj.__hook and
            self.__args == obj.__args and
            self.__kwargs == obj.__kwargs)

    def __hash__(self):
        if not self.__hash:
            self.__hash = self._compute_hash()
        return self.__hash

    def _compute_hash(self):
        hashvalue = hash(self.__hook)
        hashvalue = hash(hashvalue) ^ hash(self.__args)
        hashvalue = hash(hashvalue) ^ hash(
                tuple(sorted(self.__kwargs.items())))
        return hashvalue

    def run(self):
        if self.__hookable:
            self.__hook(self.__hookable, *self.__args, **self.__kwargs)
        else:
            self.__hook(*self.__args, **self.__kwargs)


class Hookable(with_metaclass(HookableType, object)):

    """An object which calls registered hooks on changes."""

    @property
    def __hooks__(self, *p, **k):
        if not hasattr(self, "__real_hooks__"):
            self.__real_hooks__ = set()
        return self.__real_hooks__

    def _get_hooks_enabled(self):
        if not hasattr(self, "__hooks_enabled__"):
            self.__hooks_enabled__ = True
        return self.__hooks_enabled__

    def _set_hooks_enabled(self, enabled):
        self.__hooks_enabled__ = enabled

    hooks_enabled = property(_get_hooks_enabled, _set_hooks_enabled)

    def _get_hooks_frozen(self):
        if not hasattr(self, "__hooks_frozen__"):
            self.__hooks_frozen__ = False
        return self.__hooks_frozen__

    def _set_hooks_frozen(self, freeze):
        if freeze == self.hooks_frozen:
            return

        self.__hooks_frozen__ = freeze

        if freeze:
            self.__hooks_frozen_entries__ = set()
        else:
            for hookentry in self.__hooks_frozen_entries__:
                hookentry.run()
            del self.__hooks_frozen_entries__

    hooks_frozen = property(_get_hooks_frozen, _set_hooks_frozen)

    def freeze_hooks(self):
        self.hooks_frozen = True

    def thaw_hooks(self):
        self.hooks_frozen = False

    def add_hook(self, hook, *args, **kwargs):
        self.__add_hook(hook, None, *args, **kwargs)

    def add_hook_hookable(self, hook, *args, **kwargs):
        self.__add_hook(hook, self, *args, **kwargs)

    def __add_hook(self, hook, _hookable, *args, **kwargs):
        assert isinstance(hook, collections.Callable)
        assert isinstance(_hookable, Hookable)
        hookentry = _HookEntry(hook, args, kwargs, hookable=_hookable)
        self.__hooks__.add(hookentry)

    def remove_hook(self, hook, *args, **kwargs):

        self.__hooks__.remove(_HookEntry(hook, args, kwargs))

    def _run_hooks(self):
        if self.hooks_enabled:
            if not self.hooks_frozen:
                for hookentry in self.__hooks__:
                    hookentry.run()
            else:
                self.__hooks_frozen_entries__.update(self.__hooks__)


class HookableSet(set, Hookable):

    """A set object which calls registered hooks on changes."""

    _hookable_change_methods = (
        "add", "clear", "difference_update", "discard", "intersection_update",
        "pop", "remove", "symmetric_difference_update", "update")

    def copy(self):
        obj = set.copy(self)
        obj.__real_hooks__ = set()
        return obj
util/files.py000064400000017257150501263160007210 0ustar00# -*- coding: utf-8 -*-

# slip.util.files -- file helper functions
#
# Copyright © 2009, 2010, 2012, 2015 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
# Nils Philippsen <nils@redhat.com>

"""This module contains helper functions for dealing with files."""

from __future__ import absolute_import

# ensure range() returns a generator
if 'xrange' in dir(__builtins__):
    range = xrange

__all__ = ["issamefile", "linkfile", "copyfile", "linkorcopyfile",
           "overwrite_safely"]

import os
import selinux
import tempfile
import errno
import stat

BLOCKSIZE = 1024


def _issamefile(path1, path2):
    s1 = os.stat(path1)
    s2 = os.stat(path2)

    return os.path.samestat(s1, s2)


def issamefile(path1, path2, catch_stat_exceptions=[]):
    """Check whether two paths point to the same file (i.e. are hardlinked)."""

    if catch_stat_exceptions is True:
        catch_stat_exceptions = Exception

    try:
        return _issamefile(path1, path2)
    except catch_stat_exceptions:
        return False


def linkfile(srcpath, dstpath):
    """Hardlink srcpath to dstpath.

    Attempt to atomically replace dstpath if it exists."""

    if issamefile(srcpath, dstpath, catch_stat_exceptions=OSError):
        return

    dstpath = os.path.abspath(dstpath)
    dstdname = os.path.dirname(dstpath)
    dstbname = os.path.basename(dstpath)

    hardlinked = False
    for attempt in range(tempfile.TMP_MAX):
        _dsttmp = tempfile.mktemp(prefix=dstbname + os.extsep, dir=dstdname)
        try:
            os.link(srcpath, _dsttmp)
        except OSError as e:
            if e.errno == errno.EEXIST:

                # try another name

                pass
            else:
                raise
        else:
            hardlinked = True
            break

    if hardlinked:
        os.rename(_dsttmp, dstpath)


def copyfile(srcpath, dstpath, copy_mode_from_dst=True, run_restorecon=True):
    """Copy srcpath to dstpath.

    Abort operation if e.g. not enough space is available.  Attempt to
    atomically replace dstpath if it exists."""

    if issamefile(srcpath, dstpath, catch_stat_exceptions=OSError):
        return

    dstpath = os.path.abspath(dstpath)
    dstdname = os.path.dirname(dstpath)
    dstbname = os.path.basename(dstpath)

    srcfile = open(srcpath, "rb")
    dsttmpfile = tempfile.NamedTemporaryFile(
        prefix=dstbname + os.path.extsep, dir=dstdname, delete=False)

    s = os.stat(srcpath)

    if copy_mode_from_dst:

        # attempt to copy mode from destination file (if it exists,
        # otherwise fall back to copying it from the source file below)

        try:
            s = os.stat(dstpath)
        except OSError:
            pass

    os.fchmod(dsttmpfile.fileno(), stat.S_IMODE(s.st_mode))

    data = None

    while data != "":
        data = srcfile.read(BLOCKSIZE)
        try:
            dsttmpfile.write(data)
        except:
            srcfile.close()
            dsttmpfile.close()
            os.unlink(dsttmpfile.name)
            raise

    srcfile.close()
    dsttmpfile.close()

    os.rename(dsttmpfile.name, dstpath)

    if run_restorecon and selinux.is_selinux_enabled() > 0:
        selinux.restorecon(dstpath)


def linkorcopyfile(
    srcpath, dstpath, copy_mode_from_dst=True, run_restorecon=True):

    """First attempt to hardlink srcpath to dstpath, if hardlinking isn't
    possible, attempt copying srcpath to dstpath."""

    try:
        linkfile(srcpath, dstpath)
        return
    except OSError as e:
        if e.errno not in (errno.EMLINK, errno.EPERM, errno.EXDEV):

            # don't bother copying

            raise
        else:

            # try copying

            pass

    copyfile(srcpath, dstpath, copy_mode_from_dst, run_restorecon)


def symlink_atomically(srcpath, dstpath, force=False, preserve_context=True):
    """Create a symlink, optionally replacing dstpath atomically, optionally
    setting or preserving SELinux context."""

    dstdname = os.path.dirname(dstpath)
    dstbname = os.path.basename(dstpath)

    run_restorecon = False
    ctx = None

    if preserve_context and selinux.is_selinux_enabled() <= 0:
        preserve_context = False
    else:
        try:
            ret, ctx = selinux.lgetfilecon(dstpath)
            if ret < 0:
                raise RuntimeError("getfilecon(%r) failed" % dstpath)
        except OSError as e:
            if e.errno == errno.ENOENT:
                run_restorecon = True
            else:
                raise

    if not force:
        os.symlink(srcpath, dstpath)
        if preserve_context:
            selinux.restorecon(dstpath)
    else:
        dsttmp = None
        for attempt in range(tempfile.TMP_MAX):
            _dsttmp = tempfile.mktemp(
                prefix=dstbname + os.extsep, dir=dstdname)
            try:
                os.symlink(srcpath, _dsttmp)
            except OSError as e:
                if e.errno == errno.EEXIST:
                    # try again
                    continue
                raise
            else:
                dsttmp = _dsttmp
                break

        if dsttmp is None:
            raise IOError(
                errno.EEXIST,
                "No suitable temporary symlink could be created.")

        if preserve_context and not run_restorecon:
            selinux.lsetfilecon(dsttmp, ctx)

        try:
            os.rename(dsttmp, dstpath)
        except:
            # clean up
            os.remove(dsttmp)
            raise

        if run_restorecon:
            selinux.restorecon(dstpath)


def overwrite_safely(
        path, content, preserve_mode=True, preserve_context=True,
        preserve_ownership=True):
    """Safely overwrite a file by creating a temporary file in the same
    directory, writing it, moving it over the original file, eventually
    preserving file mode, SELinux context and ownership."""

    path = os.path.realpath(path)
    dir_ = os.path.dirname(path)
    base = os.path.basename(path)

    fd = None
    f = None
    tmpname = None

    exists = os.path.exists(path)

    if preserve_context and selinux.is_selinux_enabled() <= 0:
        preserve_context = False

    try:
        fd, tmpname = tempfile.mkstemp(prefix=base + os.path.extsep,
                                       dir=dir_)

        if exists:
            s = os.stat(path)

            if preserve_ownership:
                os.fchown(fd, s.st_uid, s.st_gid)

            if preserve_mode:
                os.fchmod(fd, stat.S_IMODE(s.st_mode))

            if preserve_context:
                ret, ctx = selinux.getfilecon(path)
                if ret < 0:
                    raise RuntimeError("getfilecon(%r) failed" % path)

        f = os.fdopen(fd, "w")
        fd = None

        f.write(content)

        f.close()
        f = None

        os.rename(tmpname, path)

        if preserve_context:
            if exists:
                selinux.setfilecon(path, ctx)
            else:
                selinux.restorecon(path)

    finally:
        if f:
            f.close()
        elif fd:
            os.close(fd)
        if tmpname and os.path.isfile(tmpname):
            try:
                os.unlink(tmpname)
            except:
                pass
_wrappers/__init__.py000064400000000000150501263230010642 0ustar00_wrappers/__pycache__/_glib.cpython-36.pyc000064400000001250150501263230014453 0ustar003

�uAc\�@s�dZddlmZddlZdddgZejeZdZxhedkr�dejkrPejdZndejkrdejdZedkr2yddl	Z	Wq2e
k
r�ddlZYq2Xq2Wx*eD]"Z
e
ee�kr�eee
eee
��q�WdS)	zjThis module lets some other slip modules cooperate with either the glib
or the gi.repository.GLib modules.�)�absolute_importNZMainLoopZ
source_removeZtimeout_addzgi.repository.GLib�glib)�__doc__Z
__future__r�sys�__all__�modules�__name__�_selfZ_modr�ImportErrorZgi.repository.GLibZgiZwhat�dir�setattr�getattr�rr�/usr/lib/python3.6/_glib.py�<module>s$






_wrappers/__pycache__/_glib.cpython-36.opt-1.pyc000064400000001250150501263300015410 0ustar003

�uAc\�@s�dZddlmZddlZdddgZejeZdZxhedkr�dejkrPejdZndejkrdejdZedkr2yddl	Z	Wq2e
k
r�ddlZYq2Xq2Wx*eD]"Z
e
ee�kr�eee
eee
��q�WdS)	zjThis module lets some other slip modules cooperate with either the glib
or the gi.repository.GLib modules.�)�absolute_importNZMainLoopZ
source_removeZtimeout_addzgi.repository.GLib�glib)�__doc__Z
__future__r�sys�__all__�modules�__name__�_selfZ_modr�ImportErrorZgi.repository.GLibZgiZwhat�dir�setattr�getattr�rr�/usr/lib/python3.6/_glib.py�<module>s$






_wrappers/__pycache__/__init__.cpython-36.pyc000064400000000161150501263300015134 0ustar003

�uAc�@sdS)N�rrr�/usr/lib/python3.6/__init__.py�<module>s_wrappers/__pycache__/__init__.cpython-36.opt-1.pyc000064400000000161150501263350016100 0ustar003

�uAc�@sdS)N�rrr�/usr/lib/python3.6/__init__.py�<module>s_wrappers/_glib.py000064400000003134150501263430010174 0ustar00# -*- coding: utf-8 -*-

# slip._wrappers._glib -- abstract (some) differences between glib and
# gi.repository.GLib
#
# Copyright © 2012, 2015 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
# Nils Philippsen <nils@redhat.com>

"""This module lets some other slip modules cooperate with either the glib
or the gi.repository.GLib modules."""

from __future__ import absolute_import

import sys

__all__ = ['MainLoop', 'source_remove', 'timeout_add']

_self = sys.modules[__name__]

_mod = None

while _mod is None:
    if 'gi.repository.GLib' in sys.modules:
        _mod = sys.modules['gi.repository.GLib']
    elif 'glib' in sys.modules:
        _mod = sys.modules['glib']
    # if not yet imported, try to import glib first, then
    # gi.repository.GLib ...
    if _mod is None:
        try:
            import glib
        except ImportError:
            import gi.repository.GLib
    # ... then repeat.

for what in __all__:
    if what not in dir(_self):
        setattr(_self, what, getattr(_mod, what))