python类lower()的实例源码

mod.py 文件源码 项目:rforms 作者: Jakeable 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def user_lookup(username):
    # shows a user's page
    is_json = False
    if username.endswith(".json"):
        username = username.split(".")[0]
        is_json = True

    user = User.query.filter_by(username=username).first()
    if not user:
        # check to see if a similar username exists
        user = User.query.filter(User.username.ilike(username)).first()
        show_warning = True
    if user.username.lower() == username.lower():
        show_warning = False
    if not user:
        return abort(404)
    if is_json:
        return jsonify(username=user.username,
                       response_md=user.full_body_md,
                       response_html=user.full_body_html,
                       submitted=user.submitted,
                       processed=user.processed,
                       last_login=user.last_login)
    return render_template(
        "user.html",
        user=user,
        username=username,
        show_warning=show_warning)
api.py 文件源码 项目:rforms 作者: Jakeable 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def remove_mod():
    # removes a user from the list of moderators
    username = request.form["username"]
    user = User.query.filter(func.lower(User.username)
                             == func.lower(username)).first()
    if not user:
        return bad_request("user not found")
    user.form_mod = False
    db.session.add(user)
    db.session.commit()
    return jsonify(status="OK"), 200
test_select.py 文件源码 项目:python_ddd_flask 作者: igorvinnicius 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_composed_multiple(self):
        table = self.tables.some_table
        lx = (table.c.x + table.c.y).label('lx')
        ly = (func.lower(table.c.q) + table.c.p).label('ly')
        self._assert_result(
            select([lx, ly]).order_by(lx, ly.desc()),
            [(3, util.u('q1p3')), (5, util.u('q2p2')), (7, util.u('q3p1'))]
        )
posts.py 文件源码 项目:knowledge-repo 作者: airbnb 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def get_query_param_set(params):
    """
    Strip, lowercase, and remove empty params to be used in a query
    """
    param_set = params.strip().lower().split(" ")
    param_set = [p for p in param_set if len(p) > 0]
    return param_set
userregistry.py 文件源码 项目:websauna 作者: websauna 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_by_username(self, username):
        return self.dbsession.query(self.User).filter(func.lower(self.User.username) == username.lower()).first()
userregistry.py 文件源码 项目:websauna 作者: websauna 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def get_by_email(self, email):
        return self.dbsession.query(self.User).filter(func.lower(self.User.email) == email.lower()).first()
handler.py 文件源码 项目:dino 作者: thenetcircle 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def get_black_list(self) -> set:
        @with_session
        def _get_black_list(session=None):
            rows = session.query(BlackList).all()
            return {row.word.lower().strip() for row in rows}

        blacklist = self.env.cache.get_black_list()
        if blacklist is not None:
            return blacklist

        blacklist = _get_black_list()
        if len(blacklist) > 0:
            self.env.cache.set_black_list(blacklist)
        return blacklist
handler.py 文件源码 项目:dino 作者: thenetcircle 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def remove_matching_word_from_blacklist(self, word: str) -> None:
        @with_session
        def _delete(_word: str, session=None) -> None:
            session.query(BlackList).filter(func.lower(BlackList.word) == func.lower(_word))\
                .delete(synchronize_session='fetch')
            session.commit()

        if word is None or len(word.strip()) == 0:
            raise ValueError('empty word when deleting from word list')
        _delete(word)
        self.env.cache.reset_black_list()
handler.py 文件源码 项目:dino 作者: thenetcircle 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def add_words_to_blacklist(self, words: list, session=None) -> None:
        all_words = {row.word.lower() for row in session.query(BlackList).all()}
        for word in words:
            if word is None or len(word.strip()) == 0 or word.strip().lower() in all_words:
                continue
            blacklisted = BlackList()
            blacklisted.word = word
            session.add(blacklisted)
        session.commit()
        self.env.cache.reset_black_list()
test_select.py 文件源码 项目:webapp 作者: superchilli 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_composed_multiple(self):
        table = self.tables.some_table
        lx = (table.c.x + table.c.y).label('lx')
        ly = (func.lower(table.c.q) + table.c.p).label('ly')
        self._assert_result(
            select([lx, ly]).order_by(lx, ly.desc()),
            [(3, util.u('q1p3')), (5, util.u('q2p2')), (7, util.u('q3p1'))]
        )
1e1a63d3d186_original_resource_id_not_null.py 文件源码 项目:gnocchi 作者: gnocchixyz 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def clean_substr(col, start, length):
    return func.lower(func.substr(func.hex(col), start, length))
test_select.py 文件源码 项目:QualquerMerdaAPI 作者: tiagovizoto 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def test_composed_multiple(self):
        table = self.tables.some_table
        lx = (table.c.x + table.c.y).label('lx')
        ly = (func.lower(table.c.q) + table.c.p).label('ly')
        self._assert_result(
            select([lx, ly]).order_by(lx, ly.desc()),
            [(3, util.u('q1p3')), (5, util.u('q2p2')), (7, util.u('q3p1'))]
        )
