Skip to content

Commit

Permalink
Merge pull request #3314 from deinok/pep8
Browse files Browse the repository at this point in the history
Pep8 - BugFixing
  • Loading branch information
wardi committed Nov 17, 2016
2 parents 7a976fe + 35aee1a commit 9b5bf5d
Show file tree
Hide file tree
Showing 39 changed files with 252 additions and 233 deletions.
1 change: 1 addition & 0 deletions ckan/common.py
Expand Up @@ -107,6 +107,7 @@ def __delitem__(self, key):
except TypeError:
pass


local = Local()

# This a proxy to the bounded config object
Expand Down
1 change: 1 addition & 0 deletions ckan/config/middleware/__init__.py
Expand Up @@ -25,6 +25,7 @@ def custom_charset__set(self, charset):
if self.environ.get('CONTENT_TYPE', '').startswith(';'):
self.environ['CONTENT_TYPE'] = ''


webob.request.BaseRequest._charset__set = custom_charset__set

webob.request.BaseRequest.charset = property(
Expand Down
4 changes: 2 additions & 2 deletions ckan/controllers/api.py
Expand Up @@ -181,8 +181,8 @@ def action(self, logic_function, ver=None):
}
try:
side_effect_free = getattr(function, 'side_effect_free', False)
request_data = self._get_request_data(try_url_params=
side_effect_free)
request_data = self._get_request_data(
try_url_params=side_effect_free)
except ValueError, inst:
log.info('Bad Action API request data: %s', inst)
return self._finish_bad_request(
Expand Down
10 changes: 4 additions & 6 deletions ckan/controllers/feed.py
Expand Up @@ -24,16 +24,14 @@
import logging
import urlparse

import webhelpers.feedgenerator
from ckan.common import config

import ckan.model as model
import ckan.lib.base as base
import ckan.lib.helpers as h
import ckan.logic as logic
import ckan.model as model
import ckan.plugins as plugins

import webhelpers.feedgenerator
from ckan.common import _, g, c, request, response, json
from ckan.common import config

# TODO make the item list configurable
ITEMS_LIMIT = 20
Expand Down Expand Up @@ -417,7 +415,7 @@ def output_feed(self, results, feed_title, feed_description,
response.content_type = feed.mime_type
return feed.writeString('utf-8')

#### CLASS PRIVATE METHODS ####
# CLASS PRIVATE METHODS #

def _feed_url(self, query, controller, action, **kwargs):
"""
Expand Down
16 changes: 8 additions & 8 deletions ckan/controllers/group.py
Expand Up @@ -40,7 +40,7 @@ class GroupController(base.BaseController):

group_types = ['group']

## hooks for subclasses
# hooks for subclasses

def _group_form(self, group_type=None):
return lookup_group_plugin(group_type).group_form()
Expand Down Expand Up @@ -84,7 +84,7 @@ def _admins_template(self, group_type):
def _bulk_process_template(self, group_type):
return lookup_group_plugin(group_type).bulk_process_template()

## end hooks
# end hooks
def _replace_group_org(self, string):
''' substitute organization for group if this is an org'''
return string
Expand Down Expand Up @@ -286,7 +286,7 @@ def pager_url(q=None, page=None):
c.fields = []
search_extras = {}
for (param, value) in request.params.items():
if not param in ['q', 'page', 'sort'] \
if param not in ['q', 'page', 'sort'] \
and len(value) and not param.startswith('_'):
if not param.startswith('ext_'):
c.fields.append((param, value))
Expand Down Expand Up @@ -404,7 +404,7 @@ def bulk_process(self, id):
# FIXME: better error
raise Exception('Must be an organization')

#use different form names so that ie7 can be detected
# use different form names so that ie7 can be detected
form_names = set(["bulk_action.public", "bulk_action.delete",
"bulk_action.private"])
actions_in_form = set(request.params.keys())
Expand All @@ -418,13 +418,13 @@ def bulk_process(self, id):
return render(self._bulk_process_template(group_type),
extra_vars={'group_type': group_type})

#ie7 puts all buttons in form params but puts submitted one twice
# ie7 puts all buttons in form params but puts submitted one twice
for key, value in dict(request.params.dict_of_lists()).items():
if len(value) == 2:
action = key.split('.')[-1]
break
else:
#normal good browser form submission
# normal good browser form submission
action = actions.pop().split('.')[-1]

# process the action first find the datasets to perform the action on.
Expand Down Expand Up @@ -660,7 +660,7 @@ def member_new(self, id):
context = {'model': model, 'session': model.Session,
'user': c.user}

#self._check_access('group_delete', context, {'id': id})
# self._check_access('group_delete', context, {'id': id})
try:
data_dict = {'id': id}
data_dict['include_datasets'] = False
Expand Down Expand Up @@ -764,7 +764,7 @@ def history(self, id):
c.group_dict = self._action('group_show')(context, data_dict)
c.group_revisions = self._action('group_revision_list')(context,
data_dict)
#TODO: remove
# TODO: remove
# Still necessary for the authz check in group/layout.html
c.group = context['group']
except (NotFound, NotAuthorized):
Expand Down
12 changes: 6 additions & 6 deletions ckan/controllers/package.py
Expand Up @@ -1157,7 +1157,7 @@ def resource_download(self, id, resource_id, filename=None):
response.headers['Content-Type'] = content_type
response.status = status
return app_iter
elif not 'url' in rsc:
elif 'url' not in rsc:
abort(404, _('No download is available'))
h.redirect_to(rsc['url'])

Expand Down Expand Up @@ -1460,28 +1460,28 @@ def edit_view(self, id, resource_id, view_id=None):
else:
data = get_action('resource_view_create')(context, data)
except ValidationError, e:
## Could break preview if validation error
# Could break preview if validation error
to_preview = False
errors = e.error_dict
error_summary = e.error_summary
except NotAuthorized:
## This should never happen unless the user maliciously changed
## the resource_id in the url.
# This should never happen unless the user maliciously changed
# the resource_id in the url.
abort(403, _('Unauthorized to edit resource'))
else:
if not to_preview:
h.redirect_to(controller='package',
action='resource_views',
id=id, resource_id=resource_id)

## view_id exists only when updating
# view_id exists only when updating
if view_id:
try:
old_data = get_action('resource_view_show')(context,
{'id': view_id})
data = data or old_data
view_type = old_data.get('view_type')
## might as well preview when loading good existing view
# might as well preview when loading good existing view
if not errors:
to_preview = True
except (NotFound, NotAuthorized):
Expand Down
4 changes: 2 additions & 2 deletions ckan/controllers/user.py
Expand Up @@ -57,7 +57,7 @@ def __before__(self, action, **env):
if c.action not in ('login', 'request_reset', 'perform_reset',):
abort(403, _('Not authorized to see this page'))

## hooks for subclasses
# hooks for subclasses
new_user_form = 'user/new_user_form.html'
edit_user_form = 'user/edit_user_form.html'

Expand Down Expand Up @@ -88,7 +88,7 @@ def _setup_template_variables(self, context, data_dict):
c.is_myself = user_dict['name'] == c.user
c.about_formatted = h.render_markdown(user_dict['about'])

## end hooks
# end hooks

def _get_repoze_handler(self, handler_name):
'''Returns the URL that repoze.who will respond to and perform a
Expand Down
2 changes: 1 addition & 1 deletion ckan/lib/auth_tkt.py
@@ -1,5 +1,6 @@
# encoding: utf-8

import logging
import math
import os

Expand All @@ -8,7 +9,6 @@

_bool = repoze_auth_tkt._bool

import logging
log = logging.getLogger(__name__)


Expand Down
4 changes: 2 additions & 2 deletions ckan/lib/base.py
Expand Up @@ -129,7 +129,7 @@ def render_template():
if 'Pragma' in response.headers:
del response.headers["Pragma"]

## Caching Logic
# Caching Logic
allow_cache = True
# Force cache or not if explicit.
if cache_force is not None:
Expand All @@ -146,7 +146,7 @@ def render_template():
# Don't cache if we have set the __no_cache__ param in the query string.
elif request.params.get('__no_cache__'):
allow_cache = False
# Don't cache if we have extra vars containing data.
# Don't cache if we have extra vars containing data.
elif extra_vars:
for k, v in extra_vars.iteritems():
allow_cache = False
Expand Down
5 changes: 2 additions & 3 deletions ckan/lib/celery_app.py
Expand Up @@ -7,9 +7,10 @@
'''

import ConfigParser
import os
import logging
import os

from celery import Celery
from ckan.common import config as ckan_config
from pkg_resources import iter_entry_points, VersionConflict

Expand All @@ -19,8 +20,6 @@

LIST_PARAMS = """CELERY_IMPORTS ADMINS ROUTES""".split()

from celery import Celery

celery = Celery()

config = ConfigParser.ConfigParser()
Expand Down
6 changes: 6 additions & 0 deletions ckan/lib/helpers.py
Expand Up @@ -472,6 +472,7 @@ def pop_messages(self):
def are_there_messages(self):
return bool(session.get(self.session_key))


flash = _Flash()
# this is here for backwards compatability
_flash = flash
Expand Down Expand Up @@ -1031,6 +1032,7 @@ def linked_gravatar(email_hash, size=100, default=None):
'%s</a>' % gravatar(email_hash, size, default)
)


_VALID_GRAVATAR_DEFAULTS = ['404', 'mm', 'identicon', 'monsterid',
'wavatar', 'retro']

Expand Down Expand Up @@ -1443,6 +1445,7 @@ def process_names(items):
items.append(item)
return items


# these are the types of objects that can be followed
_follow_objects = ['dataset', 'user', 'group']

Expand Down Expand Up @@ -1771,6 +1774,7 @@ def get_request_param(parameter_name, default=None):
searches. '''
return request.params.get(parameter_name, default)


# find all inner text of html eg `<b>moo</b>` gets `moo` but not of <a> tags
# as this would lead to linkifying links if they are urls.
RE_MD_GET_INNER_HTML = re.compile(
Expand Down Expand Up @@ -2078,6 +2082,7 @@ def SI_number_span(number):
+ '">')
return output + formatters.localised_SI_number(number) + literal('</span>')


# add some formatter functions
localised_number = formatters.localised_number
localised_SI_number = formatters.localised_SI_number
Expand Down Expand Up @@ -2178,6 +2183,7 @@ def get_site_statistics():
logic.get_action('organization_list')({}, {}))
return stats


_RESOURCE_FORMATS = None


Expand Down
1 change: 1 addition & 0 deletions ckan/lib/i18n.py
Expand Up @@ -145,6 +145,7 @@ def _get_locales():

return ordered_list


available_locales = None
locales = None
locales_dict = None
Expand Down
21 changes: 10 additions & 11 deletions ckan/lib/munge.py
Expand Up @@ -5,13 +5,12 @@
# packages changing name on reimport, but these ones can be changed and
# improved.

import re
import os.path
import re

from ckan import model
from ckan.lib.io import decode_path


# Maximum length of a filename's extension (including the '.')
MAX_FILENAME_EXTENSION_LENGTH = 21

Expand Down Expand Up @@ -95,15 +94,15 @@ def substitute_ascii_equivalents(text_unicode):
0xf2: 'o', 0xf3: 'o', 0xf4: 'o', 0xf5: 'o', 0xf6: 'o', 0xf8: 'o',
0xf9: 'u', 0xfa: 'u', 0xfb: 'u', 0xfc: 'u',
0xfd: 'y', 0xfe: 'th', 0xff: 'y',
#0xa1: '!', 0xa2: '{cent}', 0xa3: '{pound}', 0xa4: '{currency}',
#0xa5: '{yen}', 0xa6: '|', 0xa7: '{section}', 0xa8: '{umlaut}',
#0xa9: '{C}', 0xaa: '{^a}', 0xab: '<<', 0xac: '{not}',
#0xad: '-', 0xae: '{R}', 0xaf: '_', 0xb0: '{degrees}',
#0xb1: '{+/-}', 0xb2: '{^2}', 0xb3: '{^3}', 0xb4:"'",
#0xb5: '{micro}', 0xb6: '{paragraph}', 0xb7: '*', 0xb8: '{cedilla}',
#0xb9: '{^1}', 0xba: '{^o}', 0xbb: '>>',
#0xbc: '{1/4}', 0xbd: '{1/2}', 0xbe: '{3/4}', 0xbf: '?',
#0xd7: '*', 0xf7: '/'
# 0xa1: '!', 0xa2: '{cent}', 0xa3: '{pound}', 0xa4: '{currency}',
# 0xa5: '{yen}', 0xa6: '|', 0xa7: '{section}', 0xa8: '{umlaut}',
# 0xa9: '{C}', 0xaa: '{^a}', 0xab: '<<', 0xac: '{not}',
# 0xad: '-', 0xae: '{R}', 0xaf: '_', 0xb0: '{degrees}',
# 0xb1: '{+/-}', 0xb2: '{^2}', 0xb3: '{^3}', 0xb4:"'",
# 0xb5: '{micro}', 0xb6: '{paragraph}', 0xb7: '*', 0xb8: '{cedilla}',
# 0xb9: '{^1}', 0xba: '{^o}', 0xbb: '>>',
# 0xbc: '{1/4}', 0xbd: '{1/2}', 0xbe: '{3/4}', 0xbf: '?',
# 0xd7: '*', 0xf7: '/'
}

r = ''
Expand Down
1 change: 1 addition & 0 deletions ckan/lib/search/common.py
Expand Up @@ -19,6 +19,7 @@ class SearchError(Exception):
class SearchQueryError(SearchError):
pass


DEFAULT_SOLR_URL = 'http://127.0.0.1:8983/solr'


Expand Down
1 change: 1 addition & 0 deletions ckan/logic/__init__.py
Expand Up @@ -119,6 +119,7 @@ def __str__(self):
self.error_dict)
return ' - '.join([str(err_msg) for err_msg in err_msgs if err_msg])


log = logging.getLogger(__name__)


Expand Down

0 comments on commit 9b5bf5d

Please sign in to comment.