mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
DRYer
This commit is contained in:
parent
81fe7d3180
commit
1ef173bca5
@ -350,8 +350,8 @@ def run_rapydscript_tests():
|
||||
setup_fake_protocol, setup_profile
|
||||
)
|
||||
must_use_qt()
|
||||
setup_default_profile()
|
||||
setup_fake_protocol()
|
||||
setup_default_profile()
|
||||
|
||||
base = base_dir()
|
||||
rapydscript_dir = os.path.join(base, 'src', 'pyj')
|
||||
|
@ -52,6 +52,16 @@ def get_current_time(target): # {{{
|
||||
return fstr(target.currentTime or 0)
|
||||
# }}}
|
||||
|
||||
def id_is_unique(idval): # {{{
|
||||
try:
|
||||
multiples = document.querySelectorAll('[id=' + window.CSS.escape(idval) + ']')
|
||||
except:
|
||||
return False
|
||||
if multiples and multiples.length < 2:
|
||||
return True
|
||||
return False
|
||||
# }}}
|
||||
|
||||
# Convert point to character offset {{{
|
||||
def range_has_point(range_, x, y):
|
||||
rects = range_.getClientRects()
|
||||
@ -239,12 +249,7 @@ def encode(doc, node, offset, tail):
|
||||
# Add id assertions for robustness where possible
|
||||
id = node.id
|
||||
idspec = ''
|
||||
if id:
|
||||
try:
|
||||
multiples = document.querySelectorAll('#' + id)
|
||||
except:
|
||||
multiples = None
|
||||
if multiples and multiples.length < 2:
|
||||
if id and id_is_unique(id):
|
||||
idspec = ('[' + escape_for_cfi(id) + ']')
|
||||
cfi = '/' + index + idspec + cfi
|
||||
node = p
|
||||
@ -274,12 +279,7 @@ def node_at_index(nodes, target, index, iter_text_nodes):
|
||||
def node_for_path_step(parent, target, assertion):
|
||||
if assertion:
|
||||
q = document.getElementById(assertion)
|
||||
if q:
|
||||
try:
|
||||
multiples = document.querySelectorAll('#' + assertion)
|
||||
except:
|
||||
multiples = None
|
||||
if multiples and multiples.length < 2:
|
||||
if q and id_is_unique(assertion):
|
||||
return q
|
||||
is_element = target % 2 == 0
|
||||
target //= 2
|
||||
|
Loading…
x
Reference in New Issue
Block a user