Skip to content

Commit

Permalink
Merge pull request #347 from alex-smile/fix_esb_py3_2
Browse files Browse the repository at this point in the history
修复 ESB 发送消息组件问题
  • Loading branch information
MrLYC authored May 26, 2021
2 parents e766146 + 0e533e8 commit adcfdee
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion paas2/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.13.3
2.13.4
5 changes: 3 additions & 2 deletions paas2/esb/components/generic/templates/cmsi/send_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import base64

from django import forms
from django.utils.encoding import force_text

from components.component import Component, SetupConfMixin
from common.forms import BaseComponentForm, ListField, DefaultBooleanField, TypeCheckField
Expand Down Expand Up @@ -117,7 +118,7 @@ def clean(self):
data["cc__username"] = None
if data["is_content_base64"]:
try:
data["content"] = base64.b64decode(data["content"])
data["content"] = force_text(base64.b64decode(data["content"]))
except Exception:
pass
if data["attachments"]:
Expand All @@ -135,7 +136,7 @@ class AttachmentForm(BaseComponentForm):
content_id = forms.CharField(label="content_id", required=False)

def clean(self):
self.cleaned_data["content"] = base64.b64decode(self.cleaned_data["content"])
self.cleaned_data["content"] = force_text(base64.b64decode(self.cleaned_data["content"]))
return self.cleaned_data

def handle(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from django import forms
from django.utils import timezone
from django.utils.encoding import force_text

from components.component import Component, SetupConfMixin
from common.forms import BaseComponentForm, ListField, TypeCheckField, DefaultBooleanField
Expand Down Expand Up @@ -105,7 +106,7 @@ class DataForm(BaseComponentForm):
def decode_message(self, message, is_message_base64):
if is_message_base64:
try:
message = base64.b64decode(message)
message = force_text(base64.b64decode(message))
except Exception:
pass
return message
Expand Down
3 changes: 2 additions & 1 deletion paas2/esb/components/generic/templates/cmsi/send_sms.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import base64

from django import forms
from django.utils.encoding import force_text

from components.component import Component, SetupConfMixin
from common.forms import BaseComponentForm, ListField, DefaultBooleanField
Expand Down Expand Up @@ -83,7 +84,7 @@ class Form(BaseComponentForm):
def decode_content(self, content, is_content_base64):
if is_content_base64:
try:
content = base64.b64decode(content)
content = force_text(base64.b64decode(content))
except Exception:
pass
return content
Expand Down
2 changes: 1 addition & 1 deletion paas2/esb/components/generic/templates/cmsi/send_weixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class DataForm(BaseComponentForm):
def decode_message(self, message, is_message_base64):
if is_message_base64:
try:
message = base64.b64decode(message)
message = force_text(base64.b64decode(message))
except Exception:
pass
return message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from email.mime.text import MIMEText
from email.utils import COMMASPACE

from django.utils.encoding import force_text

from common.base_utils import smart_str
from common.bkerrors import bk_error_codes
from common.log import logger
Expand All @@ -32,7 +34,7 @@ def __init__(
self.smtp_host = smtp_host
self.smtp_port = smtp_port
self.smtp_user = smtp_user
self.smtp_pwd = smart_str(smtp_pwd)
self.smtp_pwd = force_text(smtp_pwd)
self.smtp_usessl = smtp_usessl
self.smtp_usetls = smtp_usetls
self.smtp_timeout = smtp_timeout
Expand Down Expand Up @@ -91,7 +93,7 @@ def add_attachment_to_msg(self, mail_msg, attachments):
# rfc2047: encoded-word = "=?" charset "?" encoding "?" encoded-text "?="
# encoding b for base64
filename = smart_str(f_info.get("filename", ""))
_filename = "=?utf-8?b?" + base64.b64encode(filename) + "?="
_filename = "=?utf-8?b?" + force_text(base64.b64encode(filename)) + "?="
_content = f_info.get("content", "")
_type = f_info.get("type") or _filename.split(".")[-1] or "attachment"
_disposition = f_info.get("disposition", "")
Expand Down
4 changes: 3 additions & 1 deletion paas2/esb/components/generic/templates/cmsi/toolkit/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import base64
from collections import OrderedDict, defaultdict

from django.utils.encoding import force_text

from common.errors import CommonAPIError

default_nation_code = "86"
Expand Down Expand Up @@ -159,7 +161,7 @@ def get_user_contact_with_username(username_list=None, contact_way="phone"):

def get_base64_icon(path):
with open(os.path.join(ICON_DIR, path), "rb") as f:
return base64.b64encode(f.read())
return force_text(base64.b64encode(f.read()))


def _get_users(usernames):
Expand Down
3 changes: 3 additions & 0 deletions paas2/release.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Release Log
===============================
# 2.13.4
- update: fix esb cmsi apis for python3/upgrade

# 2.13.3
- update: bugfix esb management for python3/upgrade

Expand Down

0 comments on commit adcfdee

Please sign in to comment.