当前位置: 首页>>代码示例>>Python>>正文


Python xattr.set方法代码示例

本文整理汇总了Python中xattr.set方法的典型用法代码示例。如果您正苦于以下问题:Python xattr.set方法的具体用法?Python xattr.set怎么用?Python xattr.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在xattr的用法示例。


在下文中一共展示了xattr.set方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import xattr [as 别名]
# 或者: from xattr import set [as 别名]
def __init__(self, msg, tb=None, expected=False, cause=None, video_id=None):
        """ tb, if given, is the original traceback (so that it can be printed out).
        If expected is set, this is a normal error message and most likely not a bug in youtube-dl.
        """

        if sys.exc_info()[0] in (compat_urllib_error.URLError, socket.timeout, UnavailableVideoError):
            expected = True
        if video_id is not None:
            msg = video_id + ': ' + msg
        if cause:
            msg += ' (caused by %r)' % cause
        if not expected:
            msg += bug_reports_message()
        super(ExtractorError, self).__init__(msg)

        self.traceback = tb
        self.exc_info = sys.exc_info()  # preserve original exception
        self.cause = cause
        self.video_id = video_id 
开发者ID:tvalacarta,项目名称:tvalacarta,代码行数:21,代码来源:utils.py

示例2: set_logger

# 需要导入模块: import xattr [as 别名]
# 或者: from xattr import set [as 别名]
def set_logger(DBOBJ):
    """Set the DEBUG object.  This is called by _init_default_logger when
    the environment variable URLGRABBER_DEBUG is set, but can also be
    called by a calling program.  Basically, if the calling program uses
    the logging module and would like to incorporate urlgrabber logging,
    then it can do so this way.  It's probably not necessary as most
    internal logging is only for debugging purposes.

    The passed-in object should be a logging.Logger instance.  It will
    be pushed into the keepalive and byterange modules if they're
    being used.  The mirror module pulls this object in on import, so
    you will need to manually push into it.  In fact, you may find it
    tidier to simply push your logging object (or objects) into each
    of these modules independently.
    """

    global DEBUG
    DEBUG = DBOBJ 
开发者ID:yandex,项目名称:root-2015-tasks,代码行数:20,代码来源:grabber.py

示例3: sanitize_filename

# 需要导入模块: import xattr [as 别名]
# 或者: from xattr import set [as 别名]
def sanitize_filename(s, restricted=False, is_id=False):
    """Sanitizes a string so it could be used as part of a filename.
    If restricted is set, use a stricter subset of allowed characters.
    Set is_id if this is not an arbitrary string, but an ID that should be kept
    if possible.
    """
    def replace_insane(char):
        if restricted and char in ACCENT_CHARS:
            return ACCENT_CHARS[char]
        if char == '?' or ord(char) < 32 or ord(char) == 127:
            return ''
        elif char == '"':
            return '' if restricted else '\''
        elif char == ':':
            return '_-' if restricted else ' -'
        elif char in '\\/|*<>':
            return '_'
        if restricted and (char in '!&\'()[]{}$;`^,#' or char.isspace()):
            return '_'
        if restricted and ord(char) > 127:
            return '_'
        return char

    # Handle timestamps
    s = re.sub(r'[0-9]+(?::[0-9]+)+', lambda m: m.group(0).replace(':', '_'), s)
    result = ''.join(map(replace_insane, s))
    if not is_id:
        while '__' in result:
            result = result.replace('__', '_')
        result = result.strip('_')
        # Common case of "Foreign band name - English song title"
        if restricted and result.startswith('-_'):
            result = result[2:]
        if result.startswith('-'):
            result = '_' + result[len('-'):]
        result = result.lstrip('.')
        if not result:
            result = '_'
    return result 
开发者ID:tvalacarta,项目名称:tvalacarta,代码行数:41,代码来源:utils.py

示例4: save

