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


Python Template.escape方法代码示例

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


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

示例1: QueryContainer

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import escape [as 别名]
    def QueryContainer(self, handler, query):

        # Reject a malformed request -- these attributes should only
        # appear in requests to send_file, but sometimes appear here
        badattrs = ('Rotation', 'Width', 'Height', 'PixelShape')
        for i in badattrs:
            if i in query:
                handler.send_error(404)
                return

        subcname = query['Container'][0]
        cname = subcname.split('/')[0]
        local_base_path = self.get_local_base_path(handler, query)
        if not handler.server.containers.has_key(cname) or \
           not self.get_local_path(handler, query):
            handler.send_error(404)
            return

        def ImageFileFilter(f):
            goodexts = ('.jpg', '.gif', '.png', '.bmp', '.tif', '.xbm',
                        '.xpm', '.pgm', '.pbm', '.ppm', '.pcx', '.tga',
                        '.fpx', '.ico', '.pcd', '.jpeg', '.tiff')
            return os.path.splitext(f)[1].lower() in goodexts

        def media_data(f):
            if f.name in self.media_data_cache:
                return self.media_data_cache[f.name]

            item = {}
            item['path'] = f.name
            item['part_path'] = f.name.replace(local_base_path, '', 1)
            item['name'] = os.path.split(f.name)[1]
            item['is_dir'] = f.isdir
            item['rotation'] = 0
            item['cdate'] = '%#x' % f.cdate
            item['mdate'] = '%#x' % f.mdate

            self.media_data_cache[f.name] = item
            return item

        t = Template(photo_template, filter=EncodeUnicode)
        t.name = subcname
        t.container = cname
        t.files, t.total, t.start = self.get_files(handler, query,
            ImageFileFilter)
        t.files = map(media_data, t.files)
        t.quote = quote
        t.escape = escape
        page = str(t)

        handler.send_response(200)
        handler.send_header('Content-Type', 'text/xml')
        handler.send_header('Content-Length', len(page))
        handler.send_header('Connection', 'close')
        handler.end_headers()
        handler.wfile.write(page)
开发者ID:armooo,项目名称:pytivo,代码行数:58,代码来源:photo.py

示例2: QueryItem

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import escape [as 别名]
    def QueryItem(self, handler, query):
        uq = urllib.parse.unquote_plus
        splitpath = [x for x in uq(query['Url'][0]).split('/') if x]
        path = os.path.join(handler.container['path'], *splitpath[1:])

        if path in self.media_data_cache:
            t = Template(ITEM_TEMPLATE)
            t.file = self.media_data_cache[path]
            t.escape = escape
            handler.send_xml(str(t))
        else:
            handler.send_error(404)
开发者ID:mlippert,项目名称:pytivo,代码行数:14,代码来源:music.py

示例3: get_details_xml

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import escape [as 别名]
    def get_details_xml(self, tsn, file_path):
        if (tsn, file_path) in self.tvbus_cache:
            details = self.tvbus_cache[(tsn, file_path)]
        else:
            file_info = VideoDetails()
            file_info['valid'] = transcode.supported_format(file_path)
            if file_info['valid']:
                file_info.update(self.metadata_full(file_path, tsn))

            t = Template(TVBUS_TEMPLATE, filter=EncodeUnicode)
            t.video = file_info
            t.escape = escape
            details = str(t)
            self.tvbus_cache[(tsn, file_path)] = details
        return details
开发者ID:Gimpson,项目名称:pytivo,代码行数:17,代码来源:video.py

