[ Avaa Bypassed ]




Upload:

Command:

www-data@18.218.241.211: ~ $
"""Module with little helper functions and classes:

deprecated - decorator to emit a warning if a depreacted function is used
"""
# Copyright (C) 2008-2009 Sebastian Heinlein <sevel@glatzor.de>
#
# Licensed under the GNU General Public License Version 2
#
# 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, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

__author__ = "Sebastian Heinlein <devel@glatzor.de>"

__all__ = ("deprecated", "IsoCodes")

import os
import sys
import contextlib
import gettext
import functools
import warnings
from xml.etree import ElementTree

if sys.version >= '3':
    _gettext_method = "gettext"
else:
    _gettext_method = "ugettext"


def deprecated(func):
    """This is a decorator which can be used to mark functions
    as deprecated. It will result in a warning being emitted
    when the function is used.

    Taken from http://wiki.python.org/moin/PythonDecoratorLibrary
    #GeneratingDeprecationWarnings
    """
    @functools.wraps(func)
    def new_func(*args, **kwargs):
        warnings.warn_explicit(
            "Call to deprecated function %(funcname)s." % {
                'funcname': func.__name__,
            },
            category=DeprecationWarning,
            filename=func.__code__.co_filename,
            lineno=func.__code__.co_firstlineno + 1
        )
        return func(*args, **kwargs)
    return new_func


@contextlib.contextmanager
def set_euid_egid(uid, gid):
    # no need to drop privs
    if os.getuid() != 0 and os.getgid() != 0:
        yield
        return
    # temporary drop privs
    os.setegid(gid)
    old_groups = os.getgroups()
    os.setgroups([gid])
    os.seteuid(uid)
    try:
        yield
    finally:
        os.seteuid(os.getuid())
        os.setegid(os.getgid())
        os.setgroups(old_groups)


class IsoCodes(object):

    """Provides access to the iso-codes language, script and country
    database.
    """

    def __init__(self, norm, tag, fallback_tag=None):
        filename = "/usr/share/xml/iso-codes/%s.xml" % norm
        et = ElementTree.ElementTree(file=filename)
        self._dict = {}
        self.norm = norm
        for element in list(et.iter()):
            iso_code = element.get(tag)
            if not iso_code and fallback_tag:
                iso_code = element.get(fallback_tag)
            if iso_code:
                self._dict[iso_code] = element.get("name")

    def get_localised_name(self, value, locale):
        try:
            name = self._dict[value]
        except KeyError:
            return None
        trans = gettext.translation(domain=self.norm, fallback=True,
                                    languages=[locale])
        return getattr(trans, _gettext_method)(name)

    def get_name(self, value):
        try:
            return self._dict[value]
        except KeyError:
            return None


def split_package_id(package):
    """Return the name, the version number and the release of the
    specified package."""
    if "=" in package:
        name, version = package.split("=", 1)
        release = None
    elif "/" in package:
        name, release = package.split("/", 1)
        version = None
    else:
        name = package
        version = release = None
    return name, version, release


# vim:ts=4:sw=4:et

Filemanager

Name Type Size Permission Actions
__pycache__ Folder 0755
worker Folder 0755
__init__.py File 1.14 KB 0644
client.py File 73.22 KB 0644
config.py File 9 KB 0644
console.py File 29.89 KB 0644
core.py File 90.84 KB 0644
crash.py File 2.74 KB 0644
debconf.py File 6.24 KB 0644
enums.py File 32.34 KB 0644
errors.py File 7.28 KB 0644
gtk3widgets.py File 47.17 KB 0644
lock.py File 5.9 KB 0644
logger.py File 2.3 KB 0644
loop.py File 1.07 KB 0644
networking.py File 9.7 KB 0644
policykit1.py File 6.98 KB 0644
progress.py File 33.4 KB 0644
utils.py File 3.79 KB 0644