| 794 | base.SimpleAsn1Type.__init__(self, value, **kwargs) |
| 795 | |
| 796 | def prettyIn(self, value): |
| 797 | if isinstance(value, bytes): |
| 798 | return value |
| 799 | |
| 800 | elif isinstance(value, str): |
| 801 | try: |
| 802 | return value.encode(self.encoding) |
| 803 | |
| 804 | except UnicodeEncodeError as exc: |
| 805 | raise error.PyAsn1UnicodeEncodeError( |
| 806 | "Can't encode string '%s' with '%s' " |
| 807 | "codec" % (value, self.encoding), exc |
| 808 | ) |
| 809 | elif isinstance(value, OctetString): # a shortcut, bytes() would work the same way |
| 810 | return value.asOctets() |
| 811 | |
| 812 | elif isinstance(value, base.SimpleAsn1Type): # this mostly targets Integer objects |
| 813 | return self.prettyIn(str(value)) |
| 814 | |
| 815 | elif isinstance(value, (tuple, list)): |
| 816 | return self.prettyIn(bytes(value)) |
| 817 | |
| 818 | else: |
| 819 | return bytes(value) |
| 820 | |
| 821 | def __str__(self): |
| 822 | try: |