示例4: QueryContainer

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import escape [as 别名]
    def QueryContainer(self, handler, query):

        # Reject a malformed request -- these attributes should only
        # appear in requests to send_file, but sometimes appear here
        badattrs = ('Rotation', 'Width', 'Height', 'PixelShape')
        for i in badattrs:
            if i in query:
                handler.send_error(404)
                return

        local_base_path = self.get_local_base_path(handler, query)
        if not self.get_local_path(handler, query):
            handler.send_error(404)
            return

        def ImageFileFilter(f):
            goodexts = ('.jpg', '.gif', '.png', '.bmp', '.tif', '.xbm',
                        '.xpm', '.pgm', '.pbm', '.ppm', '.pcx', '.tga',
                        '.fpx', '.ico', '.pcd', '.jpeg', '.tiff', '.nef')
            return os.path.splitext(f)[1].lower() in goodexts

        def media_data(f):
            if f.name in self.media_data_cache:
                return self.media_data_cache[f.name]

            item = {}
            item['path'] = f.name
            item['part_path'] = f.name.replace(local_base_path, '', 1)
            item['name'] = os.path.basename(f.name)
            item['is_dir'] = f.isdir
            item['rotation'] = 0
            item['cdate'] = '%#x' % f.cdate
            item['mdate'] = '%#x' % f.mdate

            self.media_data_cache[f.name] = item
            return item

        t = Template(PHOTO_TEMPLATE, filter=EncodeUnicode)
        t.name = query['Container'][0]
        t.container = handler.cname
        t.files, t.total, t.start = self.get_files(handler, query,
            ImageFileFilter)
        t.files = map(media_data, t.files)
        t.quote = quote
        t.escape = escape

        handler.send_xml(str(t))
开发者ID:WeekdayFiller,项目名称:pytivo,代码行数:49,代码来源:photo.py

示例5: TVBusQuery

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import escape [as 别名]
    def TVBusQuery(self, handler, query):
        tsn = handler.headers.getheader('tsn', '')       
        file = query['File'][0]
        path = self.get_local_path(handler, query)
        file_path = path + file

        file_info = VideoDetails()
        file_info['valid'] = transcode.supported_format(file_path)
        if file_info['valid']:
            file_info.update(self.__metadata_full(file_path, tsn))

        handler.send_response(200)
        handler.end_headers()
        t = Template(file=os.path.join(SCRIPTDIR,'templates', 'TvBus.tmpl'))
        t.video = file_info
        t.escape = escape
        handler.wfile.write(t)
开发者ID:armooo,项目名称:pytivo,代码行数:19,代码来源:video.py

示例6: get_details_xml

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import escape [as 别名]
    def get_details_xml(self, tsn, file_path):
        if (tsn, file_path) in self.tvbus_cache:
            details = self.tvbus_cache[(tsn, file_path)]
        else:
            file_info = VideoDetails()
            file_info['valid'] = transcode.supported_format(file_path)
            if file_info['valid']:
                file_info.update(self.metadata_full(file_path, tsn))

            t = Template(TVBUS_TEMPLATE)
            t.video = file_info
            t.escape = escape
            t.get_tv = metadata.get_tv
            t.get_mpaa = metadata.get_mpaa
            t.get_stars = metadata.get_stars
            t.get_color = metadata.get_color
            details = str(t)
            self.tvbus_cache[(tsn, file_path)] = details
        return details
开发者ID:mlippert,项目名称:pytivo,代码行数:21,代码来源:video.py

示例7: root_container

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import escape [as 别名]
 def root_container(self):
     tsn = self.headers.get('TiVo_TCD_ID', '')
     tsnshares = config.getShares(tsn)
     tsncontainers = []
     for section, settings in tsnshares:
         try:
             mime = GetPlugin(settings['type']).CONTENT_TYPE
             if mime.split('/')[1] in ('tivo-videos', 'tivo-music',
                                       'tivo-photos'):
                 settings['content_type'] = mime
                 tsncontainers.append((section, settings))
         except Exception as msg:
             self.server.logger.error('%s - %s', section, str(msg))
     t = Template(file=os.path.join(SCRIPTDIR, 'templates', 'root_container.tmpl'))
     if self.server.beacon.bd:
         t.renamed = self.server.beacon.bd.renamed
     else:
         t.renamed = {}
     t.containers = tsncontainers
     t.hostname = socket.gethostname()
     t.escape = escape
     t.quote = quote
     self.send_xml(str(t))
开发者ID:mlippert,项目名称:pytivo,代码行数:25,代码来源:httpserver.py

示例8: QueryContainer

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import escape [as 别名]
    def QueryContainer(self, handler, query):
        tsn = handler.headers.getheader('tsn', '')
        subcname = query['Container'][0]
        useragent = handler.headers.getheader('User-Agent', '')

        if not self.get_local_path(handler, query):
            handler.send_error(404)
            return

        container = handler.container
        force_alpha = container.getboolean('force_alpha')
        use_html = query.get('Format', [''])[0].lower() == 'text/html'

        files, total, start = self.get_files(handler, query,
                                             self.video_file_filter,
                                             force_alpha)

        videos = []
        local_base_path = self.get_local_base_path(handler, query)
        for f in files:
            video = VideoDetails()
            mtime = f.mdate
            try:
                ltime = time.localtime(mtime)
            except:
                logger.warning('Bad file time on ' + unicode(f.name, 'utf-8'))
                mtime = int(time.time())
                ltime = time.localtime(mtime)
            video['captureDate'] = hex(mtime)
            video['textDate'] = time.strftime('%b %d, %Y', ltime)
            video['name'] = os.path.basename(f.name)
            video['path'] = f.name
            video['part_path'] = f.name.replace(local_base_path, '', 1)
            if not video['part_path'].startswith(os.path.sep):
                video['part_path'] = os.path.sep + video['part_path']
            video['title'] = os.path.basename(f.name)
            video['is_dir'] = f.isdir
            if video['is_dir']:
                video['small_path'] = subcname + '/' + video['name']
                video['total_items'] = self.__total_items(f.name)
            else:
                if len(files) == 1 or f.name in transcode.info_cache:
                    video['valid'] = transcode.supported_format(f.name)
                    if video['valid']:
                        video.update(self.metadata_full(f.name, tsn))
                        if len(files) == 1:
                            video['captureDate'] = hex(isogm(video['time']))
                else:
                    video['valid'] = True
                    video.update(metadata.basic(f.name))

                if self.use_ts(tsn, f.name):
                    video['mime'] = 'video/x-tivo-mpeg-ts'
                else:
                    video['mime'] = 'video/x-tivo-mpeg'

                video['textSize'] = metadata.human_size(f.size)

            videos.append(video)

        logger.debug('mobileagent: %d useragent: %s' % (useragent.lower().find('mobile'), useragent.lower()))
        use_mobile = useragent.lower().find('mobile') > 0
        if use_html:
            if use_mobile:
                t = Template(HTML_CONTAINER_TEMPLATE_MOBILE, filter=EncodeUnicode)
            else:
                t = Template(HTML_CONTAINER_TEMPLATE, filter=EncodeUnicode)
        else:
            t = Template(XML_CONTAINER_TEMPLATE, filter=EncodeUnicode)

        t.container = handler.cname
        t.name = subcname
        t.total = total
        t.start = start
        t.videos = videos
        t.quote = quote
        t.escape = escape
        t.crc = zlib.crc32
        t.guid = config.getGUID()
        t.tivos = config.tivos
        t.tivo_names = config.tivo_names
        if use_html:
            handler.send_html(str(t))
        else:
            handler.send_xml(str(t))
开发者ID:thspencer,项目名称:pyTivo-Taylor,代码行数:87,代码来源:video.py

示例9: QueryContainer

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import escape [as 别名]

