Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Aligned" definition function's implementation is incorrect,modify the encode method #642

Open
WhereIsOops opened this issue Sep 2, 2022 · 3 comments

Comments

@WhereIsOops
Copy link

Proposal

def encode(self, value, mutation_context): child_data = self.get_child_data(mutation_context=mutation_context)
"Aligned" can't get child data using 'get_child_data' because of it has no stack menber.I suggest taking a approach like "Size" function to get the data associated with the request parameter.

Use-Case

My modified code is as follows:
def encode(self, value, mutation_context): if self.request is not None and self.block_name is not None: target_block = self.request.resolve_name(self.context_path,self.block_name) child_data = target_block.render(mutation_context=mutation_context) padding_length = self._modulus - (len(child_data) % self._modulus) a, b = divmod(padding_length, len(self._pattern)) # remove return child_data return self._pattern * a + self._pattern[:b] else: return

Anything else?

No response

@WhereIsOops
Copy link
Author

Let me add a little more,
def encode(self, value, mutation_context): if self.request is not None and self.block_name is not None: target_block = self.request.resolve_name(self.context_path,self.block_name) child_data = target_block.render(mutation_context=mutation_context) remainder = len(child_data) % self._modulus if remainder != 0: padding_length = self._modulus - (len(child_data) % self._modulus) a, b = divmod(padding_length, len(self._pattern)) return self._pattern * a + self._pattern[:b] else: return b"" else: return
When modal, we should add a judgment that the calculation result is 0 ,which means that the data is already aligned at this time.

@hackathi
Copy link
Contributor

hackathi commented Sep 19, 2022

@WhereIsOops could you please re-format your Comments to use proper code tags? This would be the correct markdown syntax to use:

```python
def encode(self, value, mutation_context):
    # rest...
```
Thank you!

@WhereIsOops
Copy link
Author

@WhereIsOops could you please re-format your Comments to use proper code tags? This would be the correct markdown syntax to use:

def encode(self, value, mutation_context):
    # rest...

Thank you!

def encode(self, value, mutation_context):
  if self.request is not None and self.block_name is not None:
      target_block = self.request.resolve_name(self.context_path,self.block_name)
      child_data = target_block.render(mutation_context=mutation_context)
      remainder = len(child_data) % self._modulus
      if remainder != 0:
          padding_length = self._modulus - (len(child_data) % self._modulus)
          a, b = divmod(padding_length, len(self._pattern))
          return self._pattern * a + self._pattern[:b]
      else:
          return b""
  else:
      return

The alignment primitive is not a request class object and does not have the children parameter during initialization. Therefore, its stack is empty. Therefore, the get_child_data method cannot be used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants