def _cache_expires(self, seconds=0, **kw): """ Set expiration on this request. This sets the response to expire in the given seconds, and any other attributes are used for cache_control (e.g., private=True, etc). """ if seconds is True: seconds = 0 elif isinstance(seconds, timedelta): seconds = timedelta_to_seconds(seconds) cache_control = self.cache_control if seconds is None: pass elif not seconds: # To really expire something, you have to force a # bunch of these cache control attributes, and IE may # not pay attention to those still so we also set # Expires. cache_control.no_store = True cache_control.no_cache = True cache_control.must_revalidate = True cache_control.max_age = 0 cache_control.post_check = 0 cache_control.pre_check = 0 self.expires = datetime.utcnow() if 'last-modified' not in self.headers: self.last_modified = datetime.utcnow() self.pragma = 'no-cache' else: cache_control.properties.clear() cache_control.max_age = seconds self.expires = datetime.utcnow() + timedelta(seconds=seconds) self.pragma = None for name, value in kw.items(): setattr(cache_control, name, value)
def _cache_expires(self, seconds=0, **kw): """ Set expiration on this request. This sets the response to expire in the given seconds, and any other attributes are used for cache_control (e.g., private=True, etc). """ if seconds is True: seconds = 0 elif isinstance(seconds, timedelta): seconds = timedelta_to_seconds(seconds) cache_control = self.cache_control if seconds is None: pass elif not seconds: # To really expire something, you have to force a # bunch of these cache control attributes, and IE may # not pay attention to those still so we also set # Expires. cache_control.no_store = True cache_control.no_cache = True cache_control.must_revalidate = True cache_control.max_age = 0 cache_control.post_check = 0 cache_control.pre_check = 0 self.expires = datetime.utcnow() if 'last-modified' not in self.headers: self.last_modified = datetime.utcnow() self.pragma = 'no-cache' else: cache_control.max_age = seconds self.expires = datetime.utcnow() + timedelta(seconds=seconds) for name, value in kw.items(): setattr(cache_control, name, value)
def fetch_video_details(self, video_id): video_result = self._retrieve_video_details(video_id, 'snippet,contentDetails') # LATER: add debug logging for youtube response if video_result == False: return Result(False, meta_info=None, message=video_result.message) elif len(video_result) == 0: return Result( False, meta_info=None, message= _('Invalid YouTube URL. This video does not exist or is private and can not be embedded.' )) video_details = video_result[0] iso8601_duration = video_details['contentDetails']['duration'] duration = aniso8601.parse_duration(iso8601_duration) snippet = video_details['snippet'] best_thumbnail = self._find_biggest_thumbnail(snippet['thumbnails']) meta_info = { 'unique_id': video_details['id'], 'duration': timedelta_to_seconds(duration), 'display_name': snippet['title'], 'description': snippet['description'], 'thumbnail': { 'width': best_thumbnail['width'], 'height': best_thumbnail['height'], 'url': best_thumbnail['url'], }, 'type': VIDEO, } return Result(True, meta_info=meta_info, message=None)
def fetch_video_details(self, video_id): video_result = self._retrieve_video_details(video_id, 'snippet,contentDetails') # LATER: add debug logging for youtube response if video_result == False: return Result( False, meta_info=None, message=video_result.message ) elif len(video_result) == 0: return Result( False, meta_info=None, message=_('Invalid YouTube URL. This video does not exist or is private and can not be embedded.') ) video_details = video_result[0] iso8601_duration = video_details['contentDetails']['duration'] duration = aniso8601.parse_duration(iso8601_duration) snippet = video_details['snippet'] best_thumbnail = self._find_biggest_thumbnail(snippet['thumbnails']) meta_info = { 'unique_id': video_details['id'], 'duration': timedelta_to_seconds(duration), 'display_name': snippet['title'], 'description': snippet['description'], 'thumbnail': { 'width': best_thumbnail['width'], 'height': best_thumbnail['height'], 'url': best_thumbnail['url'], }, 'type': VIDEO, } return Result(True, meta_info=meta_info, message=None)
def test_timedelta_to_seconds(): val = datetime.timedelta(86400) result = datetime_utils.timedelta_to_seconds(val) eq_(result, 7464960000)
def test_timedelta_to_seconds(): val = datetime.timedelta(86400) result = datetime_utils.timedelta_to_seconds(val) assert result == 7464960000