#.........这里部分代码省略.........
            #if track[0].isdigit:
            #    track = ' '.join(track.split(' ')[1:])

            #item['SongTitle'] = track
            #item['AlbumTitle'] = album
            #item['ArtistName'] = artist

            ext = os.path.splitext(f.name)[1].lower()
            fname = f.name

            try:
                # If the file is an mp3, let's load the EasyID3 interface
                if ext == '.mp3':
                    audioFile = MP3(fname, ID3=EasyID3)
                else:
                    # Otherwise, let mutagen figure it out
                    audioFile = mutagen.File(fname)

                if audioFile:
                    # Pull the length from the FileType, if present
                    if audioFile.info.length > 0:
                        item['Duration'] = int(audioFile.info.length * 1000)

                    # Grab our other tags, if present
                    def get_tag(tagname, d):
                        for tag in ([tagname] + TAGNAMES[tagname]):
                            try:
                                if tag in d:
                                    value = d[tag][0]
                                    if not isinstance(value, str):
                                        value = str(value)
                                    return value
                            except:
                                pass
                        return ''

                    artist = get_tag('artist', audioFile)
                    title = get_tag('title', audioFile)
                    if artist == 'Various Artists' and '/' in title:
                        artist, title = [x.strip() for x in title.split('/')]
                    item['ArtistName'] = artist
                    item['SongTitle'] = title
                    item['AlbumTitle'] = get_tag('album', audioFile)
                    item['AlbumYear'] = get_tag('date', audioFile)[:4]
                    item['MusicGenre'] = get_tag('genre', audioFile)
            except Exception as msg:
                logger.error(msg)

            ffmpeg_path = config.get_bin('ffmpeg')
            if 'Duration' not in item and ffmpeg_path:
                cmd = [ffmpeg_path, '-hide_banner', '-nostdin', '-i', fname]
                ffmpeg = subprocess.Popen(cmd, stderr=subprocess.PIPE,
                                               stdout=subprocess.PIPE)

                # wait 10 sec if ffmpeg is not back give up
                for i in range(200):
                    time.sleep(.05)
                    if not ffmpeg.poll() == None:
                        break

                if ffmpeg.poll() != None:
                    output = ffmpeg.stderr.read()
                    d = durre(output)
                    if d:
                        millisecs = ((int(d.group(1)) * 3600 +
                                      int(d.group(2)) * 60 +
                                      int(d.group(3))) * 1000 +
                                     int(d.group(4)) *
                                     (10 ** (3 - len(d.group(4)))))
                    else:
                        millisecs = 0
                    item['Duration'] = millisecs

            if 'Duration' in item and ffmpeg_path:
                item['params'] = 'Yes'

            self.media_data_cache[f.name] = item
            return item

        subcname = query['Container'][0]
        local_base_path = self.get_local_base_path(handler, query)

        if not self.get_local_path(handler, query):
            handler.send_error(404)
            return

        if os.path.splitext(subcname)[1].lower() in PLAYLISTS:
            t = Template(PLAYLIST_TEMPLATE)
            t.files, t.total, t.start = self.get_playlist(handler, query)
        else:
            t = Template(FOLDER_TEMPLATE)
            t.files, t.total, t.start = self.get_files(handler, query,
                                                       AudioFileFilter)
        t.files = list(map(media_data, t.files))
        t.container = handler.cname
        t.name = subcname
        t.quote = quote
        t.escape = escape

        handler.send_xml(str(t))
开发者ID:mlippert,项目名称:pytivo,代码行数:104,代码来源:music.py

