Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

python: Remove force_bytes.

Anders Kaseorgdf10b306a6b1
diff --git a/zerver/forms.py b/zerver/forms.py
index 83e12e0fda1..e016f313c54 100644
--- a/zerver/forms.py
+++ b/zerver/forms.py
@@ -12,7 +12,6 @@ from django.core.exceptions import ValidationError
from django.core.validators import validate_email
from django.http import HttpRequest
from django.urls import reverse
-from django.utils.encoding import force_bytes
from django.utils.http import urlsafe_base64_encode
from django.utils.translation import ugettext as _
from jinja2 import Markup as mark_safe
@@ -227,7 +226,7 @@ class LoggingSetPasswordForm(SetPasswordForm):
def generate_password_reset_url(user_profile: UserProfile,
token_generator: PasswordResetTokenGenerator) -> str:
token = token_generator.make_token(user_profile)
- uid = urlsafe_base64_encode(force_bytes(user_profile.id))
+ uid = urlsafe_base64_encode(str(user_profile.id).encode())
endpoint = reverse('password_reset_confirm',
kwargs=dict(uidb64=uid, token=token))
return f"{user_profile.realm.uri}{endpoint}"
diff --git a/zerver/lib/ccache.py b/zerver/lib/ccache.py
index 2160f1f03d0..f4c7a991163 100644
--- a/zerver/lib/ccache.py
+++ b/zerver/lib/ccache.py
@@ -1,6 +1,6 @@
import base64
import struct
-from typing import Any, Dict, List, Optional, Union
+from typing import Any, Dict, List, Optional
# This file is adapted from samples/shellinabox/ssh-krb-wrapper in
# https://github.com/davidben/webathena, which has the following
@@ -28,16 +28,6 @@ from typing import Any, Dict, List, Optional, Union
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
-
-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
# into the various fields. Re-encoding in the client would be easy as
@@ -141,8 +131,8 @@ def ccache_counted_octet_string(data: bytes) -> bytes:
def ccache_principal(name: Dict[str, str], realm: str) -> bytes:
header = struct.pack("!II", name["nameType"], len(name["nameString"]))
- return (header + ccache_counted_octet_string(force_bytes(realm)) +
- b"".join(ccache_counted_octet_string(force_bytes(c))
+ return (header + ccache_counted_octet_string(realm.encode()) +
+ b"".join(ccache_counted_octet_string(c.encode())
for c in name["nameString"]))
def ccache_key(key: Dict[str, str]) -> bytes: