Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint silk directory and fix a python 3 blocker #232

Merged
merged 2 commits into from
Dec 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions silk/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,14 @@ def _get_objects(self, typ):
self._raise_not_configured(
'Attempt to access %s without initialisation.' % typ
)
if not typ in objects:
if typ not in objects:
objects[typ] = {}
return objects[typ]

@property
def profiles(self):
return self._get_objects(TYP_PROFILES)

@property
def silk_queries(self):
return self._get_objects('silk_queries')

def configure(self, request=None):
silky_config = SilkyConfig()

Expand Down Expand Up @@ -119,7 +115,7 @@ def register_objects(self, typ, *args):
self._raise_not_configured(
'Attempt to register object of type %s without initialisation. '
)
if not typ in objects:
if typ not in objects:
self.objects[typ] = {}
self.objects[typ][ident] = arg

Expand Down
2 changes: 1 addition & 1 deletion silk/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ class BaseProfile(models.Model):
request = ForeignKey(
Request, null=True, blank=True, db_index=True,
on_delete=models.CASCADE,
)
)
time_taken = FloatField(blank=True, null=True)

class Meta:
Expand Down
2 changes: 1 addition & 1 deletion silk/profiling/dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def profile_function_or_method(module, func, name=None):
@param module: module object or module name in form 'path.to.module'
@param func: function object or function name in form 'foo' or 'Class.method'
"""
if type(module) is str or type(module) is unicode:
if isinstance(module, six.string_types) or isinstance(module, six.text_type):
module = _get_module(module)
decorator = silk_profile(name, _dynamic=True)
func_name = func
Expand Down
3 changes: 1 addition & 2 deletions silk/profiling/profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ def _finalise_queries(self):
def __exit__(self, exc_type, exc_val, exc_tb):
if self._silk_installed() and self._should_profile():
with silk_meta_profiler():
start_time = None
exception_raised = exc_type is not None
self.profile['exception_raised'] = exception_raised
self.profile['end_time'] = timezone.now()
Expand Down Expand Up @@ -177,7 +176,7 @@ def wrapped_target(*args, **kwargs):
return target

def distinct_queries(self):
queries = [x for x in self._queries_after if not x in self._queries_before]
queries = [x for x in self._queries_after if x not in self._queries_before]
return queries


Expand Down
2 changes: 1 addition & 1 deletion silk/request_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def filters_from_request(request):
if splt[0].startswith('filter'):
ident = splt[1]
typ = splt[2]
if not ident in raw_filters:
if ident not in raw_filters:
raw_filters[ident] = {}
raw_filters[ident][typ] = request.POST[key]
filters = {}
Expand Down
11 changes: 7 additions & 4 deletions silk/templatetags/silk_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
register = Library()


def _no_op(x):
return x


def _esc_func(autoescape):
if autoescape:
esc = conditional_escape
else:
esc = lambda x: x
return esc
return conditional_escape
return _no_op


@stringfilter
Expand Down Expand Up @@ -86,6 +88,7 @@ def body_filter(value):
else:
return value


spacify.needs_autoescape = True
filepath_urlify.needs_autoescape = True
register.filter(spacify)
Expand Down
1 change: 1 addition & 0 deletions silk/templatetags/silk_inclusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def heading(text):
def code(lines, actual_line):
return {'code': lines, 'actual_line': [x.strip() for x in actual_line]}


register.inclusion_tag('silk/inclusion/request_summary.html')(request_summary)
register.inclusion_tag('silk/inclusion/profile_summary.html')(profile_summary)
register.inclusion_tag('silk/inclusion/code.html')(code)
Expand Down
4 changes: 2 additions & 2 deletions silk/views/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class RequestsView(View):
},
'db_time': {
'label': 'Time on queries',
'additional_query_filter': lambda x: x.annotate(db_time=Sum('queries__time_taken')) \
.filter(db_time__gte=0)
'additional_query_filter': lambda x: x.annotate(db_time=Sum('queries__time_taken'))
.filter(db_time__gte=0)
},
}
order_dir = {
Expand Down
2 changes: 1 addition & 1 deletion silk/views/sql_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def get(self, request, *_, **kwargs):
line_num = int(request.GET.get('line_num', 0))
tb = sql_query.traceback_ln_only
str, files = self._urlify(tb)
if file_path and not file_path in files:
if file_path and file_path not in files:
raise PermissionDenied
tb = [mark_safe(x) for x in str.split('\n')]
context = {
Expand Down
2 changes: 1 addition & 1 deletion silk/views/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
except ImportError:
# Django>=1.8
from django.template.context_processors import csrf

from django.db.models import Avg, Count, Sum, Max
from django.shortcuts import render
from django.utils.decorators import method_decorator
Expand Down