示例10: QueryContainer

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import escape [as 别名]
    def QueryContainer(self, handler, query):
        tsn = handler.headers.getheader('tsn', '')
        subcname = query['Container'][0]

        # If you are running 8.3 software you want to enable hack83
        # in the config file
        if config.getHack83():
            print '=' * 73
            query, hackPath = self.hack(handler, query, subcname)
            hackPath = '/'.join(hackPath)
            print 'Tivo said:', subcname, '|| Hack said:', hackPath
            debug_write(__name__, fn_attr(), ['Tivo said: ', subcname, ' || Hack said: ',
                         hackPath])
            subcname = hackPath

            if not query:
                debug_write(__name__, fn_attr(), ['sending 302 redirect page'])
                handler.send_response(302)
                handler.send_header('Location ', 'http://' +
                                    handler.headers.getheader('host') +
                                    '/TiVoConnect?Command=QueryContainer&' +
                                    'AnchorItem=Hack8.3&Container=' + hackPath)
                handler.end_headers()
                return

        # End hack mess

        cname = subcname.split('/')[0]

        if not handler.server.containers.has_key(cname) or \
           not self.get_local_path(handler, query):
            handler.send_response(404)
            handler.end_headers()
            return

        container = handler.server.containers[cname]
        precache = container.get('precache', 'False').lower() == 'true'

        files, total, start = self.get_files(handler, query,
                                             self.video_file_filter)

        videos = []
        local_base_path = self.get_local_base_path(handler, query)
        for file in files:
            mtime = datetime.fromtimestamp(os.stat(file).st_mtime)
            video = VideoDetails()
            video['captureDate'] = hex(int(time.mktime(mtime.timetuple())))
            video['name'] = os.path.split(file)[1]
            video['path'] = file
            video['part_path'] = file.replace(local_base_path, '', 1)
            video['title'] = os.path.split(file)[1]
            video['is_dir'] = self.__isdir(file)
            if video['is_dir']:
                video['small_path'] = subcname + '/' + video['name']
                video['total_items'] = self.__total_items(file)
            else:
                if precache or len(files) == 1 or file in transcode.info_cache:
                    video['valid'] = transcode.supported_format(file)
                    if video['valid']:
                        video.update(self.__metadata_full(file, tsn))
                else:
                    video['valid'] = True
                    video.update(self.__metadata_basic(file))

            videos.append(video)

        handler.send_response(200)
        handler.end_headers()
        t = Template(file=os.path.join(SCRIPTDIR,'templates', 'container.tmpl'))
        t.container = cname
        t.name = subcname
        t.total = total
        t.start = start
        t.videos = videos
        t.quote = quote
        t.escape = escape
        t.crc = zlib.crc32
        t.guid = config.getGUID()
        t.tivos = handler.tivos
        handler.wfile.write(t)
开发者ID:armooo,项目名称:pytivo,代码行数:82,代码来源:video.py

示例11: Template

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import escape [as 别名]
        if not self.get_local_path(handler, query):
            handler.send_error(404)
            return

        if os.path.splitext(subcname)[1].lower() in PLAYLISTS:
            t = Template(PLAYLIST_TEMPLATE, filter=EncodeUnicode)
            t.files, t.total, t.start = self.get_playlist(handler, query)
        else:
            t = Template(FOLDER_TEMPLATE, filter=EncodeUnicode)
            t.files, t.total, t.start = self.get_files(handler, query,
                                                       AudioFileFilter)
        t.files = map(media_data, t.files)
        t.container = handler.cname
        t.name = subcname
        t.quote = quote
        t.escape = escape

        handler.send_xml(str(t))

    def QueryItem(self, handler, query):
        uq = urllib.unquote_plus
        splitpath = [x for x in uq(query['Url'][0]).split('/') if x]
        path = os.path.join(handler.container['path'], *splitpath[1:])

        if path in self.media_data_cache:
            t = Template(ITEM_TEMPLATE, filter=EncodeUnicode)
            t.file = self.media_data_cache[path]
            t.escape = escape
            handler.send_xml(str(t))
        else:
            handler.send_error(404)
开发者ID:akolster,项目名称:pytivo,代码行数:33,代码来源:music.py

