~ubuntu-branches/ubuntu/saucy/python-django/saucy-updates

« back to all changes in this revision

Viewing changes to extras/csrf_migration_helper.py

  • Committer: Package Import Robot
  • Author(s): Luke Faraone, Jakub Wilk, Luke Faraone
  • Date: 2013-05-09 15:10:47 UTC
  • mfrom: (1.1.21) (4.4.27 sid)
  • Revision ID: package-import@ubuntu.com-20130509151047-aqv8d71oj9wvcv8c
Tags: 1.5.1-2
[ Jakub Wilk ]
* Use canonical URIs for Vcs-* fields.

[ Luke Faraone ]
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
170
170
        try:
171
171
            return self._content
172
172
        except AttributeError:
173
 
            fd = open(self.absolute_filename)
174
 
            try:
175
 
                content = fd.read().decode(TEMPLATE_ENCODING)
176
 
            except UnicodeDecodeError, e:
177
 
                message = '%s in %s' % (
178
 
                    e[4], self.absolute_filename.encode('UTF-8', 'ignore'))
179
 
                raise UnicodeDecodeError(*(e.args[:4] + (message,)))
180
 
            fd.close()
 
173
            with open(self.absolute_filename) as fd:
 
174
                try:
 
175
                    content = fd.read().decode(TEMPLATE_ENCODING)
 
176
                except UnicodeDecodeError as e:
 
177
                    message = '%s in %s' % (
 
178
                        e[4], self.absolute_filename.encode('UTF-8', 'ignore'))
 
179
                    raise UnicodeDecodeError(*(e.args[:4] + (message,)))
181
180
            self._content = content
182
181
            return content
183
182
    content = property(content)
271
270
            for f in filenames:
272
271
                if len([True for e in PYTHON_SOURCE_EXTENSIONS if f.endswith(e)]) > 0:
273
272
                    fn = os.path.join(dirpath, f)
274
 
                    fd = open(fn)
275
 
                    content = [l.decode(PYTHON_ENCODING) for l in fd.readlines()]
276
 
                    fd.close()
 
273
                    with open(fn) as fd:
 
274
                        content = [l.decode(PYTHON_ENCODING) for l in fd.readlines()]
277
275
                    retval.append((fn, content))
278
276
    return retval
279
277
 
319
317
        found = search_python_list(python_code, to_search)
320
318
 
321
319
        # Display:
322
 
        print t.absolute_filename
 
320
        print(t.absolute_filename)
323
321
        for r in t.relative_filenames:
324
 
            print u"  AKA %s" % r
325
 
        print u"  POST forms: %s" % num_post_forms
326
 
        print u"  With token: %s" % (num_post_forms - len(form_lines_without_token))
 
322
            print("  AKA %s" % r)
 
323
        print("  POST forms: %s" % num_post_forms)
 
324
        print("  With token: %s" % (num_post_forms - len(form_lines_without_token)))
327
325
        if form_lines_without_token:
328
 
            print u"  Without token:"
 
326
            print("  Without token:")
329
327
            for ln in form_lines_without_token:
330
 
                print "%s:%d:" % (t.absolute_filename, ln)
331
 
        print
332
 
        print u"  Searching for:"
 
328
                print("%s:%d:" % (t.absolute_filename, ln))
 
329
        print('')
 
330
        print("  Searching for:")
333
331
        for r in to_search:
334
 
            print u"    " + r
335
 
        print
336
 
        print u"  Found:"
 
332
            print("    " + r)
 
333
        print('')
 
334
        print("  Found:")
337
335
        if len(found) == 0:
338
 
            print "    Nothing"
 
336
            print("    Nothing")
339
337
        else:
340
338
            for fn, ln in found:
341
 
                print "%s:%d:" % (fn, ln)
 
339
                print("%s:%d:" % (fn, ln))
342
340
 
343
 
        print
344
 
        print "----"
 
341
        print('')
 
342
        print("----")
345
343
 
346
344
 
347
345
parser = OptionParser(usage=USAGE)
356
354
    settings = getattr(options, 'settings', None)
357
355
    if settings is None:
358
356
        if os.environ.get("DJANGO_SETTINGS_MODULE", None) is None:
359
 
            print "You need to set DJANGO_SETTINGS_MODULE or use the '--settings' parameter"
 
357
            print("You need to set DJANGO_SETTINGS_MODULE or use the '--settings' parameter")
360
358
            sys.exit(1)
361
359
    else:
362
360
        os.environ["DJANGO_SETTINGS_MODULE"] = settings