Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit df4480c

Browse files
committed
Shorten dviread helper definitions.
1 parent 92de753 commit df4480c

File tree

1 file changed

+22
-58
lines changed

1 file changed

+22
-58
lines changed

lib/matplotlib/dviread.py

Lines changed: 22 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -125,64 +125,28 @@ def glyph_name_or_index(self):
125125

126126
# Opcode argument parsing
127127
#
128-
# Each of the following functions takes a Dvi object and delta,
129-
# which is the difference between the opcode and the minimum opcode
130-
# with the same meaning. Dvi opcodes often encode the number of
131-
# argument bytes in this delta.
132-
133-
def _arg_raw(dvi, delta):
134-
"""Return *delta* without reading anything more from the dvi file."""
135-
return delta
136-
137-
138-
def _arg(nbytes, signed, dvi, _):
139-
"""
140-
Read *nbytes* bytes, returning the bytes interpreted as a signed integer
141-
if *signed* is true, unsigned otherwise.
142-
"""
143-
return dvi._arg(nbytes, signed)
144-
145-
146-
def _arg_slen(dvi, delta):
147-
"""
148-
Read *delta* bytes, returning None if *delta* is zero, and the bytes
149-
interpreted as a signed integer otherwise.
150-
"""
151-
if delta == 0:
152-
return None
153-
return dvi._arg(delta, True)
154-
155-
156-
def _arg_slen1(dvi, delta):
157-
"""
158-
Read *delta*+1 bytes, returning the bytes interpreted as signed.
159-
"""
160-
return dvi._arg(delta + 1, True)
161-
162-
163-
def _arg_ulen1(dvi, delta):
164-
"""
165-
Read *delta*+1 bytes, returning the bytes interpreted as unsigned.
166-
"""
167-
return dvi._arg(delta + 1, False)
168-
169-
170-
def _arg_olen1(dvi, delta):
171-
"""
172-
Read *delta*+1 bytes, returning the bytes interpreted as
173-
unsigned integer for 0<=*delta*<3 and signed if *delta*==3.
174-
"""
175-
return dvi._arg(delta + 1, delta == 3)
176-
177-
178-
_arg_mapping = dict(raw=_arg_raw,
179-
u1=partial(_arg, 1, False),
180-
u4=partial(_arg, 4, False),
181-
s4=partial(_arg, 4, True),
182-
slen=_arg_slen,
183-
olen1=_arg_olen1,
184-
slen1=_arg_slen1,
185-
ulen1=_arg_ulen1)
128+
# Each of the following functions takes a Dvi object and delta, which is the
129+
# difference between the opcode and the minimum opcode with the same meaning.
130+
# Dvi opcodes often encode the number of argument bytes in this delta.
131+
_arg_mapping = dict(
132+
# raw: Return delta as is.
133+
raw=lambda dvi, delta: delta,
134+
# u1: Read 1 byte as an unsigned number.
135+
u1=lambda dvi, delta: dvi._arg(1, signed=False),
136+
# u4: Read 4 bytes as an unsigned number.
137+
u4=lambda dvi, delta: dvi._arg(4, signed=False),
138+
# s4: Read 4 bytes as a signed number.
139+
s4=lambda dvi, delta: dvi._arg(4, signed=True),
140+
# slen: Read delta bytes as a signed number, or None if delta is None.
141+
slen=lambda dvi, delta: dvi._arg(delta, signed=True) if delta else None,
142+
# slen1: Read (delta + 1) bytes as a signed number.
143+
slen1=lambda dvi, delta: dvi._arg(delta + 1, signed=True),
144+
# ulen1: Read (delta + 1) bytes as an unsigned number.
145+
ulen1=lambda dvi, delta: dvi._arg(delta + 1, signed=False),
146+
# olen1: Read (delta + 1) bytes as an unsigned number if less than 4 bytes,
147+
# as a signed number if 4 bytes.
148+
olen1=lambda dvi, delta: dvi._arg(delta + 1, signed=(delta == 3)),
149+
)
186150

187151

188152
def _dispatch(table, min, max=None, state=None, args=('raw',)):

0 commit comments

Comments
 (0)