Back to index

python3.2  3.2.2
Classes | Functions | Variables
findnocoding Namespace Reference

Classes

class  pysource

Functions

def get_declaration
def has_correct_encoding
def needs_declaration

Variables

string __author__ = "Oleg Broytmann, Georg Brandl"
tuple decl_re = re.compile(r"coding[=:]\s*([-\w.]+)")
string usage
 is_python = pysource.looks_like_python
 debug = False
tuple result = needs_declaration(fullpath)

Function Documentation

Definition at line 37 of file findnocoding.py.

00037 
00038 def get_declaration(line):
00039     match = decl_re.search(line)
00040     if match:
00041         return match.group(1)
00042     return ''

Here is the caller graph for this function:

def findnocoding.has_correct_encoding (   text,
  codec 
)

Definition at line 43 of file findnocoding.py.

00043 
00044 def has_correct_encoding(text, codec):
00045     try:
00046         str(text, codec)
00047     except UnicodeDecodeError:
00048         return False
00049     else:
00050         return True

Here is the caller graph for this function:

def findnocoding.needs_declaration (   fullpath)

Definition at line 51 of file findnocoding.py.

00051 
00052 def needs_declaration(fullpath):
00053     try:
00054         infile = open(fullpath, 'rU')
00055     except IOError: # Oops, the file was removed - ignore it
00056         return None
00057 
00058     line1 = infile.readline()
00059     line2 = infile.readline()
00060 
00061     if get_declaration(line1) or get_declaration(line2):
00062         # the file does have an encoding declaration, so trust it
00063         infile.close()
00064         return False
00065 
00066     # check the whole file for non utf-8 characters
00067     rest = infile.read()
00068     infile.close()
00069 
00070     if has_correct_encoding(line1+line2+rest, "utf-8"):
00071         return False
00072 
00073     return True
00074 

Here is the call graph for this function:


Variable Documentation

string findnocoding.__author__ = "Oleg Broytmann, Georg Brandl"

Definition at line 8 of file findnocoding.py.

Definition at line 87 of file findnocoding.py.

tuple findnocoding.decl_re = re.compile(r"coding[=:]\s*([-\w.]+)")

Definition at line 35 of file findnocoding.py.

Definition at line 86 of file findnocoding.py.

Definition at line 102 of file findnocoding.py.

Initial value:
00001 """Usage: %s [-cd] paths...
00002     -c: recognize Python source files trying to compile them
00003     -d: debug output"""

Definition at line 75 of file findnocoding.py.