lib.py 文件源码 项目:dbas 作者: hhucn 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def get_all_arguments_with_text_and_url_by_statement_id(statement_uid, urlmanager, color_statement=False, is_jump=False):
    """
    Given a statement_uid, it returns all arguments, which use this statement and adds
    the corresponding text to it, which normally appears in the bubbles. The resulting
    text depends on the provided language.

    :param statement_uid: Id to a statement, which should be analyzed
    :param color_statement: True, if the statement (specified by the ID) should be colored
    :return: list of dictionaries containing some properties of these arguments
    :rtype: list
    """
    logger('DBAS.LIB', 'get_all_arguments_with_text_by_statement_id', 'main ' + str(statement_uid))
    arguments = get_all_arguments_by_statement(statement_uid)
    uids = [arg.uid for arg in arguments] if arguments else None
    results = list()
    sb = '<{} data-argumentation-type="position">'.format(tag_type) if color_statement else ''
    se = '</{}>'.format(tag_type) if color_statement else ''

    if not uids:
        return []

    uids.sort()
    for uid in uids:
        statement_text = get_text_for_statement_uid(statement_uid)
        attack_type = 'jump' if is_jump else ''
        argument_text = get_text_for_argument_uid(uid, anonymous_style=True, attack_type=attack_type)
        pos = argument_text.lower().find(statement_text.lower())
        argument_text = argument_text[0:pos] + sb + argument_text[pos:pos + len(statement_text)] + se + argument_text[pos + len(statement_text):]
        results.append({'uid': uid,
                        'text': argument_text,
                        'url': urlmanager.get_url_for_jump(False, uid)})
    return results
lib.py 文件源码 项目:dbas 作者: hhucn 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def get_user_by_case_insensitive_nickname(nickname):
    """
    Returns user with given nickname

    :param nickname: String
    :return: User or None
    """
    return DBDiscussionSession.query(User).filter(func.lower(User.nickname) == func.lower(nickname)).first()
lib.py 文件源码 项目:dbas 作者: hhucn 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def get_user_by_case_insensitive_public_nickname(public_nickname):
    """
    Returns user with given public nickname

    :param public_nickname: String
    :return: User or None
    """
    return DBDiscussionSession.query(User).filter(func.lower(User.public_nickname) == func.lower(public_nickname)).first()
lib.py 文件源码 项目:dbas 作者: hhucn 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def bubbles_already_last_in_list(bubble_list, bubbles):
    """
    Are the given bubbles already at the end of the bubble list

    :param bubble_list: list of Bubbles
    :param bubbles:  list of bubbles
    :return: Boolean
    """
    if isinstance(bubbles, list):
        length = len(bubbles)
    else:
        length = 1
        bubbles = [bubbles]

    if len(bubble_list) < length:
        return False

    for bubble in bubbles:
        if 'message' not in bubble:
            return False

    start_index = - length
    is_already_in = False
    for bubble in bubbles:

        last = bubble_list[start_index]
        if 'message' not in last or 'message' not in bubble:
            return False

        text1 = __cleanhtml(last['message'].lower()).strip()
        text2 = __cleanhtml(bubble['message'].lower()).strip()
        is_already_in = is_already_in or (text1 == text2)
        start_index += 1

    return is_already_in
matcher.py 文件源码 项目:dbas 作者: hhucn 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def get_strings_for_duplicates_or_reasons(value, issue, oem_value_uid=None):
    """
    Checks different textversion-strings for a match with given value

    :param value: string
    :param issue: Issue.uid
    :param oem_value: integer
    :return: dict()
    """
    db_statements = get_not_disabled_statement_as_query().filter_by(issue_uid=issue).all()
    return_array = []

    for stat in db_statements:
        if stat.uid is oem_value_uid:
            continue

        db_tv = DBDiscussionSession.query(TextVersion).filter_by(statement_uid=stat.uid).order_by(TextVersion.uid.asc()).first()
        if value.lower() in db_tv.content.lower():  # and db_tv.content.lower() != oem_value.lower():
            rd = __get_fuzzy_string_dict(current_text=value, return_text=db_tv.content, uid=db_tv.statement_uid)  # TODO #432
            return_array.append(rd)

    return_array = __sort_array(return_array)

    # logger('fuzzy_string_matcher', 'get_strings_for_duplicates_or_reasons',
    # 'string: {}, issue {}, len(dict): '.format(value, issue, len(return_array))

    return return_array[:list_length]
matcher.py 文件源码 项目:dbas 作者: hhucn 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def __get_fuzzy_string_dict(index=0, current_text='', return_text='', uid=0):
    """
    Returns dictionary with index, distance, text and statement_uid as keys

    :param index: int
    :param current_text: string
    :param return_text: string
    :param uid: int
    :return: dict()
    """
    return {'index': index,
            'distance': get_distance(current_text.lower(), return_text.lower()),
            'text': return_text,
            'statement_uid': uid}
matcher.py 文件源码 项目:dbas 作者: hhucn 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def get_lev_distance(a, b):
    """
    Returns the levensthein distance between to strings

    :param a: first string
    :param b: second string
    :return: distance between a and b
    """
    dist = distance(a.strip().lower(), b.strip().lower())
    #  logger('fuzzy_string_matcher', 'get_distance', 'levensthein: ' + str(dist) + ', value: ' + a.lower() + ' in: ' + b.lower())
    return str(dist).zfill(max_count_zeros)


问题


面经


文章

微信
公众号

扫码关注公众号