当前位置: 首页>>代码示例>>Python>>正文


Python str_utils.force_text函数代码示例

本文整理汇总了Python中zerver.lib.str_utils.force_text函数的典型用法代码示例。如果您正苦于以下问题:Python force_text函数的具体用法?Python force_text怎么用?Python force_text使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了force_text函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle

    def handle(self, *args, **options):
        # type: (*Any, **str) -> None
        realm = self.get_realm(options)
        old_name = options['old_name']
        new_name = options['new_name']
        encoding = sys.getfilesystemencoding()

        stream = get_stream(force_text(old_name, encoding), realm)
        do_rename_stream(stream, force_text(new_name, encoding))
开发者ID:yhl-python,项目名称:zulip,代码行数:9,代码来源:rename_stream.py

示例2: handle

    def handle(self, *args: Any, **options: str) -> None:
        realm = self.get_realm(options)
        assert realm is not None  # Should be ensured by parser
        old_name = options['old_name']
        new_name = options['new_name']
        encoding = sys.getfilesystemencoding()

        stream = get_stream(force_text(old_name, encoding), realm)
        do_rename_stream(stream, force_text(new_name, encoding))
开发者ID:brockwhittaker,项目名称:zulip,代码行数:9,代码来源:rename_stream.py

示例3: handle

    def handle(self, *args, **options):
        # type: (*Any, **str) -> None
        domain = options['domain']
        encoding = sys.getfilesystemencoding()
        stream_name = options['stream_name']

        realm = get_realm(force_text(domain, encoding))
        if realm is None:
            print("Unknown domain %s" % (domain,))
            exit(1)
        else:
            do_create_stream(realm, force_text(stream_name, encoding))
开发者ID:150vb,项目名称:zulip,代码行数:12,代码来源:create_stream.py

示例4: handle

    def handle(self, *args, **options):
        # type: (*Any, **str) -> None
        string_id = options['realm']
        encoding = sys.getfilesystemencoding()
        stream_name = options['stream_name']

        realm = get_realm_by_string_id(force_text(string_id, encoding))
        if realm is None:
            print("Unknown string_id %s" % (string_id,))
            exit(1)
        else:
            do_create_stream(realm, force_text(stream_name, encoding))
开发者ID:zulip,项目名称:zulip,代码行数:12,代码来源:create_stream.py

示例5: handle

    def handle(self, *args, **options):
        # type: (*Any, **str) -> None
        string_id = options['string_id']
        old_name = options['old_name']
        new_name = options['new_name']
        encoding = sys.getfilesystemencoding()

        realm = get_realm(force_text(string_id, encoding))
        if realm is None:
            print("Unknown subdomain or string_id %s" % (string_id,))
            exit(1)

        do_rename_stream(realm, force_text(old_name, encoding),
                         force_text(new_name, encoding))
开发者ID:acemaster,项目名称:zulip,代码行数:14,代码来源:rename_stream.py

示例6: handle

    def handle(self, *args: Any, **options: str) -> None:
        realm = self.get_realm(options)
        assert realm is not None  # Should be ensured by parser

        encoding = sys.getfilesystemencoding()
        stream_name = options['stream_name']
        create_stream_if_needed(realm, force_text(stream_name, encoding))
开发者ID:brockwhittaker,项目名称:zulip,代码行数:7,代码来源:create_stream.py

示例7: process_message

def process_message(message: message.Message, rcpt_to: Optional[str]=None, pre_checked: bool=False) -> None:
    subject_header = str(message.get("Subject", "")).strip()
    if subject_header == "":
        subject_header = "(no topic)"
    encoded_subject, encoding = decode_header(subject_header)[0]
    if encoding is None:
        subject = force_text(encoded_subject)  # encoded_subject has type str when encoding is None
    else:
        try:
            subject = encoded_subject.decode(encoding)
        except (UnicodeDecodeError, LookupError):
            subject = "(unreadable subject)"

    debug_info = {}

    try:
        if rcpt_to is not None:
            to = rcpt_to
        else:
            to = find_emailgateway_recipient(message)
        debug_info["to"] = to

        if is_missed_message_address(to):
            process_missed_message(to, message, pre_checked)
        else:
            process_stream_message(to, subject, message, debug_info)
    except ZulipEmailForwardError as e:
        # TODO: notify sender of error, retry if appropriate.
        log_and_report(message, str(e), debug_info)
开发者ID:brainwane,项目名称:zulip,代码行数:29,代码来源:email_mirror.py

示例8: get_url_data

 def get_url_data(self, e):
     # type: (Element) -> Optional[Tuple[text_type, text_type]]
     if e.tag == "a":
         if e.text is not None:
             return (e.get("href"), force_text(e.text))
         return (e.get("href"), e.get("href"))
     return None
开发者ID:krtkmj,项目名称:zulip,代码行数:7,代码来源:__init__.py

示例9: process_message

def process_message(message, rcpt_to=None, pre_checked=False):
    # type: (message.Message, Optional[text_type], bool) -> None
    subject_header = message.get("Subject", "(no subject)")
    encoded_subject, encoding = decode_header(subject_header)[0] # type: ignore # https://github.com/python/typeshed/pull/333
    if encoding is None:
        subject = force_text(encoded_subject) # encoded_subject has type str when encoding is None
    else:
        try:
            subject = encoded_subject.decode(encoding)
        except (UnicodeDecodeError, LookupError):
            subject = u"(unreadable subject)"

    debug_info = {}

    try:
        if rcpt_to is not None:
            to = rcpt_to
        else:
            to = find_emailgateway_recipient(message)
        debug_info["to"] = to

        if is_missed_message_address(to):
            process_missed_message(to, message, pre_checked)
        else:
            process_stream_message(to, subject, message, debug_info)
    except ZulipEmailForwardError as e:
        # TODO: notify sender of error, retry if appropriate.
        log_and_report(message, str(e), debug_info)
