From c59901a4679faff44844bffdf877dc859fd1351a Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Sat, 4 Feb 2006 20:18:18 +0000 Subject: [PATCH] Improved 'inspectdb' handling of Python keywords from [2271] to use the 'keywords' module rather than hard-coding the list of keywords. git-svn-id: http://code.djangoproject.com/svn/django/trunk@2272 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/core/management.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/django/core/management.py b/django/core/management.py index f13d80d7677..5ea9539d256 100644 --- a/django/core/management.py +++ b/django/core/management.py @@ -562,13 +562,12 @@ def inspectdb(db_name): "Generator that introspects the tables in the given database name and returns a Django model, one line at a time." from django.core import db from django.conf import settings + import keyword def table2model(table_name): object_name = table_name.title().replace('_', '') return object_name.endswith('s') and object_name[:-1] or object_name - reserved_python_words = set(['and', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while']) - settings.DATABASE_NAME = db_name cursor = db.db.cursor() yield "# This is an auto-generated Django model module." @@ -593,7 +592,7 @@ def inspectdb(db_name): comment_notes = [] # Holds Field notes, to be displayed in a Python comment. extra_params = {} # Holds Field parameters such as 'db_column'. - if column_name in reserved_python_words: + if keyword.iskeyword(column_name): extra_params['db_column'] = column_name column_name += '_field' comment_notes.append('Field renamed because it was a Python reserved word.')