Skip to content

Instantly share code, notes, and snippets.

View staugur's full-sized avatar
:octocat:
Sorry, thank you!

Hiroshi.tao staugur

:octocat:
Sorry, thank you!
View GitHub Profile
@staugur
staugur / Python URL Validation.py
Created September 3, 2019 08:24 — forked from Integralist/Python URL Validation.py
[Python URL Validation] #python #urls #validation
import re
ip_middle_octet = u"(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5]))"
ip_last_octet = u"(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))"
regex = re.compile(
u"^"
# protocol identifier
u"(?:(?:https?|ftp)://)"
# user:pass authentication
@staugur
staugur / autojsonresp.py
Last active September 24, 2019 07:18
统一返回json数据,允许主动触发异常,拦截所有http异常转为json
# coding:utf8
from flask import Flask, Response, jsonify
from werkzeug.exceptions import HTTPException
class JsonResponse(Response):
@classmethod
def force_type(cls, rv, environ=None):