File api.py
has 895 lines of code (exceeds 250 allowed). Consider refactoring. Open
# -*- coding: utf-8 -*-
#
# Copyright (C) 2004-2023 Edgewall Software
# Copyright (C) 2004 Daniel Lundin <daniel@edgewall.com>
# Copyright (C) 2005-2006 Christopher Lenz <cmlenz@gmx.de>
Function render
has a Cognitive Complexity of 50 (exceeds 5 allowed). Consider refactoring. Open
def render(self, context, mimetype, content, filename=None, url=None,
annotations=None, force_source=False):
"""Render an XHTML preview of the given `content`.
`content` is the same as an `IHTMLPreviewRenderer.render`'s
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function convert_content
has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring. Open
def convert_content(self, req, mimetype, content, key, filename=None,
url=None, iterable=False):
"""Convert the given content to the target MIME type represented by
`key`, which can be either a MIME type or a key. Returns a tuple of
(content, output_mime_type, extension)."""
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function get_mimetype
has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring. Open
def get_mimetype(filename, content=None, mime_map=MIME_MAP,
mime_map_patterns={}):
"""Guess the most probable MIME type of a file with the given name.
`filename` is either a filename (the lookup will then use the suffix)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function mime_map
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
def mime_map(self):
# Extend default extension to MIME type mappings with configured ones
if not self._mime_map:
self._mime_map = MIME_MAP.copy()
# augment mime_map from `IHTMLPreviewRenderer`s
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _render_source
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def _render_source(self, context, lines, annotations):
from trac.web.chrome import add_warning
annotators, labels, titles = {}, {}, {}
for annotator in self.annotators:
atype, alabel, atitle = annotator.get_annotation_type()
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function send_converted
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def send_converted(self, req, in_type, content, selector, filename='file'):
"""Helper method for converting `content` and sending it directly.
`selector` can be either a key or a MIME Type."""
from trac.web.chrome import Chrome
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function preview_data
has 8 arguments (exceeds 4 allowed). Consider refactoring. Open
def preview_data(self, context, content, length, mimetype, filename,
Function mime_map_patterns
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def mime_map_patterns(self):
if not self._mime_map_patterns:
self._mime_map_patterns = {}
for mapping in self.config['mimeviewer'] \
.getlist('mime_map_patterns'):
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function render
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
def render(self, context, mimetype, content, filename=None, url=None,
Function convert_content
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
def convert_content(self, req, mimetype, content, key, filename=None,
Avoid deeply nested control flow statements. Open
for keyword in kwds:
self._mime_map[keyword] = mimetype
# augment/override mime_map from trac.ini
for mapping in self.config['mimeviewer'].getlist('mime_map'):
Function get_supported_conversions
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def get_supported_conversions(self, mimetype):
"""Return a list of target MIME types as instances of the `namedtuple`
`MimeConversion`. Output is ordered from best to worst quality.
The `MimeConversion` `namedtuple` has fields: key, name, extension,
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function annotate_row
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def annotate_row(self, context, row, lineno, line, data):
Function render
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def render(self, context, mimetype, content, filename=None, url=None):
Function render
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def render(self, context, mimetype, content, filename=None, url=None):
Function send_converted
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def send_converted(self, req, in_type, content, selector, filename='file'):
Function render
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def render(self, context, mimetype, content, filename=None, url=None):
Avoid too many return
statements within this function. Open
return self._render_source(context, result, annotations)
Avoid too many return
statements within this function. Open
return mimetype
Avoid too many return
statements within this function. Open
return tag.div(class_='code')(tag.pre(result))
Function is_binary
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def is_binary(self, mimetype=None, filename=None, content=None):
"""Check if a file must be considered as binary."""
if not mimetype and filename:
mimetype = self.get_mimetype(filename, content)
if mimetype:
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function get_charset
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def get_charset(self, content='', mimetype=None):
"""Infer the character encoding from the `content` or the `mimetype`.
`content` is either a `bytes` or a `str` object.
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"