From 285ffeddf3542201b83072d3be544c85e9c487c2 Mon Sep 17 00:00:00 2001 From: Nathan Yergler Date: Sat, 1 Oct 2011 15:10:41 -0700 Subject: [PATCH] has_key is deprecated, converting uses to use "in" operator. --- mediagoblin/auth/views.py | 4 ++-- mediagoblin/db/util.py | 2 +- mediagoblin/gmg_commands/__init__.py | 2 +- mediagoblin/init/__init__.py | 4 ++-- mediagoblin/init/celery/__init__.py | 10 +++++----- mediagoblin/staticdirect.py | 6 +++--- mediagoblin/submit/views.py | 2 +- mediagoblin/util.py | 16 ++++++++-------- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/mediagoblin/auth/views.py b/mediagoblin/auth/views.py index afcfcf1e..adf2c315 100644 --- a/mediagoblin/auth/views.py +++ b/mediagoblin/auth/views.py @@ -146,7 +146,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( @@ -307,6 +307,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/util.py b/mediagoblin/db/util.py index 38f0233f..52e97f6d 100644 --- a/mediagoblin/db/util.py +++ b/mediagoblin/db/util.py @@ -148,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/gmg_commands/__init__.py b/mediagoblin/gmg_commands/__init__.py index b3f69ccc..3250c246 100644 --- a/mediagoblin/gmg_commands/__init__.py +++ b/mediagoblin/gmg_commands/__init__.py @@ -61,7 +61,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: diff --git a/mediagoblin/init/__init__.py b/mediagoblin/init/__init__.py index f21e2fdd..08a0618d 100644 --- a/mediagoblin/init/__init__.py +++ b/mediagoblin/init/__init__.py @@ -103,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( diff --git a/mediagoblin/init/celery/__init__.py b/mediagoblin/init/celery/__init__.py index 21ce1d39..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'] 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/submit/views.py b/mediagoblin/submit/views.py index 22a13b6d..d450ca21 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -40,7 +40,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( diff --git a/mediagoblin/util.py b/mediagoblin/util.py index 4132b497..d6ce5930 100644 --- a/mediagoblin/util.py +++ b/mediagoblin/util.py @@ -89,7 +89,7 @@ def get_jinja_env(template_loader, locale): # If we have a jinja environment set up with this locale, just # return that one. - if SETUP_JINJA_ENVS.has_key(locale): + if locale in SETUP_JINJA_ENVS: return SETUP_JINJA_ENVS[locale] template_env = jinja2.Environment( @@ -166,7 +166,7 @@ def setup_user_in_request(request): Examine a request and tack on a request.user parameter if that's appropriate. """ - if not request.session.has_key('user_id'): + if not 'user_id' in request.session: request.user = None return @@ -356,7 +356,7 @@ def get_locale_from_request(request): """ request_form = request.GET or request.POST - if request_form.has_key('lang'): + if 'lang' in request_form: return locale_to_lower_upper(request_form['lang']) accept_lang_matches = request.accept_language.best_matches() @@ -364,9 +364,9 @@ def get_locale_from_request(request): # Your routing can explicitly specify a target language matchdict = request.matchdict or {} - if matchdict.has_key('locale'): + if 'locale' in matchdict: target_lang = matchdict['locale'] - elif request.session.has_key('target_lang'): + elif 'target_lang' in request.session: target_lang = request.session['target_lang'] # Pull the first acceptable language elif accept_lang_matches: @@ -393,9 +393,9 @@ HTML_CLEANER = Cleaner( annoying_tags=True, allow_tags=[ 'div', 'b', 'i', 'em', 'strong', 'p', 'ul', 'ol', 'li', 'a', 'br'], - remove_unknown_tags=False, # can't be used with allow_tags + remove_unknown_tags=False, # can't be used with allow_tags safe_attrs_only=True, - add_nofollow=True, # for now + add_nofollow=True, # for now host_whitelist=(), whitelist_tags=set([])) @@ -492,7 +492,7 @@ def setup_gettext(locale): # TODO: fallback nicely on translations from pt_PT to pt if not # available, etc. - if SETUP_GETTEXTS.has_key(locale): + if locale in SETUP_GETTEXTS: this_gettext = SETUP_GETTEXTS[locale] else: this_gettext = gettext.translation( -- 2.25.1