Пример #1
0
def validate_shown_fields(field):
    domain_fields = [
        'id', 'name', 'sponsor', 'sponsor_type', 'icp_number', 'icp_source',
        'icp_updated', 'website_count', 'subdomain_count', 'create_time',
        'update_time', 'city_code', 'region_code', 'industries',
        'national_level', 'tags'
    ]
    if field not in domain_fields:
        raise InvalidAPIRequest('无效的字段: {}'.format(field))
Пример #2
0
def validate_website_archived_shown_fields(field):
    domain_fields = [
        'url', 'domain', 'domain_id', 'city_code', 'region_code', 'ip',
        'ip_area', 'title', 'web_type', 'host_dept', 'host_type', 'industries',
        'ai_industries', 'tags', 'code_language', 'http_status',
        'http_status_list', 'category', 'id'
    ]

    if field not in domain_fields:
        raise InvalidAPIRequest('无效的字段: {}'.format(field))
Пример #3
0
def website_url_not_in_db(url):
    domain = db.session.query(DomainArchived).filter_by(
        name=get_fld(url)).first()
    if not domain:
        raise InvalidAPIRequest('主域名未收录,请先添加主域名')
    for model in [
            WebsiteArchived, WebsiteNews, WebsiteRecycler, WebsiteBanned,
            WebsiteDuplicated
    ]:
        if db.session.query(model).filter_by(url=url.strip('/')).first():
            raise RecordAlreadyExists('已有此网站')
Пример #4
0
    def handle_bad_request(error):
        """
        Custom error handler for 400 http exception.
        Returns a JSON object with a message of bad request.
        """

        tb = traceback.format_exc()
        message = "HTTP请求异常(参数解析错误)"
        current_app.logger.error(
            "{}:{}\n{}".format(BadRequest.__name__, error.description, tb))
        response = jsonify(InvalidAPIRequest(message=message).to_dict())
        response.status_code = BadRequest.code
        return response
Пример #5
0
    def method_not_allowed(error):
        """
        Custom error handler for 405 http exception.
        Returns a JSON object with a message that accessed URL was not found.
        """

        tb = traceback.format_exc()
        message = "HTTP请求异常(不允许的请求方法)"
        current_app.logger.error(
            "{}:{}\n{}".format(MethodNotAllowed.__name__, error.description, tb))
        response = jsonify(InvalidAPIRequest(
            message=message, status_code=MethodNotAllowed.code).to_dict())
        response.status_code = MethodNotAllowed.code
        return response
Пример #6
0
 def __call__(self, value):
     if value not in self.choices:
         raise InvalidAPIRequest(self.desc)
Пример #7
0
def length_validator(length):
    if length < 0 or length > 100:
        raise InvalidAPIRequest('长度应在0-100之间')