Code view:

A painting is a person's account of this edit as text, recorded independently of the node mapping - a rendering often has several equally defensible answers where the mapping has one. Deletions and insertions carry no position on the opposite side in a painting, so that panel draws no caret for them.

Before

…lines 1–55 unchanged (55 lines)
56 if sf not in afields:
57 return f'Unknown sort field: {sf}'
58 sort_spec = [((sf if not sf.startswith('*') else '#'+sf[1:]), ascending) for sf in sort_fields]
59 if not set(fields).issubset(afields):
60 return 'Unknown fields: {}'.format(', '.join(set(fields) - afields))
61 if search_text:
62 book_ids = db.multisort(sort_spec, ids_to_sort=db.search(search_text))
63 else:
64 book_ids = db.multisort(sort_spec)
65 if limit > -1:
66 book_ids = book_ids[:limit]
67 data = {}
68 metadata = {}
…lines 69–399 unchanged (331 lines)

After

…lines 1–55 unchanged (55 lines)
56 if sf not in afields:
57 return f'Unknown sort field: {sf}'
58 sort_spec = [((sf if not sf.startswith('*') else '#'+sf[1:]), ascending) for sf in sort_fields]
59 if not set(fields).issubset(afields):
60 return 'Unknown fields: {}'.format(', '.join(set(fields) - afields))
61 if search_text:
62 book_ids = db.multisort(sort_spec, ids_to_sort=db.search(search_text, allow_templates=not is_remote))
63 else:
64 book_ids = db.multisort(sort_spec)
65 if limit > -1:
66 book_ids = book_ids[:limit]
67 data = {}
68 metadata = {}
…lines 69–399 unchanged (331 lines)

Before

module
comment "#!/usr/bin/env python"
comment "# License: GPLv3 Copyright: 2017, Kovid Goyal <kovid at kovi"...
import_statement
import "import"
dotted_name
identifier "json"
import_statement
import "import"
dotted_name
identifier "os"
import_statement
import "import"
dotted_name
identifier "sys"
import_from_statement
from "from"
dotted_name
identifier "textwrap"
import "import"
dotted_name
identifier "TextWrapper"
import_from_statement
from "from"
dotted_name
identifier "calibre"
. "."
identifier "db"
. "."
identifier "cli"
. "."
identifier "utils"
import "import"
dotted_name
identifier "str_width"
import_from_statement
from "from"
dotted_name
identifier "calibre"
. "."
identifier "ebooks"
. "."
identifier "metadata"
import "import"
dotted_name
identifier "authors_to_string"
import_from_statement
from "from"
dotted_name
identifier "calibre"
. "."
identifier "utils"
. "."
identifier "date"
import "import"
dotted_name
identifier "isoformat"
import_from_statement
from "from"
dotted_name
identifier "polyglot"
. "."
identifier "builtins"
import "import"
dotted_name
identifier "as_bytes"
expression_statement
assignment
identifier "readonly"
= "="
true "True"
expression_statement
assignment
identifier "version"
= "="
integer "0"
comment "# change this if you change signature of implementation()"
expression_statement (+106 nodes collapsed)
function_definition (+71 nodes collapsed)
function_definition (+27 nodes collapsed)
function_definition
def "def"
identifier "implementation"
parameters (+21 nodes collapsed)
: ":"
block
expression_statement
assignment
identifier "is_remote"
= "="
comparison_operator
identifier "notify_changes"
is not
is "is"
not "not"
none "None"
if_statement
if "if"
identifier "is_remote"
: ":"
comment "# templates allow arbitrary code execution via python templa"...
comment "# could possibly disallow only python templates but that is "...
comment "# than I feel like doing for this, so simply ignore template"...
comment "# connections."
block
expression_statement
assignment
identifier "template"
= "="
none "None"
expression_statement
assignment
identifier "formatter"
= "="
none "None"
with_statement
with "with"
with_clause
with_item
attribute
identifier "db"
. "."
identifier "safe_read_lock"
: ":"
block
expression_statement
assignment
identifier "fm"
= "="
attribute
identifier "db"
. "."
identifier "field_metadata"
expression_statement
assignment
identifier "afields"
= "="
binary_operator
call
identifier "set"
argument_list
( "("
identifier "FIELDS"
) ")"
| "|"
set
{ "{"
string
string_start "'"
string_content "id"
string_end "'"
} "}"
for_statement (+36 nodes collapsed)
if_statement (+38 nodes collapsed)
expression_statement
assignment
identifier "sort_by"
= "="
boolean_operator
identifier "sort_by"
or "or"
string
string_start "'"
string_content "id"
string_end "'"
expression_statement
assignment
identifier "sort_fields"
= "="
call
attribute
identifier "sort_by"
. "."
identifier "split"
argument_list
( "("
string
string_start "'"
string_content ","
string_end "'"
) ")"
for_statement (+27 nodes collapsed)
expression_statement (+51 nodes collapsed)
if_statement (+53 nodes collapsed)
if_statement
if "if"
identifier "search_text"
: ":"
block
expression_statement
assignment
identifier "book_ids"
= "="
call
attribute
identifier "db"
. "."
identifier "multisort"
argument_list
( "("
identifier "sort_spec"
, ","
keyword_argument
identifier "ids_to_sort"
= "="
call
attribute
identifier "db"
. "."
identifier "search"
argument_list
( "("
identifier "search_text"
) ")"
) ")"
else_clause
else "else"
: ":"
block
expression_statement
assignment
identifier "book_ids"
= "="
call
attribute
identifier "db"
. "."
identifier "multisort"
argument_list
( "("
identifier "sort_spec"
) ")"
if_statement (+21 nodes collapsed)
expression_statement
assignment
identifier "data"
= "="
dictionary
{ "{"
} "}"
expression_statement
assignment
identifier "metadata"
= "="
dictionary
{ "{"
} "}"
for_statement (+423 nodes collapsed)
return_statement (+36 nodes collapsed)
function_definition (+379 nodes collapsed)
function_definition (+103 nodes collapsed)
function_definition (+157 nodes collapsed)
function_definition (+1142 nodes collapsed)
function_definition (+620 nodes collapsed)
function_definition (+176 nodes collapsed)