示例12: QueryContainer

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import escape [as 别名]
    def QueryContainer(self, handler, query):
        tsn = handler.headers.getheader('tsn', '')
        subcname = query['Container'][0]

        if not self.get_local_path(handler, query):
            handler.send_error(404)
            return

        container = handler.container
        force_alpha = container.getboolean('force_alpha')
        ar = container.get('allow_recurse', 'auto').lower()
        if ar == 'auto':
            allow_recurse = not tsn or tsn[0] < '7'
        else:
            allow_recurse = ar in ('1', 'yes', 'true', 'on')

        files, total, start = self.get_files(handler, query,
                                             self.video_file_filter,
                                             force_alpha, allow_recurse)

        videos = []
        local_base_path = self.get_local_base_path(handler, query)
        for f in files:
            video = VideoDetails()
            mtime = f.mdate
            try:
                ltime = time.localtime(mtime)
            except:
                logger.warning('Bad file time on ' + unicode(f.name, 'utf-8'))
                mtime = time.time()
                ltime = time.localtime(mtime)
            video['captureDate'] = hex(int(mtime))
            video['textDate'] = time.strftime('%b %d, %Y', ltime)
            video['name'] = os.path.basename(f.name)
            video['path'] = f.name
            video['part_path'] = f.name.replace(local_base_path, '', 1)
            if not video['part_path'].startswith(os.path.sep):
                video['part_path'] = os.path.sep + video['part_path']
            video['title'] = os.path.basename(f.name)
            video['is_dir'] = f.isdir
            if video['is_dir']:
                video['small_path'] = subcname + '/' + video['name']
                video['total_items'] = self.__total_items(f.name)
            else:
                if len(files) == 1 or f.name in transcode.info_cache:
                    video['valid'] = transcode.supported_format(f.name)
                    if video['valid']:
                        video.update(self.metadata_full(f.name, tsn,
                                     mtime=mtime))
                        if len(files) == 1:
                            video['captureDate'] = hex(isogm(video['time']))
                else:
                    video['valid'] = True
                    video.update(metadata.basic(f.name, mtime))

                if self.use_ts(tsn, f.name):
                    video['mime'] = 'video/x-tivo-mpeg-ts'
                else:
                    video['mime'] = 'video/x-tivo-mpeg'

                video['textSize'] = metadata.human_size(f.size)

            videos.append(video)

        t = Template(XML_CONTAINER_TEMPLATE, filter=EncodeUnicode)
        t.container = handler.cname
        t.name = subcname
        t.total = total
        t.start = start
        t.videos = videos
        t.quote = quote
        t.escape = escape
        t.crc = zlib.crc32
        t.guid = config.getGUID()
        t.tivos = config.tivos
        handler.send_xml(str(t))
开发者ID:ertyu,项目名称:pytivo,代码行数:78,代码来源:video.py

示例13: QueryContainer

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import escape [as 别名]
    def QueryContainer(self, handler, query):
        tsn = handler.headers.getheader('tsn', '')
        subcname = query['Container'][0]
        cname = subcname.split('/')[0]

        if (not cname in handler.server.containers or
            not self.get_local_path(handler, query)):
            handler.send_error(404)
            return

        container = handler.server.containers[cname]
        precache = container.get('precache', 'False').lower() == 'true'
        force_alpha = container.get('force_alpha', 'False').lower() == 'true'

        files, total, start = self.get_files(handler, query,
                                             self.video_file_filter,
                                             force_alpha)

        videos = []
        local_base_path = self.get_local_base_path(handler, query)
        for f in files:
            video = VideoDetails()
            mtime = f.mdate
            try:
                ltime = time.localtime(mtime)
            except:
                logger.warning('Bad file time on ' + unicode(f.name, 'utf-8'))
                mtime = int(time.time())
                ltime = time.localtime(mtime)
            video['captureDate'] = hex(mtime)
            video['textDate'] = time.strftime('%b %d, %Y', ltime)
            video['name'] = os.path.split(f.name)[1]
            video['path'] = f.name
            video['part_path'] = f.name.replace(local_base_path, '', 1)
            if not video['part_path'].startswith(os.path.sep):
                video['part_path'] = os.path.sep + video['part_path']
            video['title'] = os.path.split(f.name)[1]
            video['is_dir'] = f.isdir
            if video['is_dir']:
                video['small_path'] = subcname + '/' + video['name']
                video['total_items'] = self.__total_items(f.name)
            else:
                if precache or len(files) == 1 or f.name in transcode.info_cache:
                    video['valid'] = transcode.supported_format(f.name)
                    if video['valid']:
                        video.update(self.metadata_full(f.name, tsn))
                else:
                    video['valid'] = True
                    video.update(metadata.basic(f.name))

                video['textSize'] = ( '%.3f GB' %
                    (float(f.size) / (1024 ** 3)) )

            videos.append(video)

        t = Template(CONTAINER_TEMPLATE, filter=EncodeUnicode)
        t.container = cname
        t.name = subcname
        t.total = total
        t.start = start
        t.videos = videos
        t.quote = quote
        t.escape = escape
        t.crc = zlib.crc32
        t.guid = config.getGUID()
        t.tivos = config.tivos
        t.tivo_names = config.tivo_names
        handler.send_response(200)
        handler.send_header('Content-Type', 'text/xml')
        handler.send_header('Expires', '0')
        handler.end_headers()
        handler.wfile.write(t)