# 需要导入模块: import xattr [as 别名]
# 或者: from xattr import set [as 别名]
def save(self, filename=None, ignore_discard=False, ignore_expires=False):
        # Store session cookies with `expires` set to 0 instead of an empty
        # string
        for cookie in self:
            if cookie.expires is None:
                cookie.expires = 0
        compat_cookiejar.MozillaCookieJar.save(self, filename, ignore_discard, ignore_expires) 
开发者ID:tvalacarta,项目名称:tvalacarta,代码行数:9,代码来源:utils.py

示例5: load

# 需要导入模块: import xattr [as 别名]
# 或者: from xattr import set [as 别名]
def load(self, filename=None, ignore_discard=False, ignore_expires=False):
        """Load cookies from a file."""
        if filename is None:
            if self.filename is not None:
                filename = self.filename
            else:
                raise ValueError(compat_cookiejar.MISSING_FILENAME_TEXT)

        cf = io.StringIO()
        with open(filename) as f:
            for line in f:
                if line.startswith(self._HTTPONLY_PREFIX):
                    line = line[len(self._HTTPONLY_PREFIX):]
                cf.write(compat_str(line))
        cf.seek(0)
        self._really_load(cf, filename, ignore_discard, ignore_expires)
        # Session cookies are denoted by either `expires` field set to
        # an empty string or 0. MozillaCookieJar only recognizes the former
        # (see [1]). So we need force the latter to be recognized as session
        # cookies on our own.
        # Session cookies may be important for cookies-based authentication,
        # e.g. usually, when user does not check 'Remember me' check box while
        # logging in on a site, some important cookies are stored as session
        # cookies so that not recognizing them will result in failed login.
        # 1. https://bugs.python.org/issue17164
        for cookie in self:
            # Treat `expires=0` cookies as session cookies
            if cookie.expires == 0:
                cookie.expires = None
                cookie.discard = True 
开发者ID:tvalacarta,项目名称:tvalacarta,代码行数:32,代码来源:utils.py

示例6: age_restricted

# 需要导入模块: import xattr [as 别名]
# 或者: from xattr import set [as 别名]
def age_restricted(content_limit, age_limit):
    """ Returns True iff the content should be blocked """

    if age_limit is None:  # No limit set
        return False
    if content_limit is None:
        return False  # Content available for everyone
    return age_limit < content_limit 
开发者ID:tvalacarta,项目名称:tvalacarta,代码行数:10,代码来源:utils.py

示例7: _apply_linux_xattr_rec

# 需要导入模块: import xattr [as 别名]
# 或者: from xattr import set [as 别名]
def _apply_linux_xattr_rec(self, path, restore_numeric_ids=False):
        if not xattr:
            if self.linux_xattr:
                add_error("%s: can't restore xattr; xattr support missing.\n"
                          % path)
            return
        existing_xattrs = set(xattr.list(path, nofollow=True))
        if self.linux_xattr:
            for k, v in self.linux_xattr:
                if k not in existing_xattrs \
                        or v != xattr.get(path, k, nofollow=True):
                    try:
                        xattr.set(path, k, v, nofollow=True)
                    except IOError, e:
                        if e.errno == errno.EPERM:
                            raise ApplyError('xattr.set: %s' % e)
                        else:
                            raise
                existing_xattrs -= frozenset([k])
            for k in existing_xattrs:
                try:
                    xattr.remove(path, k, nofollow=True)
                except IOError, e:
                    if e.errno == errno.EPERM:
                        raise ApplyError('xattr.remove: %s' % e)
                    else:
                        raise 
开发者ID:omererdem,项目名称:honeything,代码行数:29,代码来源:metadata.py

示例8: sanitize_filename