After

module
comment "#!/usr/bin/env python"
comment "# License: GPLv3 Copyright: 2017, Kovid Goyal <kovid at kovi"...
import_statement
import "import"
dotted_name
identifier "json"
import_statement
import "import"
dotted_name
identifier "os"
import_statement
import "import"
dotted_name
identifier "sys"
import_from_statement
from "from"
dotted_name
identifier "textwrap"
import "import"
dotted_name
identifier "TextWrapper"
import_from_statement
from "from"
dotted_name
identifier "calibre"
. "."
identifier "db"
. "."
identifier "cli"
. "."
identifier "utils"
import "import"
dotted_name
identifier "str_width"
import_from_statement
from "from"
dotted_name
identifier "calibre"
. "."
identifier "ebooks"
. "."
identifier "metadata"
import "import"
dotted_name
identifier "authors_to_string"
import_from_statement
from "from"
dotted_name
identifier "calibre"
. "."
identifier "utils"
. "."
identifier "date"
import "import"
dotted_name
identifier "isoformat"
import_from_statement
from "from"
dotted_name
identifier "polyglot"
. "."
identifier "builtins"
import "import"
dotted_name
identifier "as_bytes"
expression_statement
assignment
identifier "readonly"
= "="
true "True"
expression_statement
assignment
identifier "version"
= "="
integer "0"
comment "# change this if you change signature of implementation()"
expression_statement (+106 nodes collapsed)
function_definition (+71 nodes collapsed)
function_definition (+27 nodes collapsed)
function_definition
def "def"
identifier "implementation"
parameters (+21 nodes collapsed)
: ":"
block
expression_statement
assignment
identifier "is_remote"
= "="
comparison_operator
identifier "notify_changes"
is not
is "is"
not "not"
none "None"
if_statement
if "if"
identifier "is_remote"
: ":"
comment "# templates allow arbitrary code execution via python templa"...
comment "# could possibly disallow only python templates but that is "...
comment "# than I feel like doing for this, so simply ignore template"...
comment "# connections."
block
expression_statement
assignment
identifier "template"
= "="
none "None"
expression_statement
assignment
identifier "formatter"
= "="
none "None"
with_statement
with "with"
with_clause
with_item
attribute
identifier "db"
. "."
identifier "safe_read_lock"
: ":"
block
expression_statement
assignment
identifier "fm"
= "="
attribute
identifier "db"
. "."
identifier "field_metadata"
expression_statement
assignment
identifier "afields"
= "="
binary_operator
call
identifier "set"
argument_list
( "("
identifier "FIELDS"
) ")"
| "|"
set
{ "{"
string
string_start "'"
string_content "id"
string_end "'"
} "}"
for_statement (+36 nodes collapsed)
if_statement (+38 nodes collapsed)
expression_statement
assignment
identifier "sort_by"
= "="
boolean_operator
identifier "sort_by"
or "or"
string
string_start "'"
string_content "id"
string_end "'"
expression_statement
assignment
identifier "sort_fields"
= "="
call
attribute
identifier "sort_by"
. "."
identifier "split"
argument_list
( "("
string
string_start "'"
string_content ","
string_end "'"
) ")"
for_statement (+27 nodes collapsed)
expression_statement (+51 nodes collapsed)
if_statement (+53 nodes collapsed)
if_statement
if "if"
identifier "search_text"
: ":"
block
expression_statement
assignment
identifier "book_ids"
= "="
call
attribute
identifier "db"
. "."
identifier "multisort"
argument_list
( "("
identifier "sort_spec"
, ","
keyword_argument
identifier "ids_to_sort"
= "="
call
attribute
identifier "db"
. "."
identifier "search"
argument_list
( "("
identifier "search_text"
, ","
keyword_argument
identifier "allow_templates"
= "="
not_operator
not "not"
identifier "is_remote"
) ")"
) ")"
else_clause
else "else"
: ":"
block
expression_statement
assignment
identifier "book_ids"
= "="
call
attribute
identifier "db"
. "."
identifier "multisort"
argument_list
( "("
identifier "sort_spec"
) ")"
if_statement (+21 nodes collapsed)
expression_statement
assignment
identifier "data"
= "="
dictionary
{ "{"
} "}"
expression_statement
assignment
identifier "metadata"
= "="
dictionary
{ "{"
} "}"
for_statement (+423 nodes collapsed)
return_statement (+36 nodes collapsed)
function_definition (+379 nodes collapsed)
function_definition (+103 nodes collapsed)
function_definition (+157 nodes collapsed)
function_definition (+1142 nodes collapsed)
function_definition (+620 nodes collapsed)
function_definition (+176 nodes collapsed)