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


Python util.check_u函数代码示例

本文整理汇总了Python中miro.util.check_u函数的典型用法代码示例。如果您正苦于以下问题:Python check_u函数的具体用法?Python check_u怎么用?Python check_u使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: unicode_to_filename

def unicode_to_filename(filename, path=None):
    """Takes in a unicode string representation of a filename (NOT a
    file path) and creates a valid byte representation of it
    attempting to preserve extensions.

    .. Note::

       This is not guaranteed to give the same results every time it
       is run, nor is it guaranteed to reverse the results of
       filename_to_unicode.
    """
    check_u(filename)
    if path:
        check_b(path)
    else:
        path = os.getcwd()

    # keep this a little shorter than the max length, so we can
    # add a number to the end
    max_len = os.statvfs(path)[statvfs.F_NAMEMAX] - 5

    for mem in ("/", "\000", "\\", ":", "*", "?", "\"", "'",
                "<", ">", "|", "&", "\r", "\n"):
        filename = filename.replace(mem, "_")

    new_filename = encode_fn(filename)

    while len(new_filename) > max_len:
        filename = shorten_fn(filename)
        new_filename = encode_fn(filename)

    return new_filename
开发者ID:codito,项目名称:miro,代码行数:32,代码来源:utils.py

示例2: filename_from_url

def filename_from_url(url, clean=False):
    """Returns a reasonable filename for saving the given url.
    """
    check_u(url)
    try:
        match = URI_PATTERN.match(url)
        if match is None:
            # This code path will never be executed.
            return unicode_to_filename(url)
        filename = match.group(2)
        query = match.group(4)
        if not filename:
            ret = query
        elif not query:
            ret = filename
        else:
            root, ext = os.path.splitext(filename)
            ret = u"%s-%s%s" % (root, query, ext)
        ret = unquote(ret)
        if ret is None:
            ret = u'unknown'
        if clean:
            return clean_filename(ret)
        else:
            return unicode_to_filename(ret)
    except (SystemExit, KeyboardInterrupt):
        raise
    except:
        return unicode_to_filename(u'unknown')
开发者ID:cool-RR,项目名称:Miro,代码行数:29,代码来源:download_utils.py

示例3: create_downloader

def create_downloader(url, contentType, dlid):
    check_u(url)
    check_u(contentType)
    if contentType == u'application/x-bittorrent':
        return BTDownloader(url, dlid)
    else:
        return HTTPDownloader(url, dlid, expectedContentType=contentType)
开发者ID:nxmirrors,项目名称:miro,代码行数:7,代码来源:download.py

示例4: _scrape_youtube_url

def _scrape_youtube_url(url, callback):
    check_u(url)

    components = urlparse.urlsplit(url)
    params = cgi.parse_qs(components[3])

    video_id = None
    if components[2] == u'/watch' and 'v' in params:
        try:
            video_id = params['v'][0]
        except IndexError:
            pass
    elif components[2].startswith('/v/'):
        m = re.compile(r'/v/([\w-]+)').match(components[2])
        if m is not None:
            video_id = m.group(1)

    if video_id is None:
        logging.warning('_scrape_youtube_url: unable to scrape YouTube Video URL')
        callback(None)
        return

    try:
        url = u"http://www.youtube.com/get_video_info?video_id=%s&el=embedded&ps=default&eurl=" % video_id
        httpclient.grab_url(
            url,
            lambda x: _youtube_callback_step2(x, video_id, callback),
            lambda x: _youtube_errback(x, callback))

    except StandardError:
        logging.exception("youtube_callback: unable to scrape YouTube Video URL")
        callback(None)
开发者ID:bluezone,项目名称:miro,代码行数:32,代码来源:flashscraper.py

示例5: __setitem__

 def __setitem__(self, key, value):
     check_u(key)
     super(DeviceDatabase, self).__setitem__(key, value)
     if self.parent:
         self.parent.notify_changed()
     else:
         self.notify_changed()
开发者ID:codito,项目名称:miro,代码行数:7,代码来源:devices.py

示例6: setup_new

    def setup_new(self, url, item, content_type=None, channel_name=None):
        check_u(url)
        if content_type:
            check_u(content_type)
        self.orig_url = self.url = url
        self.item_list = []
        self.child_deleted = False
        self.main_item_id = None
        self.dlid = generate_dlid()
        if content_type is None:
            # HACK: Some servers report the wrong content-type for
            # torrent files.  We try to work around that by assuming
            # if the enclosure states that something is a torrent,
            # it's a torrent.  Thanks to [email protected]
            if item.enclosure_type == u'application/x-bittorrent':
                content_type = item.enclosure_type
        self.content_type = u""
        self.delete_files = True
        self.channel_name = channel_name
        self.manualUpload = False
        self._update_retry_time_dc = None
        self.status_updates_frozen = False
        self.last_update = time.time()
        self.reset_status_attributes()
        if content_type is None:
            self.content_type = u""
        else:
            self.content_type = content_type

        if self.content_type == u'':
            self.get_content_type()
        else:
            self.run_downloader()
开发者ID:dankamongmen,项目名称:miro,代码行数:33,代码来源:downloader.py

示例7: shorten_fn

def shorten_fn(filename):
    check_u(filename)
    first, last = os.path.splitext(filename)

    if first:
        return u"".join([first[:-1], last])

    return unicode(last[:-1])
