Skip to content

Commit

Permalink
🗓 Feb 26, 2024 9:23:17 PM
Browse files Browse the repository at this point in the history
✨ to/from_quoted_printable
✨ to/from_rison
  • Loading branch information
securisec committed Feb 27, 2024
1 parent 1ba98da commit 89e7c5e
Show file tree
Hide file tree
Showing 4 changed files with 444 additions and 10 deletions.
51 changes: 51 additions & 0 deletions chepy/modules/dataformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import pickle
import string
import itertools
import quopri
from random import randint
from .internal.constants import Encoding
from .internal.helpers import (
Expand All @@ -32,6 +33,7 @@

from ..core import ChepyCore, ChepyDecorators
from chepy.modules.internal.constants import Encoding
import chepy.modules.internal.rison as rison

DataFormatT = TypeVar("DataFormatT", bound="DataFormat")

Expand Down Expand Up @@ -2066,3 +2068,52 @@ def from_uuencode(self: DataFormatT, header: str = "-") -> DataFormatT:
"""
self.state = UUEncoderDecoder(self._convert_to_bytes(), header).uudecode()
return self

@ChepyDecorators.call_stack
def from_quoted_printable(self) -> DataFormatT:
"""From quoted printable
Returns:
Chepy: The Chepy object.
"""
self.state = quopri.decodestring(self._convert_to_bytes())
return self

@ChepyDecorators.call_stack
def to_quoted_printable(self) -> DataFormatT:
"""To quoted printable
Returns:
Chepy: The Chepy object.
"""
self.state = quopri.encodestring(self._convert_to_bytes())
return self

@ChepyDecorators.call_stack
def from_rison(self):
"""Encode to RISON
Returns:
Chepy: The Chepy object.
"""
self.state = rison.loads(self._convert_to_str())
return self

@ChepyDecorators.call_stack
def to_rison(self):
"""Decode from RISON
Returns:
Chepy: The Chepy object.
"""
self.state = rison.dumps(self.state)
# if option is None:
# elif option == 'array':
# self.state = rison.encode_array(self.state)
# elif option == 'object':
# self.state = rison.encode_object(self.state)
# elif option == 'uri':
# self.state = rison.encode_uri(self.state)
# else:
# self._log.error('Invalid data type')
return self
4 changes: 4 additions & 0 deletions chepy/modules/dataformat.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,7 @@ class DataFormat(ChepyCore):
def from_utf21(self: DataFormatT) -> DataFormatT: ...
def to_uuencode(self: DataFormatT, header: str='-') -> DataFormatT: ...
def from_uuencode(self: DataFormatT, header: str='-') -> DataFormatT: ...
def from_quoted_printable(self: DataFormatT) -> DataFormatT: ...
def to_quoted_printable(self: DataFormatT) -> DataFormatT: ...
def from_rison(self: DataFormatT) -> DataFormatT: ...
def to_rison(self: DataFormatT) -> DataFormatT: ...
Loading

0 comments on commit 89e7c5e

Please sign in to comment.