# 需要导入模块: import xattr [as 别名]
# 或者: from xattr import set [as 别名]
def sanitize_filename(s, restricted=False, is_id=False):
    """Sanitizes a string so it could be used as part of a filename.
    If restricted is set, use a stricter subset of allowed characters.
    Set is_id if this is not an arbitrary string, but an ID that should be kept if possible
    """
    def replace_insane(char):
        if restricted and char in ACCENT_CHARS:
            return ACCENT_CHARS[char]
        if char == '?' or ord(char) < 32 or ord(char) == 127:
            return ''
        elif char == '"':
            return '' if restricted else '\''
        elif char == ':':
            return '_-' if restricted else ' -'
        elif char in '\\/|*<>':
            return '_'
        if restricted and (char in '!&\'()[]{}$;`^,#' or char.isspace()):
            return '_'
        if restricted and ord(char) > 127:
            return '_'
        return char

    # Handle timestamps
    s = re.sub(r'[0-9]+(?::[0-9]+)+', lambda m: m.group(0).replace(':', '_'), s)
    result = ''.join(map(replace_insane, s))
    if not is_id:
        while '__' in result:
            result = result.replace('__', '_')
        result = result.strip('_')
        # Common case of "Foreign band name - English song title"
        if restricted and result.startswith('-_'):
            result = result[2:]
        if result.startswith('-'):
            result = '_' + result[len('-'):]
        result = result.lstrip('.')
        if not result:
            result = '_'
    return result 
开发者ID:Xonshiz,项目名称:anime-dl,代码行数:40,代码来源:utils.py

示例9: _make_callback

# 需要导入模块: import xattr [as 别名]
# 或者: from xattr import set [as 别名]
def _make_callback(self, callback_obj):
        # not used, left for compatibility
        if callable(callback_obj):
            return callback_obj, (), {}
        else:
            return callback_obj

# create the default URLGrabber used by urlXXX functions.
# NOTE: actual defaults are set in URLGrabberOptions 
开发者ID:yandex,项目名称:root-2015-tasks,代码行数:11,代码来源:grabber.py

示例10: _build_range

# 需要导入模块: import xattr [as 别名]
# 或者: from xattr import set [as 别名]
def _build_range(self):
        reget_length = 0
        rt = None
        if self.opts.reget and type(self.filename) in types.StringTypes:
            # we have reget turned on and we're dumping to a file
            try:
                s = os.stat(self.filename)
            except OSError:
                pass
            else:
                self.reget_time = s[stat.ST_MTIME]
                reget_length = s[stat.ST_SIZE]

                # Set initial length when regetting
                self._amount_read = reget_length    
                self._reget_length = reget_length # set where we started from, too

                rt = reget_length, ''
                self.append = 1
                
        if self.opts.range:
            rt = self.opts.range
            
            if rt[0] is None:
                rt = (0, rt[1])
            rt = (rt[0] + reget_length, rt[1])
            

        if rt:
            header = range_tuple_to_header(rt)
            if header:
                return header.split('=')[1] 
开发者ID:yandex,项目名称:root-2015-tasks,代码行数:34,代码来源:grabber.py

示例11: parallel_wait

# 需要导入模块: import xattr [as 别名]
# 或者: from xattr import set [as 别名]
def parallel_wait(meter=None):
    '''Process queued requests in parallel.
    '''

    # calculate total sizes
    meters = {}
    for opts in _async_queue:
        if opts.progress_obj and opts.multi_progress_obj:
            count, total = meters.get(opts.multi_progress_obj) or (0, 0)
            meters[opts.multi_progress_obj] = count + 1, total + opts.size

    # start multi-file meters
    for meter in meters:
        count, total = meters[meter]
        meter.start(count, total)

    dl = _ExternalDownloaderPool()
    host_con = {} # current host connection counts
    single = set() # hosts in single connection mode
    retry_queue = []

    def start(opts, tries):
        opts.tries = tries
        try:
            dl.start(opts)
        except OSError, e:
            # can't spawn downloader, give up immediately
            opts.exception = URLGrabError(5, exception2msg(e))
            _run_callback(opts.failfunc, opts)
            return

        key, limit = opts.async 
开发者ID:yandex,项目名称:root-2015-tasks,代码行数:34,代码来源:grabber.py


注:本文中的xattr.set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。