开发者ID:codito,项目名称:miro,代码行数:8,代码来源:utils.py

示例8: __getitem__

 def __getitem__(self, key):
     check_u(key)
     value = super(DeviceDatabase, self).__getitem__(key)
     if isinstance(value, dict) and not isinstance(value, DeviceDatabase):
         value = DeviceDatabase(value, self.parent or self)
          # don't trip the changed signal
         super(DeviceDatabase, self).__setitem__(key, value)
     return value
开发者ID:codito,项目名称:miro,代码行数:8,代码来源:devices.py

示例9: try_scraping_url

def try_scraping_url(url, callback):
    check_u(url)
    scrape = _get_scrape_function_for(url)

    if scrape is not None:
        scrape(url,
               lambda newurl, content_type=u"video/x-flv", title=None: _actual_url_callback(url, callback, newurl, content_type, title))
    else:
        callback(url)
开发者ID:bluezone,项目名称:miro,代码行数:9,代码来源:flashscraper.py

示例10: filename_to_unicode

def filename_to_unicode(filename, path=None):
    """Given a filename in raw bytes, return the unicode representation

    Since this is not guaranteed to give the same results every time
    it is run, not is it garanteed to reverse the results of
    unicode_to_filename
    """
    if path:
        check_u(path)
    check_u(filename)
    return filename
开发者ID:nxmirrors,项目名称:miro,代码行数:11,代码来源:utils.py

示例11: setup_new

 def setup_new(self, typ):
     """Construct a TabOrder.  typ should be either ``channel`` or
     ``playlist``.
     """
     check_u(typ)
     self.type = typ
     self.tab_ids = []
     self._setup_views()
     to_sort = self.id_to_tab.values()
     to_sort.sort(key=lambda x: x.get_title().lower())
     for tab in to_sort:
         self.tab_ids.append(tab.id)
开发者ID:cool-RR,项目名称:Miro,代码行数:12,代码来源:tabs.py

示例12: start_new_download

def start_new_download(url, dlid, contentType, channelName):
    """Creates a new downloader object.

    Returns id on success, None on failure.
    """
    check_u(url)
    check_u(contentType)
    if channelName:
        check_f(channelName)
    dl = create_downloader(url, contentType, dlid)
    dl.channelName = channelName
    _downloads[dlid] = dl
开发者ID:nxmirrors,项目名称:miro,代码行数:12,代码来源:download.py

示例13: shortenFilename

def shortenFilename(filename):
    check_u(filename)
    # Find the first part and the last part
    pieces = filename.split(u".")
    lastpart = pieces[-1]
    if len(pieces) > 1:
        firstpart = u".".join(pieces[:-1])
    else:
        firstpart = u""
    # If there's a first part, use that, otherwise shorten what we have
    if len(firstpart) > 0:
        return u"%s.%s" % (firstpart[:-1],lastpart)
    else:
        return filename[:-1]
开发者ID:jcooley,项目名称:miro,代码行数:14,代码来源:utils.py

示例14: unicode_to_filename

def unicode_to_filename(filename, path=None):
    """Takes in a unicode string representation of a filename and
    creates a valid byte representation of it attempting to preserve
    extensions

    This is not guaranteed to give the same results every time it is
    run, not is it garanteed to reverse the results of
    filename_to_unicode
    """
    @returns_unicode
    def shorten_filename(filename):
        check_u(filename)
        # Find the first part and the last part
        pieces = filename.split(u".")
        lastpart = pieces[-1]
        if len(pieces) > 1:
            firstpart = u".".join(pieces[:-1])
        else:
            firstpart = u""
        # If there's a first part, use that, otherwise shorten what we have
        if len(firstpart) > 0:
            return u"%s.%s" % (firstpart[:-1], lastpart)
        else:
            return filename[:-1]

    check_u(filename)
    if path:
        check_u(path)
    else:
        path = os.getcwd()

    # Keep this a little shorter than the max length, so we can run
    # nextFilename
    MAX_LEN = 200

    badchars = ('/', '\000', '\\', ':', '*', '?', "'", '"',
                '<', '>', '|', "\n", "\r")
    for mem in badchars:
        filename = filename.replace(mem, "_")

    new_filename = filename
    while len(new_filename) > MAX_LEN:
        new_filename = shorten_filename(new_filename)

    return new_filename
开发者ID:ShriramK,项目名称:miro,代码行数:45,代码来源:utils.py

示例15: unicode_to_filename

def unicode_to_filename(filename, path = None):
    check_u(filename)
    if path:
        check_b(path)
    else:
        path = os.getcwd()

    # Keep this a little shorter than the max length, so we can run
    # nextFilename
    MAX_LEN = os.statvfs(path)[statvfs.F_NAMEMAX]-5

    for mem in ("/", "\000", "\\", ":", "*", "?", "'", "\"", "<", ">", "|", "&", "\r", "\n"):
        filename = filename.replace(mem, "_")

    new_filename = filename.encode('utf-8','replace')
    while len(new_filename) > MAX_LEN:
        filename = shortenFilename(filename)
        new_filename = filename.encode('utf-8','replace')

    return new_filename
开发者ID:jcooley,项目名称:miro,代码行数:20,代码来源:utils.py


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