當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。