Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def render(self):
"""
Render the sizer.
:return: Rendered value.
"""
if self._should_render_fuzz_value():
self._rendered = self.bit_field.render()
elif self._recursion_flag:
self._rendered = self._get_dummy_value()
else:
self._rendered = self._render()
return helpers.str_to_bytes(self._rendered)
def render(self):
# ensure there are no open blocks lingering.
if self.block_stack:
raise exception.SullyRuntimeError("UNCLOSED BLOCK: %s" % self.block_stack[-1].name)
self._rendered = b""
for item in self.stack:
self._rendered += item.render()
return helpers.str_to_bytes(self._rendered)
def _render(self, value):
"""
Render string value, properly padded.
"""
value = helpers.str_to_bytes(value)
# if size is set, then pad undersized values.
if self.size is not None:
value += self.padding * (self.size - len(value))
return helpers.str_to_bytes(value)
def original_value(self):
# ensure there are no open blocks lingering.
if self.block_stack:
raise exception.SullyRuntimeError("UNCLOSED BLOCK: %s" % self.block_stack[-1].name)
self._rendered = b""
for item in self.stack:
self._rendered += helpers.str_to_bytes(item.original_value)
return self._rendered
def _render(self, value):
"""
Render string value, properly padded.
"""
if isinstance(value, six.text_type):
value = helpers.str_to_bytes(value)
# pad undersized library items.
if len(value) < self.size:
value += self.padding * (self.size - len(value))
return helpers.str_to_bytes(value)
def _render(self):
length = self._calculated_length()
return helpers.str_to_bytes(self._length_to_bytes(length))
#
# otherwise, render and encode as usual.
#
for item in self.stack:
self._rendered += item.render()
# add the completed block to the request dictionary.
self.request.closed_blocks[self.name] = self
# if an encoder was attached to this block, call it.
if self.encoder:
self._rendered = self.encoder(self._rendered)
return helpers.str_to_bytes(self._rendered)
def _render(self, value):
"""
Render an arbitrary value.
Args:
value: Value to render.
Returns:
bytes: Rendered value
"""
if value is None:
value = b""
return helpers.str_to_bytes(value)
def render(self):
# let the parent do the initial render.
blocks.Block.render(self)
# TODO: What is this I don't even
self._rendered = self.prefix + b"\x84" + self._rendered
return helpers.str_to_bytes(self._rendered)