mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
lit reader: consistently use bytes when writing to the buffer
This commit is contained in:
parent
e37cf6ab3c
commit
e02f836bd0
@ -226,7 +226,7 @@ class UnBinary(object):
|
|||||||
state = 'text' if oc == 0 else 'get attr'
|
state = 'text' if oc == 0 else 'get attr'
|
||||||
if flags & FLAG_OPENING:
|
if flags & FLAG_OPENING:
|
||||||
tag = oc
|
tag = oc
|
||||||
buf.write('<')
|
buf.write(b'<')
|
||||||
if not (flags & FLAG_CLOSING):
|
if not (flags & FLAG_CLOSING):
|
||||||
is_goingdown = True
|
is_goingdown = True
|
||||||
if tag == 0x8000:
|
if tag == 0x8000:
|
||||||
@ -261,9 +261,9 @@ class UnBinary(object):
|
|||||||
if not is_goingdown:
|
if not is_goingdown:
|
||||||
tag_name = None
|
tag_name = None
|
||||||
dynamic_tag = 0
|
dynamic_tag = 0
|
||||||
buf.write(' />')
|
buf.write(b' />')
|
||||||
else:
|
else:
|
||||||
buf.write('>')
|
buf.write(b'>')
|
||||||
frame = (depth, tag_name, current_map,
|
frame = (depth, tag_name, current_map,
|
||||||
dynamic_tag, errors, in_censorship, False,
|
dynamic_tag, errors, in_censorship, False,
|
||||||
'close tag', flags)
|
'close tag', flags)
|
||||||
@ -288,7 +288,7 @@ class UnBinary(object):
|
|||||||
in_censorship = True
|
in_censorship = True
|
||||||
state = 'get value length'
|
state = 'get value length'
|
||||||
continue
|
continue
|
||||||
buf.write(' ' + encode(attr) + '=')
|
buf.write(b' ' + encode(attr) + b'=')
|
||||||
if attr in ['href', 'src']:
|
if attr in ['href', 'src']:
|
||||||
state = 'get href length'
|
state = 'get href length'
|
||||||
else:
|
else:
|
||||||
@ -296,11 +296,11 @@ class UnBinary(object):
|
|||||||
|
|
||||||
elif state == 'get value length':
|
elif state == 'get value length':
|
||||||
if not in_censorship:
|
if not in_censorship:
|
||||||
buf.write('"')
|
buf.write(b'"')
|
||||||
count = oc - 1
|
count = oc - 1
|
||||||
if count == 0:
|
if count == 0:
|
||||||
if not in_censorship:
|
if not in_censorship:
|
||||||
buf.write('"')
|
buf.write(b'"')
|
||||||
in_censorship = False
|
in_censorship = False
|
||||||
state = 'get attr'
|
state = 'get attr'
|
||||||
continue
|
continue
|
||||||
@ -313,7 +313,7 @@ class UnBinary(object):
|
|||||||
elif state == 'get value':
|
elif state == 'get value':
|
||||||
if count == 0xfffe:
|
if count == 0xfffe:
|
||||||
if not in_censorship:
|
if not in_censorship:
|
||||||
buf.write('%s"' % (oc - 1))
|
buf.write(encode('%s"' % (oc - 1)))
|
||||||
in_censorship = False
|
in_censorship = False
|
||||||
state = 'get attr'
|
state = 'get attr'
|
||||||
elif count > 0:
|
elif count > 0:
|
||||||
@ -326,7 +326,7 @@ class UnBinary(object):
|
|||||||
count -= 1
|
count -= 1
|
||||||
if count == 0:
|
if count == 0:
|
||||||
if not in_censorship:
|
if not in_censorship:
|
||||||
buf.write('"')
|
buf.write(b'"')
|
||||||
in_censorship = False
|
in_censorship = False
|
||||||
state = 'get attr'
|
state = 'get attr'
|
||||||
|
|
||||||
@ -349,14 +349,14 @@ class UnBinary(object):
|
|||||||
count = oc - 1
|
count = oc - 1
|
||||||
if count <= 0 or count > (len(bin) - self.cpos):
|
if count <= 0 or count > (len(bin) - self.cpos):
|
||||||
raise LitError('Invalid character count %d' % count)
|
raise LitError('Invalid character count %d' % count)
|
||||||
buf.write(' ')
|
buf.write(b' ')
|
||||||
state = 'get custom attr'
|
state = 'get custom attr'
|
||||||
|
|
||||||
elif state == 'get custom attr':
|
elif state == 'get custom attr':
|
||||||
buf.write(encode(c))
|
buf.write(encode(c))
|
||||||
count -= 1
|
count -= 1
|
||||||
if count == 0:
|
if count == 0:
|
||||||
buf.write('=')
|
buf.write(b'=')
|
||||||
state = 'get value length'
|
state = 'get value length'
|
||||||
|
|
||||||
elif state == 'get href length':
|
elif state == 'get href length':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user