diff options
author | Christopher Allan Webber <cwebber@dustycloud.org> | 2011-11-13 20:23:26 -0600 |
---|---|---|
committer | Christopher Allan Webber <cwebber@dustycloud.org> | 2011-11-13 20:23:26 -0600 |
commit | ee91c2b88d1a42b9d15d34d2c081cd8394649041 (patch) | |
tree | 01a75b958b2814763a0b219145bbe284d1d04931 | |
parent | 4671fda345394dad9ca4278b1cf7b2cdf7d2b4ee (diff) | |
parent | 285ffeddf3542201b83072d3be544c85e9c487c2 (diff) | |
download | mediagoblin-ee91c2b88d1a42b9d15d34d2c081cd8394649041.tar.lz mediagoblin-ee91c2b88d1a42b9d15d34d2c081cd8394649041.tar.xz mediagoblin-ee91c2b88d1a42b9d15d34d2c081cd8394649041.zip |
Merge remote-tracking branch 'remotes/nyergler/pep8-ification'
Conflicts:
mediagoblin/db/migrations.py
mediagoblin/db/models.py
mediagoblin/user_pages/views.py
mediagoblin/util.py
44 files changed, 159 insertions, 123 deletions
diff --git a/mediagoblin/app.py b/mediagoblin/app.py index d39469c3..ce4b0bec 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -94,7 +94,7 @@ class MediaGoblinApp(object): # object. ####################################################### - setup_globals(app = self) + setup_globals(app=self) # Workbench *currently* only used by celery, so this only # matters in always eager mode :) @@ -104,7 +104,6 @@ class MediaGoblinApp(object): self.middleware = [common.import_component(m)(self) for m in middleware.ENABLED_MIDDLEWARE] - def __call__(self, environ, start_response): request = Request(environ) diff --git a/mediagoblin/auth/forms.py b/mediagoblin/auth/forms.py index a932ad26..dcb6766c 100644 --- a/mediagoblin/auth/forms.py +++ b/mediagoblin/auth/forms.py @@ -59,9 +59,10 @@ class ForgotPassForm(wtforms.Form): 'Username or email', [wtforms.validators.Required()]) - def validate_username(form,field): - if not (re.match(r'^\w+$',field.data) or - re.match(r'^.+@[^.].*\.[a-z]{2,10}$',field.data, re.IGNORECASE)): + def validate_username(form, field): + if not (re.match(r'^\w+$', field.data) or + re.match(r'^.+@[^.].*\.[a-z]{2,10}$', field.data, + re.IGNORECASE)): raise wtforms.ValidationError(u'Incorrect input') @@ -82,4 +83,3 @@ class ChangePassForm(wtforms.Form): token = wtforms.HiddenField( '', [wtforms.validators.Required()]) - diff --git a/mediagoblin/auth/lib.py b/mediagoblin/auth/lib.py index 4c57ef88..653424cc 100644 --- a/mediagoblin/auth/lib.py +++ b/mediagoblin/auth/lib.py @@ -94,6 +94,7 @@ EMAIL_VERIFICATION_TEMPLATE = ( u"http://{host}{uri}?" u"userid={userid}&token={verification_key}") + def send_verification_email(user, request): """ Send the verification email to users to activate their accounts. @@ -128,6 +129,7 @@ EMAIL_FP_VERIFICATION_TEMPLATE = ( u"http://{host}{uri}?" u"userid={userid}&token={fp_verification_key}") + def send_fp_verification_email(user, request): """ Send the verification email to users to change their password. @@ -151,4 +153,3 @@ def send_fp_verification_email(user, request): [user['email']], 'GNU MediaGoblin - Change forgotten password!', rendered_email) - diff --git a/mediagoblin/auth/routing.py b/mediagoblin/auth/routing.py index 912d89fa..365ccfaa 100644 --- a/mediagoblin/auth/routing.py +++ b/mediagoblin/auth/routing.py @@ -33,7 +33,8 @@ auth_routes = [ controller='mediagoblin.views:simple_template_render'), Route('mediagoblin.auth.forgot_password', '/forgot_password/', controller='mediagoblin.auth.views:forgot_password'), - Route('mediagoblin.auth.verify_forgot_password', '/forgot_password/verify/', + Route('mediagoblin.auth.verify_forgot_password', + '/forgot_password/verify/', controller='mediagoblin.auth.views:verify_forgot_password'), Route('mediagoblin.auth.fp_changed_success', '/forgot_password/changed_success/', diff --git a/mediagoblin/auth/views.py b/mediagoblin/auth/views.py index 2a670679..8888d23c 100644 --- a/mediagoblin/auth/views.py +++ b/mediagoblin/auth/views.py @@ -160,7 +160,7 @@ def verify_email(request): you are lucky :) """ # If we don't have userid and token parameters, we can't do anything; 404 - if not request.GET.has_key('userid') or not request.GET.has_key('token'): + if not 'userid' in request.GET or not 'token' in request.GET: return render_404(request) user = request.db.User.find_one( @@ -253,8 +253,7 @@ def forgot_password(request): request, 'mediagoblin.user_pages.user_home', user=user['username']) - - # do not reveal whether or not there is a matching user, just move along + # do not reveal whether or not there is a matching user return redirect(request, 'mediagoblin.auth.fp_email_sent') return render_to_response( @@ -328,6 +327,6 @@ def _process_for_token(request): formdata = { 'vars': formdata_vars, 'has_userid_and_token': - formdata_vars.has_key('userid') and formdata_vars.has_key('token')} + 'userid' in formdata_vars and 'token' in formdata_vars} return formdata diff --git a/mediagoblin/db/__init__.py b/mediagoblin/db/__init__.py index c5124b1a..27e8a90f 100644 --- a/mediagoblin/db/__init__.py +++ b/mediagoblin/db/__init__.py @@ -23,7 +23,7 @@ Database Abstraction/Wrapper Layer pymongo. Read beow for why, but note that nobody is actually doing this and there's no proof that we'll ever support more than MongoDB... it would be a huge amount of work to do so. - + If you really want to prove that possible, jump on IRC and talk to us about making such a branch. In the meanwhile, it doesn't hurt to have things as they are... if it ever makes it hard for us to diff --git a/mediagoblin/db/indexes.py b/mediagoblin/db/indexes.py index 75394a31..1dd73f2b 100644 --- a/mediagoblin/db/indexes.py +++ b/mediagoblin/db/indexes.py @@ -93,8 +93,9 @@ MEDIAENTRY_INDEXES = { ('created', DESCENDING)]}, 'state_uploader_tags_created': { - # Indexing on processed?, media uploader, associated tags, and timestamp - # Used for showing media items matching a tag search, most recent first. + # Indexing on processed?, media uploader, associated tags, and + # timestamp Used for showing media items matching a tag + # search, most recent first. 'index': [('state', ASCENDING), ('uploader', ASCENDING), ('tags.slug', DESCENDING), diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 0f5174cc..c010cb89 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -14,7 +14,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -import datetime, uuid +import datetime +import uuid from mongokit import Document @@ -67,17 +68,17 @@ class User(Document): 'username': unicode, 'email': unicode, 'created': datetime.datetime, - 'plugin_data': dict, # plugins can dump stuff here. + 'plugin_data': dict, # plugins can dump stuff here. 'pw_hash': unicode, 'email_verified': bool, 'status': unicode, 'verification_key': unicode, 'is_admin': bool, - 'url' : unicode, - 'bio' : unicode, # May contain markdown - 'bio_html': unicode, # May contain plaintext, or HTML - 'fp_verification_key': unicode, # forgotten password verification key - 'fp_token_expire': datetime.datetime + 'url': unicode, + 'bio': unicode, # May contain markdown + 'bio_html': unicode, # May contain plaintext, or HTML + 'fp_verification_key': unicode, # forgotten password verification key + 'fp_token_expire': datetime.datetime, } required_fields = ['username', 'created', 'pw_hash', 'email'] @@ -172,8 +173,8 @@ class MediaEntry(Document): critical to this piece of media but may be usefully relevant to people viewing the work. (currently unused.) - - fail_error: path to the exception raised - - fail_metadata: + - fail_error: path to the exception raised + - fail_metadata: """ __collection__ = 'media_entries' @@ -182,11 +183,11 @@ class MediaEntry(Document): 'title': unicode, 'slug': unicode, 'created': datetime.datetime, - 'description': unicode, # May contain markdown/up - 'description_html': unicode, # May contain plaintext, or HTML + 'description': unicode, # May contain markdown/up + 'description_html': unicode, # May contain plaintext, or HTML 'media_type': unicode, - 'media_data': dict, # extra data relevant to this media_type - 'plugin_data': dict, # plugins can dump stuff here. + 'media_data': dict, # extra data relevant to this media_type + 'plugin_data': dict, # plugins can dump stuff here. 'tags': [dict], 'state': unicode, @@ -218,7 +219,8 @@ class MediaEntry(Document): return self.db.MediaComment.find({ 'media_entry': self['_id']}).sort('created', DESCENDING) - def get_display_media(self, media_map, fetch_order=common.DISPLAY_IMAGE_FETCHING_ORDER): + def get_display_media(self, media_map, + fetch_order=common.DISPLAY_IMAGE_FETCHING_ORDER): """ Find the best media for display. @@ -271,7 +273,7 @@ class MediaEntry(Document): """ Provide a url to the previous entry from this user, if there is one """ - cursor = self.db.MediaEntry.find({'_id' : {"$gt": self['_id']}, + cursor = self.db.MediaEntry.find({'_id': {"$gt": self['_id']}, 'uploader': self['uploader'], 'state': 'processed'}).sort( '_id', ASCENDING).limit(1) @@ -284,7 +286,7 @@ class MediaEntry(Document): """ Provide a url to the next entry from this user, if there is one """ - cursor = self.db.MediaEntry.find({'_id' : {"$lt": self['_id']}, + cursor = self.db.MediaEntry.find({'_id': {"$lt": self['_id']}, 'uploader': self['uploader'], 'state': 'processed'}).sort( '_id', DESCENDING).limit(1) @@ -351,4 +353,3 @@ def register_models(connection): Register all models in REGISTER_MODELS with this connection. """ connection.register(REGISTER_MODELS) - diff --git a/mediagoblin/db/open.py b/mediagoblin/db/open.py index e73b6258..e677ba12 100644 --- a/mediagoblin/db/open.py +++ b/mediagoblin/db/open.py @@ -29,7 +29,7 @@ def connect_database_from_config(app_config, use_pymongo=False): port = app_config.get('db_port') if port: port = asint(port) - + if use_pymongo: connection = pymongo.Connection( app_config.get('db_host'), port) diff --git a/mediagoblin/db/util.py b/mediagoblin/db/util.py index 84a6cbce..52e97f6d 100644 --- a/mediagoblin/db/util.py +++ b/mediagoblin/db/util.py @@ -118,11 +118,12 @@ def remove_deprecated_indexes(database, deprecated_indexes=DEPRECATED_INDEXES): ################# # The default migration registry... -# +# # Don't set this yourself! RegisterMigration will automatically fill # this with stuff via decorating methods in migrations.py -class MissingCurrentMigration(Exception): pass +class MissingCurrentMigration(Exception): + pass MIGRATIONS = {} @@ -147,7 +148,7 @@ class RegisterMigration(object): """ def __init__(self, migration_number, migration_registry=MIGRATIONS): assert migration_number > 0, "Migration number must be > 0!" - assert not migration_registry.has_key(migration_number), \ + assert migration_number not in migration_registry, \ "Duplicate migration numbers detected! That's not allowed!" self.migration_number = migration_number diff --git a/mediagoblin/decorators.py b/mediagoblin/decorators.py index 6431d67e..b247e229 100644 --- a/mediagoblin/decorators.py +++ b/mediagoblin/decorators.py @@ -119,6 +119,7 @@ def get_user_media_entry(controller): return _make_safe(wrapper, controller) + def get_media_entry_by_id(controller): """ Pass in a MediaEntry based off of a url component @@ -138,4 +139,3 @@ def get_media_entry_by_id(controller): return controller(request, media=media, *args, **kwargs) return _make_safe(wrapper, controller) - diff --git a/mediagoblin/edit/__init__.py b/mediagoblin/edit/__init__.py index 576bd0f5..ba347c69 100644 --- a/mediagoblin/edit/__init__.py +++ b/mediagoblin/edit/__init__.py @@ -13,5 +13,3 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. - - diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index 17244831..f3ebebe8 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -120,7 +120,7 @@ def edit_attachments(request, media): name=request.POST['attachment_name'] \ or request.POST['attachment_file'].filename, filepath=attachment_public_filepath, - created=datetime.utcnow() + created=datetime.utcnow(), )) media.save() diff --git a/mediagoblin/gmg_commands/__init__.py b/mediagoblin/gmg_commands/__init__.py index 10c30385..04187ff2 100644 --- a/mediagoblin/gmg_commands/__init__.py +++ b/mediagoblin/gmg_commands/__init__.py @@ -29,7 +29,7 @@ SUBCOMMAND_MAP = { 'setup': 'mediagoblin.gmg_commands.migrate:migrate_parser_setup', 'func': 'mediagoblin.gmg_commands.migrate:migrate', 'help': 'Apply all unapplied bulk migrations to the database'}, - 'adduser':{ + 'adduser': { 'setup': 'mediagoblin.gmg_commands.users:adduser_parser_setup', 'func': 'mediagoblin.gmg_commands.users:adduser', 'help': 'Creates an user'}, @@ -68,7 +68,7 @@ def main_cli(): subparsers = parser.add_subparsers(help='sub-command help') for command_name, command_struct in SUBCOMMAND_MAP.iteritems(): - if command_struct.has_key('help'): + if 'help' in command_struct: subparser = subparsers.add_parser( command_name, help=command_struct['help']) else: @@ -94,4 +94,3 @@ def main_cli(): if __name__ == '__main__': main_cli() - diff --git a/mediagoblin/gmg_commands/import_export.py b/mediagoblin/gmg_commands/import_export.py index 78d30713..a46219a0 100644 --- a/mediagoblin/gmg_commands/import_export.py +++ b/mediagoblin/gmg_commands/import_export.py @@ -88,7 +88,7 @@ def _import_database(db, args): args.mongorestore_path, '-d', db.name, os.path.join(args._cache_path['database'], db.name)]) - + p.wait() _log.info('...Database imported') @@ -226,7 +226,8 @@ def env_export(args): ''' if args.cache_path: if os.path.exists(args.cache_path): - _log.error('The cache directory must not exist before you run this script') + _log.error('The cache directory must not exist ' + 'before you run this script') _log.error('Cache directory: {0}'.format(args.cache_path)) return False @@ -242,7 +243,7 @@ def env_export(args): globa_config, app_config = setup_global_and_app_config(args.conf_file) setup_storage() - + connection, db = setup_connection_and_db_from_config( app_config, use_pymongo=True) diff --git a/mediagoblin/gmg_commands/migrate.py b/mediagoblin/gmg_commands/migrate.py index fad9b363..beea109d 100644 --- a/mediagoblin/gmg_commands/migrate.py +++ b/mediagoblin/gmg_commands/migrate.py @@ -53,13 +53,13 @@ def migrate(args): for collection, index_name in removed_indexes: print "Removed index '%s' in collection '%s'" % ( index_name, collection) - + # Migrate print "\n== Applying migrations... ==" migration_manager.migrate_new( pre_callback=_print_started_migration, post_callback=_print_finished_migration) - + # Add new indexes print "\n== Adding new indexes... ==" new_indexes = db_util.add_new_indexes(db) diff --git a/mediagoblin/gmg_commands/users.py b/mediagoblin/gmg_commands/users.py index 345c3e5c..4c4b0c1b 100644 --- a/mediagoblin/gmg_commands/users.py +++ b/mediagoblin/gmg_commands/users.py @@ -38,7 +38,7 @@ def adduser(args): db = mg_globals.database users_with_username = \ db.User.find({ - 'username': args.username.lower() + 'username': args.username.lower(), }).count() if users_with_username: @@ -68,7 +68,7 @@ def makeadmin(args): db = mg_globals.database - user = db.User.one({'username':unicode(args.username.lower())}) + user = db.User.one({'username': unicode(args.username.lower())}) if user: user['is_admin'] = True user.save() @@ -91,11 +91,10 @@ def changepw(args): db = mg_globals.database - user = db.User.one({'username':unicode(args.username.lower())}) + user = db.User.one({'username': unicode(args.username.lower())}) if user: user['pw_hash'] = auth_lib.bcrypt_gen_password_hash(args.password) user.save() print 'Password successfully changed' else: print 'The user doesn\'t exist' - diff --git a/mediagoblin/init/__init__.py b/mediagoblin/init/__init__.py index b7f52595..08a0618d 100644 --- a/mediagoblin/init/__init__.py +++ b/mediagoblin/init/__init__.py @@ -29,8 +29,12 @@ from mediagoblin.workbench import WorkbenchManager from mediagoblin.storage import storage_system_from_config -class Error(Exception): pass -class ImproperlyConfigured(Error): pass +class Error(Exception): + pass + + +class ImproperlyConfigured(Error): + pass def setup_global_and_app_config(config_path): @@ -76,8 +80,8 @@ def setup_database(): "in fact they appear to be from the future?!") setup_globals( - db_connection = connection, - database = db) + db_connection=connection, + database=db) return connection, db @@ -99,10 +103,10 @@ def get_jinja_loader(user_template_path=None): def get_staticdirector(app_config): - if app_config.has_key('direct_remote_path'): + if 'direct_remote_path' in app_config: return staticdirect.RemoteStaticDirect( app_config['direct_remote_path'].strip()) - elif app_config.has_key('direct_remote_paths'): + elif 'direct_remote_paths' in app_config: direct_remote_path_lines = app_config[ 'direct_remote_paths'].strip().splitlines() return staticdirect.MultiRemoteStaticDirect( @@ -126,8 +130,8 @@ def setup_storage(): queue_store = storage_system_from_config(global_config[key_long]) setup_globals( - public_store = public_store, - queue_store = queue_store) + public_store=public_store, + queue_store=queue_store) return public_store, queue_store @@ -137,7 +141,7 @@ def setup_workbench(): workbench_manager = WorkbenchManager(app_config['workbench_path']) - setup_globals(workbench_manager = workbench_manager) + setup_globals(workbench_manager=workbench_manager) def setup_beaker_cache(): diff --git a/mediagoblin/init/celery/__init__.py b/mediagoblin/init/celery/__init__.py index c58b1305..f7ef9f39 100644 --- a/mediagoblin/init/celery/__init__.py +++ b/mediagoblin/init/celery/__init__.py @@ -40,25 +40,25 @@ def setup_celery_from_config(app_config, global_config, - set_environ: if set, this will CELERY_CONFIG_MODULE to the settings_module """ - if global_config.has_key('celery'): + if 'celery' in global_config: celery_conf = global_config['celery'] else: celery_conf = {} - + celery_settings = {} # set up mongodb stuff celery_settings['CELERY_RESULT_BACKEND'] = 'mongodb' - if not celery_settings.has_key('BROKER_BACKEND'): + if 'BROKER_BACKEND' not in celery_settings: celery_settings['BROKER_BACKEND'] = 'mongodb' celery_mongo_settings = {} - if app_config.has_key('db_host'): + if 'db_host' in app_config: celery_mongo_settings['host'] = app_config['db_host'] if celery_settings['BROKER_BACKEND'] == 'mongodb': celery_settings['BROKER_HOST'] = app_config['db_host'] - if app_config.has_key('db_port'): + if 'db_port' in app_config: celery_mongo_settings['port'] = app_config['db_port'] if celery_settings['BROKER_BACKEND'] == 'mongodb': celery_settings['BROKER_PORT'] = app_config['db_port'] @@ -84,6 +84,6 @@ def setup_celery_from_config(app_config, global_config, for key, value in celery_settings.iteritems(): setattr(this_module, key, value) - + if set_environ: os.environ['CELERY_CONFIG_MODULE'] = settings_module diff --git a/mediagoblin/init/celery/from_celery.py b/mediagoblin/init/celery/from_celery.py index 3e5adb98..05669b67 100644 --- a/mediagoblin/init/celery/from_celery.py +++ b/mediagoblin/init/celery/from_celery.py @@ -44,7 +44,7 @@ def setup_self(check_environ_for_conf=True, module_name=OUR_MODULENAME, if not os.path.exists(mgoblin_conf_file): raise IOError( "MEDIAGOBLIN_CONFIG not set or file does not exist") - + # By setting the environment variable here we should ensure that # this is the module that gets set up. os.environ['CELERY_CONFIG_MODULE'] = module_name diff --git a/mediagoblin/init/config.py b/mediagoblin/init/config.py index 029a0956..ae232e91 100644 --- a/mediagoblin/init/config.py +++ b/mediagoblin/init/config.py @@ -73,7 +73,7 @@ def read_mediagoblin_config(config_path, config_spec=CONFIG_SPEC_PATH): # For now the validator just works with the default functions, # but in the future if we want to add additional validation/configuration # functions we'd add them to validator.functions here. - # + # # See also: # http://www.voidspace.org.uk/python/validate.html#adding-functions validator = Validator() diff --git a/mediagoblin/listings/routing.py b/mediagoblin/listings/routing.py index b72bd015..234f2595 100644 --- a/mediagoblin/listings/routing.py +++ b/mediagoblin/listings/routing.py @@ -25,4 +25,3 @@ tag_routes = [ Route('mediagoblin.listings.tag_atom_feed', "/{tag}/atom/", controller="mediagoblin.listings.views:tag_atom_feed"), ] - diff --git a/mediagoblin/listings/views.py b/mediagoblin/listings/views.py index 01aad803..12e539e7 100644 --- a/mediagoblin/listings/views.py +++ b/mediagoblin/listings/views.py @@ -47,7 +47,7 @@ def tag_listing(request, page): {u'state': u'processed', u'tags.slug': tag_slug}) cursor = cursor.sort('created', DESCENDING) - + pagination = Pagination(page, cursor) media_entries = pagination() @@ -64,6 +64,7 @@ def tag_listing(request, page): ATOM_DEFAULT_NR_OF_UPDATED_ITEMS = 15 + def tag_atom_feed(request): """ generates the atom feed with the tag images diff --git a/mediagoblin/messages.py b/mediagoblin/messages.py index dc82fbf6..054d46c0 100644 --- a/mediagoblin/messages.py +++ b/mediagoblin/messages.py @@ -20,11 +20,13 @@ SUCCESS = 'success' WARNING = 'warning' ERROR = 'error' + def add_message(request, level, text): messages = request.session.setdefault('messages', []) messages.append({'level': level, 'text': text}) request.session.save() + def fetch_messages(request, clear_from_session=True): messages = request.session.get('messages') if messages and clear_from_session: diff --git a/mediagoblin/middleware/noop.py b/mediagoblin/middleware/noop.py index 28380232..820b5d9e 100644 --- a/mediagoblin/middleware/noop.py +++ b/mediagoblin/middleware/noop.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. + class NoOpMiddleware(object): def __init__(self, mg_app): diff --git a/mediagoblin/process_media/__init__.py b/mediagoblin/process_media/__init__.py index f63fb2b0..3d6b418f 100644 --- a/mediagoblin/process_media/__init__.py +++ b/mediagoblin/process_media/__init__.py @@ -66,9 +66,10 @@ class ProcessMedia(Task): """ If the processing failed we should mark that in the database. - Assuming that the exception raised is a subclass of BaseProcessingFail, - we can use that to get more information about the failure and store that - for conveying information to users about the failure, etc. + Assuming that the exception raised is a subclass of + BaseProcessingFail, we can use that to get more information + about the failure and store that for conveying information to + users about the failure, etc. """ entry_id = args[0] mark_entry_failed(entry_id, exc) @@ -81,10 +82,10 @@ def mark_entry_failed(entry_id, exc): """ Mark a media entry as having failed in its conversion. - Uses the exception that was raised to mark more information. If the - exception is a derivative of BaseProcessingFail then we can store extra - information that can be useful for users telling them why their media failed - to process. + Uses the exception that was raised to mark more information. If + the exception is a derivative of BaseProcessingFail then we can + store extra information that can be useful for users telling them + why their media failed to process. Args: - entry_id: The id of the media entry @@ -161,7 +162,8 @@ def process_image(entry): with queued_file: original_filepath = create_pub_filepath(entry, queued_filepath[-1]) - with mgg.public_store.get_file(original_filepath, 'wb') as original_file: + with mgg.public_store.get_file(original_filepath, 'wb') \ + as original_file: original_file.write(queued_file.read()) mgg.queue_store.delete_file(queued_filepath) diff --git a/mediagoblin/process_media/errors.py b/mediagoblin/process_media/errors.py index 8003ffaf..4224a3e1 100644 --- a/mediagoblin/process_media/errors.py +++ b/mediagoblin/process_media/errors.py @@ -16,17 +16,18 @@ from mediagoblin.tools.translate import lazy_pass_to_ugettext as _ + class BaseProcessingFail(Exception): """ Base exception that all other processing failure messages should subclass from. - + You shouldn't call this itself; instead you should subclass it and provid the exception_path and general_message applicable to this error. """ general_message = u'' - + @property def exception_path(self): return u"%s:%s" % ( @@ -34,8 +35,8 @@ class BaseProcessingFail(Exception): def __init__(self, **metadata): self.metadata = metadata or {} - - + + class BadMediaFail(BaseProcessingFail): """ Error that should be raised when an inappropriate file was given diff --git a/mediagoblin/staticdirect.py b/mediagoblin/staticdirect.py index 58175881..c6d2b374 100644 --- a/mediagoblin/staticdirect.py +++ b/mediagoblin/staticdirect.py @@ -21,24 +21,24 @@ import urlparse # Staticdirect infrastructure. # Borrowed largely from cc.engine # by Chris Webber & Creative Commons -# +# # This needs documentation! #################################### import pkg_resources import urlparse + class StaticDirect(object): def __init__(self): self.cache = {} def __call__(self, filepath): - if self.cache.has_key(filepath): + if filepath in self.cache: return self.cache[filepath] static_direction = self.cache[filepath] = self.get(filepath) return static_direction - def get(self, filepath): # should be implemented by the individual staticdirector diff --git a/mediagoblin/storage/cloudfiles.py b/mediagoblin/storage/cloudfiles.py index b1dd9450..0d3cc3df 100644 --- a/mediagoblin/storage/cloudfiles.py +++ b/mediagoblin/storage/cloudfiles.py @@ -27,6 +27,7 @@ from mediagoblin.storage import StorageInterface, clean_listy_filepath import cloudfiles import mimetypes + class CloudFilesStorage(StorageInterface): ''' OpenStack/Rackspace Cloud's Swift/CloudFiles support diff --git a/mediagoblin/submit/__init__.py b/mediagoblin/submit/__init__.py index 576bd0f5..ba347c69 100644 --- a/mediagoblin/submit/__init__.py +++ b/mediagoblin/submit/__init__.py @@ -13,5 +13,3 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. - - diff --git a/mediagoblin/submit/security.py b/mediagoblin/submit/security.py index 9d62a36e..6708baf7 100644 --- a/mediagoblin/submit/security.py +++ b/mediagoblin/submit/security.py @@ -16,9 +16,9 @@ from mimetypes import guess_type - ALLOWED = ['image/jpeg', 'image/png', 'image/tiff', 'image/gif'] + def check_filetype(posted_file): if not guess_type(posted_file.filename)[0] in ALLOWED: return False diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 7134235e..25f7d79d 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -39,7 +39,7 @@ def submit_start(request): submit_form = submit_forms.SubmitStartForm(request.POST) if request.method == 'POST' and submit_form.validate(): - if not (request.POST.has_key('file') + if not ('file' in request.POST and isinstance(request.POST['file'], FieldStorage) and request.POST['file'].file): submit_form.file.errors.append( @@ -60,8 +60,8 @@ def submit_start(request): entry['description'] = unicode(request.POST.get('description')) entry['description_html'] = cleaned_markdown_conversion( entry['description']) - - entry['media_type'] = u'image' # heh + + entry['media_type'] = u'image' # heh entry['uploader'] = request.user['_id'] # Process the user's folksonomy "tags" @@ -89,8 +89,10 @@ def submit_start(request): # We generate this ourselves so we know what the taks id is for # retrieval later. - # (If we got it off the task's auto-generation, there'd be a risk of - # a race condition when we'd save after sending off the task) + + # (If we got it off the task's auto-generation, there'd be + # a risk of a race condition when we'd save after sending + # off the task) task_id = unicode(uuid.uuid4()) entry['queued_task_id'] = task_id @@ -112,8 +114,8 @@ def submit_start(request): # expect a lot of users to run things in this way we have to # capture stuff here. # - # ... not completely the diaper pattern because the exception is - # re-raised :) + # ... not completely the diaper pattern because the + # exception is re-raised :) mark_entry_failed(entry[u'_id'], exc) # re-raise the exception raise @@ -121,7 +123,7 @@ def submit_start(request): add_message(request, SUCCESS, _('Woohoo! Submitted!')) return redirect(request, "mediagoblin.user_pages.user_home", - user = request.user['username']) + user=request.user['username']) return render_to_response( request, diff --git a/mediagoblin/tools/common.py b/mediagoblin/tools/common.py index ea4541a8..12d8309e 100644 --- a/mediagoblin/tools/common.py +++ b/mediagoblin/tools/common.py @@ -21,6 +21,7 @@ DISPLAY_IMAGE_FETCHING_ORDER = [u'medium', u'original', u'thumb'] global TESTS_ENABLED TESTS_ENABLED = False + def import_component(import_string): """ Import a module component defined by STRING. Probably a method, diff --git a/mediagoblin/tools/mail.py b/mediagoblin/tools/mail.py index 826acdbf..9e00be7d 100644 --- a/mediagoblin/tools/mail.py +++ b/mediagoblin/tools/mail.py @@ -24,7 +24,7 @@ from mediagoblin.tools import common ### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # We have two "test inboxes" here: -# +# # EMAIL_TEST_INBOX: # ---------------- # If you're writing test views, you'll probably want to check this. @@ -44,11 +44,12 @@ from mediagoblin.tools import common # ***IMPORTANT!*** # ---------------- # Before running tests that call functions which send email, you should -# always call _clear_test_inboxes() to "wipe" the inboxes clean. +# always call _clear_test_inboxes() to "wipe" the inboxes clean. EMAIL_TEST_INBOX = [] EMAIL_TEST_MBOX_INBOX = [] + class FakeMhost(object): """ Just a fake mail host so we can capture and test messages @@ -63,12 +64,14 @@ class FakeMhost(object): 'to': to_addrs, 'message': message}) + def _clear_test_inboxes(): global EMAIL_TEST_INBOX global EMAIL_TEST_MBOX_INBOX EMAIL_TEST_INBOX = [] EMAIL_TEST_MBOX_INBOX = [] + ### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ### </Special email test stuff> ### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/mediagoblin/tools/pagination.py b/mediagoblin/tools/pagination.py index 3ea96e6d..bc20ec90 100644 --- a/mediagoblin/tools/pagination.py +++ b/mediagoblin/tools/pagination.py @@ -19,8 +19,10 @@ import copy from math import ceil, floor from itertools import izip, count + PAGINATION_DEFAULT_PER_PAGE = 30 + class Pagination(object): """ Pagination class for mongodb queries. @@ -37,9 +39,9 @@ class Pagination(object): Args: - page: requested page - per_page: number of objects per page - - cursor: db cursor - - jump_to_id: ObjectId, sets the page to the page containing the object - with _id == jump_to_id. + - cursor: db cursor + - jump_to_id: ObjectId, sets the page to the page containing the + object with _id == jump_to_id. """ self.page = page self.per_page = per_page @@ -91,19 +93,19 @@ class Pagination(object): last = num def get_page_url_explicit(self, base_url, get_params, page_no): - """ + """ Get a page url by adding a page= parameter to the base url - """ + """ new_get_params = copy.copy(get_params or {}) new_get_params['page'] = page_no return "%s?%s" % ( base_url, urllib.urlencode(new_get_params)) def get_page_url(self, request, page_no): - """ + """ Get a new page url based of the request, and the new page number. This is a nice wrapper around get_page_url_explicit() - """ + """ return self.get_page_url_explicit( request.full_path, request.GET, page_no) diff --git a/mediagoblin/tools/response.py b/mediagoblin/tools/response.py index 1477b9bc..b01d31a2 100644 --- a/mediagoblin/tools/response.py +++ b/mediagoblin/tools/response.py @@ -17,12 +17,14 @@ from webob import Response, exc from mediagoblin.tools.template import render_template + def render_to_response(request, template, context, status=200): """Much like Django's shortcut.render()""" return Response( render_template(request, template, context), status=status) + def render_404(request): """ Render a 404. @@ -30,9 +32,10 @@ def render_404(request): return render_to_response( request, 'mediagoblin/404.html', {}, status=400) + def redirect(request, *args, **kwargs): """Returns a HTTPFound(), takes a request and then urlgen params""" - + querystring = None if kwargs.get('querystring'): querystring = kwargs.get('querystring') diff --git a/mediagoblin/tools/template.py b/mediagoblin/tools/template.py index a773ca99..905a36df 100644 --- a/mediagoblin/tools/template.py +++ b/mediagoblin/tools/template.py @@ -17,18 +17,19 @@ from math import ceil import jinja2 from babel.localedata import exists -from babel.support import LazyProxy from mediagoblin import mg_globals from mediagoblin import messages from mediagoblin.tools import common from mediagoblin.tools.translate import setup_gettext from mediagoblin.middleware.csrf import render_csrf_form_token + SETUP_JINJA_ENVS = {} + def get_jinja_env(template_loader, locale): """ - Set up the Jinja environment, + Set up the Jinja environment, (In the future we may have another system for providing theming; for now this is good enough.) @@ -60,6 +61,7 @@ def get_jinja_env(template_loader, locale): return template_env + # We'll store context information here when doing unit tests TEMPLATE_TEST_CONTEXT = {} @@ -76,8 +78,8 @@ def render_template(request, template_path, context): context['request'] = request context['csrf_token'] = render_csrf_form_token(request) rendered = template.render(context) - - if common.TESTS_ENABLED: + + if common.TESTS_ENABLED: TEMPLATE_TEST_CONTEXT[template_path] = context return rendered @@ -87,6 +89,7 @@ def clear_test_template_context(): global TEMPLATE_TEST_CONTEXT TEMPLATE_TEST_CONTEXT = {} + def gridify_list(this_list, num_cols=5): """ Generates a list of lists where each sub-list's length depends on diff --git a/mediagoblin/tools/text.py b/mediagoblin/tools/text.py index de4bb281..be1adb00 100644 --- a/mediagoblin/tools/text.py +++ b/mediagoblin/tools/text.py @@ -21,6 +21,7 @@ from lxml.html.clean import Cleaner from mediagoblin import mg_globals from mediagoblin.tools import url + # A super strict version of the lxml.html cleaner class HTML_CLEANER = Cleaner( scripts=True, @@ -42,6 +43,7 @@ HTML_CLEANER = Cleaner( host_whitelist=(), whitelist_tags=set([])) + def clean_html(html): # clean_html barfs on an empty string if not html: @@ -49,6 +51,7 @@ def clean_html(html): return HTML_CLEANER.clean_html(html) + def convert_to_tag_list_of_dicts(tag_string): """ Filter input from incoming string containing user tags, @@ -73,6 +76,7 @@ def convert_to_tag_list_of_dicts(tag_string): 'slug': url.slugify(tag.strip())}) return taglist + def media_tags_as_string(media_entry_tags): """ Generate a string from a media item's tags, stored as a list of dicts @@ -85,9 +89,11 @@ def media_tags_as_string(media_entry_tags): [tag['name'] for tag in media_entry_tags]) return media_tag_string + TOO_LONG_TAG_WARNING = \ u'Tags must be shorter than %s characters. Tags that are too long: %s' + def tag_length_validator(form, field): """ Make sure tags do not exceed the maximum tag length. @@ -105,6 +111,7 @@ def tag_length_validator(form, field): MARKDOWN_INSTANCE = markdown.Markdown(safe_mode='escape') + def cleaned_markdown_conversion(text): """ Take a block of text, run it through MarkDown, and clean its HTML. diff --git a/mediagoblin/tools/url.py b/mediagoblin/tools/url.py index 458ef2c8..78b5dd63 100644 --- a/mediagoblin/tools/url.py +++ b/mediagoblin/tools/url.py @@ -17,8 +17,10 @@ import re import translitcodec + _punct_re = re.compile(r'[\t !"#$%&\'()*\-/<=>?@\[\\\]^_`{|},.]+') + def slugify(text, delim=u'-'): """ Generates an ASCII-only slug. Taken from http://flask.pocoo.org/snippets/5/ diff --git a/mediagoblin/user_pages/__init__.py b/mediagoblin/user_pages/__init__.py index 576bd0f5..ba347c69 100644 --- a/mediagoblin/user_pages/__init__.py +++ b/mediagoblin/user_pages/__init__.py @@ -13,5 +13,3 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. - - diff --git a/mediagoblin/user_pages/views.py b/mediagoblin/user_pages/views.py index 484c1e28..2090d6fd 100644 --- a/mediagoblin/user_pages/views.py +++ b/mediagoblin/user_pages/views.py @@ -54,7 +54,7 @@ def user_home(request, page): #if no data is available, return NotFound if media_entries == None: return render_404(request) - + user_gallery_url = request.urlgen( 'mediagoblin.user_pages.user_gallery', user=user['username']) @@ -67,6 +67,7 @@ def user_home(request, page): 'media_entries': media_entries, 'pagination': pagination}) + @uses_pagination def user_gallery(request, page): """'Gallery' of a User()""" @@ -86,7 +87,7 @@ def user_gallery(request, page): #if no data is available, return NotFound if media_entries == None: return render_404(request) - + return render_to_response( request, 'mediagoblin/user_pages/gallery.html', @@ -96,6 +97,7 @@ def user_gallery(request, page): MEDIA_COMMENTS_PER_PAGE = 50 + @get_user_media_entry @uses_pagination def media_home(request, media, page, **kwargs): @@ -192,6 +194,7 @@ def media_confirm_delete(request, media): ATOM_DEFAULT_NR_OF_UPDATED_ITEMS = 15 + def atom_feed(request): """ generates the atom feed with the newest images @@ -212,7 +215,7 @@ def atom_feed(request): feed = AtomFeed(request.matchdict['user'], feed_url=request.url, url=request.host_url) - + for entry in cursor: feed.add(entry.get('title'), entry.get('description_html'), diff --git a/mediagoblin/views.py b/mediagoblin/views.py index 22f9268d..ecf5b723 100644 --- a/mediagoblin/views.py +++ b/mediagoblin/views.py @@ -20,6 +20,7 @@ from mediagoblin.tools.response import render_to_response from mediagoblin.db.util import DESCENDING from mediagoblin.decorators import uses_pagination + @uses_pagination def root_view(request, page): cursor = request.db.MediaEntry.find( diff --git a/mediagoblin/workbench.py b/mediagoblin/workbench.py index 722f8e27..60a79f47 100644 --- a/mediagoblin/workbench.py +++ b/mediagoblin/workbench.py @@ -42,8 +42,10 @@ class Workbench(object): def __unicode__(self): return unicode(self.dir) + def __str__(self): return str(self.dir) + def __repr__(self): return repr(self.dir) @@ -140,7 +142,7 @@ class WorkbenchManager(object): self.base_workbench_dir = os.path.abspath(base_workbench_dir) if not os.path.exists(self.base_workbench_dir): os.makedirs(self.base_workbench_dir) - + def create_workbench(self): """ Create and return the path to a new workbench (directory). @@ -29,16 +29,17 @@ def get_version(): if mo: return mo.group(1) else: - raise RuntimeError("Unable to find version string in %s." % VERSIONFILE) + raise RuntimeError("Unable to find version string in %s." % + VERSIONFILE) setup( - name = "mediagoblin", - version = get_version(), + name="mediagoblin", + version=get_version(), packages=find_packages(exclude=['ez_setup', 'examples', 'tests']), zip_safe=False, # scripts and dependencies - install_requires = [ + install_requires=[ 'setuptools', 'PasteScript', 'beaker', @@ -66,7 +67,7 @@ setup( # 'lxml', ], test_suite='nose.collector', - entry_points = """\ + entry_points="""\ [console_scripts] gmg = mediagoblin.gmg_commands:main_cli pybabel = mediagoblin.babel.messages.frontend:main @@ -83,7 +84,6 @@ setup( [babel.extractors] jinja2 = jinja2.ext:babel_extract """, - license='AGPLv3', author='Free Software Foundation and contributors', author_email='cwebber@gnu.org', |