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:
Tim Abbott 2018-05-15 19:07:11 -07:00
parent aec57baef2
commit 351fab204b
2 changed files with 10 additions and 10 deletions

View File

@ -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

View File

@ -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):