开发者ID:Gimpson,项目名称:pytivo,代码行数:74,代码来源:video.py

示例14: QueryContainer

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import escape [as 别名]
    def QueryContainer(self, handler, query):
        tsn = handler.headers.getheader('tsn', '')
        subcname = query['Container'][0]

        if not self.get_local_path(handler, query):
            handler.send_error(404)
            return

        container = handler.container
        force_alpha = container.getboolean('force_alpha')
        ar = container.get('allow_recurse', 'auto').lower()
        if ar == 'auto':
            allow_recurse = not tsn or tsn[0] < '7'
        else:
            allow_recurse = ar in ('1', 'yes', 'true', 'on')
        use_html = query.get('Format', [''])[0].lower() == 'text/html'

        files, total, start = self.get_files(handler, query,
                                             self.video_file_filter,
                                             force_alpha, allow_recurse)

        videos = []
        local_base_path = self.get_local_base_path(handler, query)
        resort = False
        for f in files:
            video = VideoDetails()
            mtime = f.mdate
            try:
                ltime = time.localtime(mtime)
            except:
                logger.warning('Bad file time on ' + unicode(f.name, 'utf-8'))
                mtime = time.time()
                ltime = time.localtime(mtime)
            video['captureDate'] = hex(int(mtime))
            video['textDate'] = time.strftime('%b %d, %Y', ltime)
            video['name'] = os.path.basename(f.name)
            video['path'] = f.name
            video['part_path'] = f.name.replace(local_base_path, '', 1)
            if not video['part_path'].startswith(os.path.sep):
                video['part_path'] = os.path.sep + video['part_path']
            video['title'] = os.path.basename(f.name)
            video['is_dir'] = f.isdir
            if video['is_dir']:
                video['small_path'] = subcname + '/' + video['name']
                video['total_items'] = self.__total_items(f.name)
            else:
                if len(files) == 1 or f.name in transcode.info_cache:
                    video['valid'] = transcode.supported_format(f.name)
                    if video['valid']:
                        video.update(self.metadata_full(f.name, tsn,
                                     mtime=mtime))
                        if len(files) == 1:
                            video['captureDate'] = hex(isogm(video['time']))
                else:
                    video['valid'] = True
                    video.update(metadata.basic(f.name, mtime))

                if 'time' in video and video['time'] != '':
                    if video['time'].lower() == 'oad':
                        video['time'] = video['originalAirDate']
                        resort = True
                    try:
                        video['captureDate'] = hex(isogm(video['time']))
                        video['textDate'] = time.strftime('%b %d, %Y', time.localtime(isogm(video['time'])))
                        resort = True
                    except:
                        logger.warning('Bad time format: "' + video['time'] +
                                       '", using current time')

                if self.use_ts(tsn, f.name):
                    video['mime'] = 'video/x-tivo-mpeg-ts'
                else:
                    video['mime'] = 'video/x-tivo-mpeg'

                video['textSize'] = metadata.human_size(f.size)

            videos.append(video)

        if use_html:
            t = Template(HTML_CONTAINER_TEMPLATE, filter=EncodeUnicode)
        else:
            t = Template(XML_CONTAINER_TEMPLATE, filter=EncodeUnicode)

        sortby = query.get('SortOrder', ['Normal'])[0].lower()
        t.sortby = sortby
        if use_html and resort:
            if sortby == 'capturedate':
                logger.info('re-sorting by captureDate, reverse=True')
                videos.sort(key=itemgetter('captureDate'), reverse=True)
            elif sortby == '!capturedate':
                logger.info('re-sorting by captureDate, reverse=False')
                videos.sort(key=itemgetter('captureDate'), reverse=False)

        t.container = handler.cname
        t.name = subcname
        t.total = total
        t.start = start
        t.videos = videos
        t.quote = quote
        t.escape = escape
#.........这里部分代码省略.........
开发者ID:driver8x,项目名称:pytivo,代码行数:103,代码来源:video.py

示例15: QueryContainer

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import escape [as 别名]
    def QueryContainer(self, handler, query):
        tsn = handler.headers.getheader("tsn", "")
        subcname = query["Container"][0]

        if not self.get_local_path(handler, query):
            handler.send_error(404)
            return

        container = handler.container
        force_alpha = container.get("force_alpha", "False").lower() == "true"
        use_html = query.get("Format", [""])[0].lower() == "text/html"

        files, total, start = self.get_files(handler, query, self.video_file_filter, force_alpha)

        videos = []
        local_base_path = self.get_local_base_path(handler, query)
        for f in files:
            video = VideoDetails()
            mtime = f.mdate
            try:
                ltime = time.localtime(mtime)
            except:
                logger.warning("Bad file time on " + unicode(f.name, "utf-8"))
                mtime = int(time.time())
                ltime = time.localtime(mtime)
            video["captureDate"] = hex(mtime)
            video["textDate"] = time.strftime("%b %d, %Y", ltime)
            video["name"] = os.path.basename(f.name)
            video["path"] = f.name
            video["part_path"] = f.name.replace(local_base_path, "", 1)
            if not video["part_path"].startswith(os.path.sep):
                video["part_path"] = os.path.sep + video["part_path"]
            video["title"] = os.path.basename(f.name)
            video["is_dir"] = f.isdir
            if video["is_dir"]:
                video["small_path"] = subcname + "/" + video["name"]
                video["total_items"] = self.__total_items(f.name)
            else:
                if len(files) == 1 or f.name in transcode.info_cache:
                    video["valid"] = transcode.supported_format(f.name)
                    if video["valid"]:
                        video.update(self.metadata_full(f.name, tsn))
                        if len(files) == 1:
                            video["captureDate"] = hex(isogm(video["time"]))
                else:
                    video["valid"] = True
                    video.update(metadata.basic(f.name))

                if self.use_ts(tsn, f.name):
                    video["mime"] = "video/x-tivo-mpeg-ts"
                else:
                    video["mime"] = "video/x-tivo-mpeg"

                video["textSize"] = "%.3f GB" % (float(f.size) / (1024 ** 3))

            videos.append(video)

        if use_html:
            t = Template(HTML_CONTAINER_TEMPLATE, filter=EncodeUnicode)
        else:
            t = Template(XML_CONTAINER_TEMPLATE, filter=EncodeUnicode)
        t.container = handler.cname
        t.name = subcname
        t.total = total
        t.start = start
        t.videos = videos
        t.quote = quote
        t.escape = escape
        t.crc = zlib.crc32
        t.guid = config.getGUID()
        t.tivos = config.tivos
        t.tivo_names = config.tivo_names
        if use_html:
            handler.send_html(str(t))
        else:
            handler.send_xml(str(t))
开发者ID:WeekdayFiller,项目名称:pytivo,代码行数:78,代码来源:video.py


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