コード例 #1
0
import inspect
import os
import tempfile
import unittest
import imp
from zoo.libs.utils import zlogging

logger = zlogging.getLogger(__name__)


def decorating_meta(decorator):
    class DecoratingMetaclass(type):
        def __new__(cls, class_name, bases, namespace):
            for key, value in list(namespace.items()):
                if callable(value):
                    namespace[key] = decorator(value)
            return type.__new__(cls, class_name, bases, namespace)

    return DecoratingMetaclass


def skipUnlessHasattr(obj):
    if not hasattr(obj, 'skip'):

        def decorated(*a, **kw):
            return obj(*a, **kw)

        return decorated

    def decorated(*a, **kw):
        return unittest.skip("{!r} doesn't have {!r}".format(obj, 'skip'))
コード例 #2
0
ファイル: filesystem.py プロジェクト: keenfoong/zoocore
import contextlib
import json
import os
import subprocess
import shutil
import errno
import zipfile
import cStringIO
import re
import functools
import sys

from zoo.libs.utils import zlogging, commandline

logger = zlogging.getLogger(zlogging.CENTRAL_LOGGER_NAME)

FILENAMEEXP = re.compile(u'[^\w\.-1]', re.UNICODE)


def clearUnMasked(func):
    """Decorator which clears the umask for a method.
    The umask is a permissions mask that gets applied
    whenever new files or folders are created. For I/O methods
    that have a permissions parameter, it is important that the
    umask is cleared prior to execution, otherwise the default
    umask may alter the resulting permissions

    :type func: function
    """
    @functools.wraps(func)
    def wrapper(*args, **kwargs):