Forbid using python keywords as names

closes #4
master
Salvo 'LtWorf' Tomaselli 2017-05-12 22:50:01 +07:00
parent d61bfafe5c
commit 0778be30a1
No known key found for this signature in database
GPG Key ID: B3A7CF0C801886CF
2 changed files with 5 additions and 2 deletions

@ -1,5 +1,6 @@
2.6
- Improved survey sending
- Prevent names from being reserved keywords
2.5
- Add new class of tests for queries that are supposed to fail

@ -1,5 +1,5 @@
# Relational
# Copyright (C) 2008-2016 Salvo "LtWorf" Tomaselli
# Copyright (C) 2008-2017 Salvo "LtWorf" Tomaselli
#
# Relation is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -21,6 +21,7 @@
# implementing dates to use in selection.
import datetime
import keyword
import re
RELATION_NAME_REGEXP = re.compile(r'^[_a-z][_a-z0-9]*$', re.IGNORECASE)
@ -161,7 +162,8 @@ class Rdate (object):
def is_valid_relation_name(name):
'''Checks if a name is valid for a relation.
Returns boolean'''
return re.match(RELATION_NAME_REGEXP, name) != None
return re.match(RELATION_NAME_REGEXP, name) != None and not keyword.iskeyword(name)
# Backwards compatibility
rdate = Rdate