momosecurity / aswan

陌陌风控系统静态规则引擎,零基础简易便捷的配置多种复杂规则,实时高效管控用户异常行为。
GNU Lesser General Public License v2.1
2.99k stars 828 forks source link

Python 3 compatibility issues #1

Closed cclauss closed 5 years ago

cclauss commented 5 years ago

Python 2 end of life is in less than 200 days...

flake8 testing of https://github.com/momosecurity/aswan on Python 3.7.1

$ flake8 . --count --select=E9,F63,F72,F82 --show-source --statistics

./www/rule/views.py:219:26: F821 undefined name 'unicode'
                'error': unicode(e),
                         ^
./www/rule/templatetags/reverse_tags.py:28:35: F821 undefined name 'basestring'
        if not isinstance(object, basestring):
                                  ^
./www/rule/templatetags/reverse_tags.py:37:26: F821 undefined name 'basestring'
    if isinstance(value, basestring):
                         ^
./www/rule/templatetags/reverse_tags.py:78:13: F821 undefined name 'unicode'
    value = unicode(value)
            ^
./www/core/utils.py:11:17: F821 undefined name 'unicode'
        (k, map(unicode, v))
                ^
./www/core/columns.py:14:30: F821 undefined name 'basestring'
        if isinstance(value, basestring) and len(value) > self.truncate_limit:
                             ^
./www/settings/settings.py:138:50: E999 SyntaxError: invalid syntax
    exec 'from local_settings.{risk_env} import *'.format(risk_env=risk_env)
                                                 ^
./www/strategy/largest_period.py:75:35: E999 SyntaxError: invalid syntax
    print get_source_largest_period()
                                  ^
./www/strategy/forms.py:224:33: F821 undefined name 'reduce'
                strategy_time = reduce(lambda x, y: x * y, args)
                                ^
./www/strategy/templatetags/reverse_tags.py:29:35: F821 undefined name 'basestring'
        if not isinstance(object, basestring):
                                  ^
./www/strategy/templatetags/reverse_tags.py:38:26: F821 undefined name 'basestring'
    if isinstance(value, basestring):
                         ^
./www/strategy/templatetags/reverse_tags.py:79:13: F821 undefined name 'unicode'
    value = unicode(value)
            ^
./risk_models/source.py:160:66: F821 undefined name 'basestring'
        return 'user_id' in data and isinstance(data['user_id'], basestring)
                                                                 ^
./builtin_funcs/sample.py:8:44: F821 undefined name 'basestring'
                               ('user_id', basestring),
                                           ^
./builtin_funcs/sample.py:29:44: F821 undefined name 'basestring'
                               ('user_id', basestring),
                                           ^
./config/base.py:36:42: E999 SyntaxError: invalid syntax
    exec 'from config.{risk_env} import *'.format(risk_env=risk_env)
                                         ^
3     E999 SyntaxError: invalid syntax
13    F821 undefined name 'basestring'
16

E901,E999,F821,F822,F823 are the "showstopper" flake8 issues that can halt the runtime with a SyntaxError, NameError, etc. These 5 are different from most other flake8 issues which are merely "style violations" -- useful for readability but they do not effect runtime safety.

leohowell commented 5 years ago

@cclauss Thanks a lot. Porting current project code to Python 3 that is exactly what we are doing on schedule.

huohuohahei commented 5 years ago

curl 127.0.0.1:50000/report/ -X POST -d '{"source": "test", "user_id": "10000", "ip": "127.0.0.1", "uid": "abcabc112333222"}' -H "Content-Type:application/json" {"ec": 100, "error": "invalid source"} @leohowell 是什么原因呢