mirror of https://github.com/zulip/zulip.git
str_utils: Move force_bytes into ccache.py.
This is only used there, and so belongs in that bundle of barely-maintained code.
This commit is contained in:
parent
aec57baef2
commit
351fab204b
|
@ -26,9 +26,18 @@ from typing import Any, Dict, List, Optional
|
|||
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
from zerver.lib.str_utils import force_bytes
|
||||
import base64
|
||||
import struct
|
||||
from typing import Union
|
||||
|
||||
def force_bytes(s: Union[str, bytes], encoding: str='utf-8') -> bytes:
|
||||
"""converts a string to binary string"""
|
||||
if isinstance(s, bytes):
|
||||
return s
|
||||
elif isinstance(s, str):
|
||||
return s.encode(encoding)
|
||||
else:
|
||||
raise TypeError("force_bytes expects a string type")
|
||||
|
||||
# Some DER encoding stuff. Bleh. This is because the ccache contains a
|
||||
# DER-encoded krb5 Ticket structure, whereas Webathena deserializes
|
||||
|
|
|
@ -43,15 +43,6 @@ def force_text(s: Union[str, bytes], encoding: str='utf-8') -> str:
|
|||
else:
|
||||
raise TypeError("force_text expects a string type")
|
||||
|
||||
def force_bytes(s: Union[str, bytes], encoding: str='utf-8') -> bytes:
|
||||
"""converts a string to binary string"""
|
||||
if isinstance(s, bytes):
|
||||
return s
|
||||
elif isinstance(s, str):
|
||||
return s.encode(encoding)
|
||||
else:
|
||||
raise TypeError("force_bytes expects a string type")
|
||||
|
||||
def force_str(s: Union[str, bytes], encoding: str='utf-8') -> str:
|
||||
"""converts a string to a native string"""
|
||||
if isinstance(s, str):
|
||||
|
|
Loading…
Reference in New Issue