From 1c8c73ebfa2c20a204bcd3bdcffaebb78fa1e7ff Mon Sep 17 00:00:00 2001 From: Pablo Hoffman Date: Tue, 19 Aug 2008 19:52:31 +0000 Subject: [PATCH] added some validation to new spider module names --HG-- extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%40174 --- scrapy/trunk/scrapy/command/commands/genspider.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scrapy/trunk/scrapy/command/commands/genspider.py b/scrapy/trunk/scrapy/command/commands/genspider.py index bb72916ef..07e6b0500 100644 --- a/scrapy/trunk/scrapy/command/commands/genspider.py +++ b/scrapy/trunk/scrapy/command/commands/genspider.py @@ -1,4 +1,5 @@ import os +import string from scrapy.spider import spiders from scrapy.command import ScrapyCommand @@ -33,6 +34,9 @@ class Command(ScrapyCommand): spiders_module = __import__(settings['NEWSPIDER_MODULE'], {}, {}, ['']) spidersdir = os.path.abspath(os.path.dirname(spiders_module.__file__)) + if name[0] not in string.letters: # must start with a letter, for valid python modules + name = "a" + name + name = name.replace('-', '_') # - are replaced by _, for valid python modules self._genfiles('spider.tmpl', '%s/%s.py' % (spidersdir, name), tvars) def _genfiles(self, template_name, source_name, tvars):