Skip to content

Commit

Permalink
formatter code style
Browse files Browse the repository at this point in the history
  • Loading branch information
Eastwu5788 committed Aug 25, 2020
1 parent 17fa063 commit 8cfe7a5
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 34 deletions.
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
.. py:currentmodule:: pre_request
Version 2.1.4 (Unreleased)
------------------------------

- 修复使用过程中发现的问题
- 规整代码规范


Version 2.1.3
------------------------

Expand Down
2 changes: 1 addition & 1 deletion pre_request/filters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# @Author: 'Wu Dong <wudong@eastwu.cn>'
# @Time: '2020-03-17 15:34'
# flake8: noqa

from pre_request.filters.simple.empty_filter import EmptyFilter
from pre_request.filters.simple.trim_filter import TrimFilter
from pre_request.filters.simple.length_filter import LengthFilter
Expand All @@ -29,6 +28,7 @@
from pre_request.filters.cross.equal_key_filter import EqualKeyFilter
from pre_request.filters.cross.required_with_filter import RequiredWithFilter


simple_filters = [
"EmptyFilter", # 1.判断字段是否为空的过滤器
"SplitFilter", # 字符串分割过滤器
Expand Down
26 changes: 26 additions & 0 deletions pre_request/macro.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# !/usr/local/python/bin/python
# -*- coding: utf-8 -*-
# (C) Wu Dong, 2020
# All rights reserved
# @Author: 'Wu Dong <wudong@eastwu.cn>'
# @Time: '2020-08-25 09:46'

# Project config key
K_CONTENT_TYPE = "PRE_CONTENT_TYPE"
K_FUZZY = "PRE_FUZZY"
K_STORE_KEY = "PRE_STORE_KEY"
K_SKIP_FILTER = "PRE_SKIP_FILTER"

# Regexp key
# email regexp
K_EMAIL_REG = r'^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$'
# mobile regexp
K_MOBILE_REG = r'^0\d{2,3}\d{7,8}$|^1[3578]\d{9}$|^14[579]\d{8}$'
# file path regexp
K_FILE_REG = r'^(?<1>.*[\\/])(?<2>.+)\.(?<3>.+)?$|^(?<1>.*[\\/])(?<2>.+)$|^(?<2>.+)\.(?<3>.+)?$|^(?<2>.+)$'
# mac address regexp
K_MAC_REG = r'^([0-9a-fA-F][0-9a-fA-F]:){5}([0-9a-fA-F][0-9a-fA-F])$'
# latitude regexp
K_LATITUDE_REG = r'^[\-\+]?((0|([1-8]\d?))(\.\d{1,10})?|90(\.0{1,10})?)$'
# longitude regexp
K_LONGITUDE_REG = r'^[\-\+]?(0(\.\d{1,10})?|([1-9](\d)?)(\.\d{1,10})?|1[0-7]\d{1}(\.\d{1,10})?|180\.0{1,10})$'
30 changes: 9 additions & 21 deletions pre_request/regexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,15 @@
# sys
import re


# email regexp
K_EMAIL_REG = r'^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$'


# mobile regexp
K_MOBILE_REG = r'^0\d{2,3}\d{7,8}$|^1[3578]\d{9}$|^14[579]\d{8}$'


# file path regexp
K_FILE_REG = r'^(?<1>.*[\\/])(?<2>.+)\.(?<3>.+)?$|^(?<1>.*[\\/])(?<2>.+)$|^(?<2>.+)\.(?<3>.+)?$|^(?<2>.+)$'


# mac address regexp
K_MAC_REG = r'^([0-9a-fA-F][0-9a-fA-F]:){5}([0-9a-fA-F][0-9a-fA-F])$'


# latitude regexp
K_LATITUDE_REG = r'^[\-\+]?((0|([1-8]\d?))(\.\d{1,10})?|90(\.0{1,10})?)$'
# longitude regexp
K_LONGITUDE_REG = r'^[\-\+]?(0(\.\d{1,10})?|([1-9](\d)?)(\.\d{1,10})?|1[0-7]\d{1}(\.\d{1,10})?|180\.0{1,10})$'
# project
from .macro import (
K_EMAIL_REG,
K_FILE_REG,
K_LATITUDE_REG,
K_LONGITUDE_REG,
K_MAC_REG,
K_MOBILE_REG
)


class Regexp:
Expand Down
31 changes: 19 additions & 12 deletions pre_request/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,26 @@
# object
from .exception import ParamsValueError
from .filters.base import BaseFilter
from .filters import simple_filters, complex_filters
from .response import JSONResponse, HTMLResponse, BaseResponse
from .filters import (
complex_filters,
simple_filters,
)
from .macro import (
K_CONTENT_TYPE,
K_FUZZY,
K_SKIP_FILTER,
K_STORE_KEY
)
from .response import (
BaseResponse,
HTMLResponse,
JSONResponse,
)
from .rules import Rule
from .utils import get_deep_value
from . import filters


k_content_type = "PRE_CONTENT_TYPE"
k_fuzzy = "PRE_FUZZY"
k_store_key = "PRE_STORE_KEY"
k_skip_filter = "PRE_SKIP_FILTER"


class PreRequest:
""" An object to dispatch filters to handler request params
"""
Expand Down Expand Up @@ -65,10 +72,10 @@ def init_app(self, app, config=None):
basic_config.update(config)
config = basic_config

self.fuzzy = config.get(k_fuzzy, False)
self.content_type = config.get(k_content_type, "application/json")
self.store_key = config.get(k_store_key, "params")
self.skip_filter = config.get(k_skip_filter, False)
self.fuzzy = config.get(K_FUZZY, False)
self.content_type = config.get(K_CONTENT_TYPE, "application/json")
self.store_key = config.get(K_STORE_KEY, "params")
self.skip_filter = config.get(K_SKIP_FILTER, False)

self.app = app
app.extensions["pre_request"] = self
Expand Down

0 comments on commit 8cfe7a5

Please sign in to comment.