Esempio n. 1
0
#!/usr/bin/env python
# encoding: utf-8

from colors import ColorsPrint

CLP = ColorsPrint()
CLP.notify_color('info', '装饰器演示')


def decorator(f):
    def new_f(a, b):
        print("input", a, b)
        return f(a, b)

    return new_f


# get square sum
@decorator
def square_sum(a, b):
    return a ** 2 + b ** 2


# get square diff
@decorator
def square_diff(a, b):
    return a ** 2 - b ** 2


print(square_sum(3, 4))
print(square_diff(3, 4))
Esempio n. 2
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2016/11/16 17:45
# @Author  : GHL
# @File    : check_sql.py


# 从模板中导入某一个类
from colors import ColorsPrint as CLP
import re

CL = CLP()
CL.notify_color('notify', '检查mysql 脚本')


class MysqlCheck(object):
    def __init__(self, filename):
        self.filename = filename

    def check_file(self):
        try:
            with open(self.filename.decode('utf-8')) as f: # 若路径含有中文open需要做编码处理
                contents = f.read()
                update_reg = re.compile(r"^\s*UPDATE[\s\w.,!=()'`\[\]\n+\-\x80-\xff]*;$", re.I | re.M)
                alter_reg = re.compile(r"^\s*ALTER[\w\s'`\-()\n.:=%,+\x80-\xff]*;$", re.I | re.M)
                delete_reg = re.compile(r"^\s*DELETE[\w\s'`.=><!]*;$", re.I | re.M)
                create_table_reg = re.compile(r'^\s*CREATE TABLE[\w\s.=(),\'`\n+/\-\x80-\xff]*', re.I | re.M)
                create_view_reg = re.compile(r"^\s*CREATE VIEW[\w\s.=(),'`\n+/\-\x80-\xff]*", re.I | re.M)
                # utf-8 字符集匹配中文 \x80-\xff unicode 字符集匹配中文为 \u3040-\u309f
                match_create_table = re.findall(create_table_reg, contents)
                match_create_view = re.findall(create_view_reg, contents)