开发者ID:150vb,项目名称:zulip,代码行数:28,代码来源:email_mirror.py

示例10: make_safe_digest

def make_safe_digest(string, hash_func=hashlib.sha1):
    # type: (text_type, Callable[[binary_type], Any]) -> text_type
    """
    return a hex digest of `string`.
    """
    # hashlib.sha1, md5, etc. expect bytes, so non-ASCII strings must
    # be encoded.
    return force_text(hash_func(string.encode('utf-8')).hexdigest())
开发者ID:ahmadassaf,项目名称:Zulip,代码行数:8,代码来源:utils.py

示例11: list_of_tlds

def list_of_tlds():
    # type: () -> List[text_type]
    # HACK we manually blacklist .py
    blacklist = [u'PY\n', ]

    # tlds-alpha-by-domain.txt comes from http://data.iana.org/TLD/tlds-alpha-by-domain.txt
    tlds_file = os.path.join(os.path.dirname(__file__), 'tlds-alpha-by-domain.txt')
    tlds = [force_text(tld).lower().strip() for tld in open(tlds_file, 'r')
                if tld not in blacklist and not tld[0].startswith('#')]
    tlds.sort(key=len, reverse=True)
    return tlds
开发者ID:Kingedgar,项目名称:zulip,代码行数:11,代码来源:__init__.py

示例12: get_file_info

def get_file_info(request, user_file):
    # type: (HttpRequest, File) -> Tuple[text_type, text_type]

    uploaded_file_name = user_file.name
    content_type = request.GET.get('mimetype')
    if content_type is None:
        content_type = force_text(guess_type(uploaded_file_name)[0])
    else:
        uploaded_file_name = uploaded_file_name + guess_extension(content_type)

    uploaded_file_name = urllib.parse.unquote(uploaded_file_name)
    return uploaded_file_name, content_type
开发者ID:Kingedgar,项目名称:zulip,代码行数:12,代码来源:upload.py

示例13: run

 def run(self, root):
     # type: (ElementTree) -> None
     """ Find code blocks and store in htmlStash. """
     blocks = root.getiterator('pre')
     for block in blocks:
         children = block.getchildren()
         tag = force_text(children[0].tag)
         if len(children) == 1 and tag == 'code':
             text = force_text(children[0].text)
             code = CodeHilite(text,
                         force_linenos=self.config['force_linenos'],
                         guess_lang=self.config['guess_lang'],
                         css_class=self.config['css_class'],
                         style=self.config['pygments_style'],
                         noclasses=self.config['noclasses'],
                         tab_length=self.markdown.tab_length)
             placeholder = self.markdown.htmlStash.store(code.hilite(),
                                                         safe=True)
             # Clear codeblock in etree instance
             block.clear()
             # Change to p element which will later
             # be removed when inserting raw html
             block.tag = 'p'
             block.text = placeholder
开发者ID:150vb,项目名称:zulip,代码行数:24,代码来源:codehilite.py

示例14: handle

    def handle(self, *args, **options):
        # type: (*Any, **str) -> None

        string_id = options['string_id']
        bot_email = options['bot_email']
        service_name = options['service_name']
        base_url = options['base_url']

        encoding = sys.getfilesystemencoding()
        realm = get_realm(force_text(string_id, encoding))
        if realm is None:
            print('Unknown subdomain or string_id %s' % (string_id,))
            exit(1)

        if not bot_email:
            print('Email of existing bot must be provided')
            exit(1)

        if not service_name:
            print('Name for Service object must be provided')
            exit(1)

        if not base_url:
            print('Base URL of outgoing webhook must be provided')
            exit(1)

        # TODO: Normalize email?
        bot_profile = UserProfile.objects.get(email=bot_email)
        if not bot_profile:
            print('User %s does not exist' % (bot_email,))
            exit(1)
        if not bot_profile.is_bot:
            print('User %s is not a bot' % (bot_email,))
            exit(1)
        if bot_profile.is_outgoing_webhook_bot:
            print('%s is already marked as an outgoing webhook bot' % (bot_email,))
            exit(1)

        Service.objects.create(name=service_name,
                               user_profile=bot_profile,
                               base_url=base_url,
                               token='',
                               interface=1)

        bot_profile.bot_type = UserProfile.OUTGOING_WEBHOOK_BOT
        bot_profile.save()

        print('Successfully converted %s into an outgoing webhook bot' % (bot_email,))
开发者ID:JamesLinus,项目名称:zulip,代码行数:48,代码来源:convert_bot_to_outgoing_webhook.py

示例15: highlight_string_bytes_offsets

def highlight_string_bytes_offsets(text, locs):
    # type: (AnyStr, Iterable[Tuple[int, int]]) -> Text
    string = force_bytes(text)
    highlight_start = b'<span class="highlight">'
    highlight_stop = b'</span>'
    pos = 0
    result = b''
    for loc in locs:
        (offset, length) = loc
        result += string[pos:offset]
        result += highlight_start
        result += string[offset:offset + length]
        result += highlight_stop
        pos = offset + length
    result += string[pos:]
    return force_text(result)
开发者ID:souravbadami,项目名称:zulip,代码行数:16,代码来源:messages.py


注:本文中的zerver.lib.str_utils.force_text函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。