def __call__(self, environ, start_response): # sanitize the path for non unix systems cleaned_path = environ.get('PATH_INFO', '').strip('/') for sep in os.sep, os.altsep: if sep and sep != '/': cleaned_path = cleaned_path.replace(sep, '/') path = '/'.join([''] + [x for x in cleaned_path.split('/') if x and x != '..']) file_loader = None for search_path, loader in self.exports.iteritems(): if search_path == path: real_filename, file_loader = loader(None) if file_loader is not None: break if not search_path.endswith('/'): search_path += '/' if path.startswith(search_path): real_filename, file_loader = loader(path[len(search_path):]) if file_loader is not None: break if file_loader is None or not self.is_allowed(real_filename): return self.app(environ, start_response) guessed_type = mimetypes.guess_type(real_filename) mime_type = guessed_type[0] or self.fallback_mimetype f, mtime, file_size = file_loader() headers = [('Date', http_date())] if self.cache: timeout = self.cache_timeout etag = self.generate_etag(mtime, file_size, real_filename) headers += [ ('Etag', '"%s"' % etag), ('Cache-Control', 'max-age=%d, public' % timeout) ] if not is_resource_modified(environ, etag, last_modified=mtime): f.close() start_response('304 Not Modified', headers) return [] headers.append(('Expires', http_date(time() + timeout))) else: headers.append(('Cache-Control', 'public')) headers.extend(( ('Content-Type', mime_type), ('Content-Length', str(file_size)), ('Last-Modified', http_date(mtime)) )) start_response('200 OK', headers) return wrap_file(environ, f)
def __call__(self, environ, start_response): # sanitize the path for non unix systems cleaned_path = environ.get('PATH_INFO', '').strip('/') for sep in os.sep, os.altsep: if sep and sep != '/': cleaned_path = cleaned_path.replace(sep, '/') path = '/'.join( [''] + [x for x in cleaned_path.split('/') if x and x != '..']) file_loader = None for search_path, loader in self.exports.iteritems(): if search_path == path: real_filename, file_loader = loader(None) if file_loader is not None: break if not search_path.endswith('/'): search_path += '/' if path.startswith(search_path): real_filename, file_loader = loader(path[len(search_path):]) if file_loader is not None: break if file_loader is None or not self.is_allowed(real_filename): return self.app(environ, start_response) guessed_type = mimetypes.guess_type(real_filename) mime_type = guessed_type[0] or self.fallback_mimetype f, mtime, file_size = file_loader() headers = [('Date', http_date())] if self.cache: timeout = self.cache_timeout etag = self.generate_etag(mtime, file_size, real_filename) headers += [('Etag', '"%s"' % etag), ('Cache-Control', 'max-age=%d, public' % timeout)] if not is_resource_modified(environ, etag, last_modified=mtime): f.close() start_response('304 Not Modified', headers) return [] headers.append(('Expires', http_date(time() + timeout))) else: headers.append(('Cache-Control', 'public')) headers.extend( (('Content-Type', mime_type), ('Content-Length', str(file_size)), ('Last-Modified', http_date(mtime)))) start_response('200 OK', headers) return wrap_file(environ, f)
def get_friends_timeline(self, since=None, since_id=None, count=None, page=None): """ Returns the 20 most recent statuses posted by the authenticating user and that user's friends. This is the equivalent of /home on the Web. """ url = "%s%s" % (twitter_statuses_prefix, "friends_timeline.json") data = {} if since is not None: data['since'] = http.http_date(since) if since_id is not None: data['since_id'] = since_id got_data = http.GET(url, self.username, self.password, data) return self.__get_json_or_error(got_data)
def get_user_timeline(self, user_id=None, count=None, since=None, since_id=None, page=None): """ Returns the 20 most recent statuses posted from the authenticating user. It's also possible to request another user's timeline via the id parameter below. This is the equivalent of the Web /archive page for your own user, or the profile page for a third party. """ url = "%s%s" % (twitter_statuses_prefix, "user_timeline.json") data = {} if user_id is not None: data['id'] = user_id else: data['id'] = self.username if since is not None: data['since'] = http.http_date(since) if since_id is not None: data['since_id'] = since_id got_data = http.GET(url, self.username, self.password, data) return self.__get_json_or_error(got_data)