Back to index

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

Classes

class  PythonIndenter
class  StringReader
class  StringWriter

Functions

def complete_filter
def delete_filter
def reformat_filter
def complete_string
def delete_string
def reformat_string
def complete_file
def delete_file
def reformat_file
def error_both
def test

Variables

int STEPSIZE = 8
int TABSIZE = 8
int EXPANDTABS = 0
dictionary next = {}
string start = 'if'
string usage

Function Documentation

def pindent.complete_file (   filename,
  stepsize = STEPSIZE,
  tabsize = TABSIZE,
  expandtabs = EXPANDTABS 
)

Definition at line 423 of file pindent.py.

00423 
00424 def complete_file(filename, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
00425     source = open(filename, 'r').read()
00426     result = complete_string(source, stepsize, tabsize, expandtabs)
00427     if source == result: return 0
00428     # end if
00429     import os
00430     try: os.rename(filename, filename + '~')
00431     except os.error: pass
00432     # end try
00433     f = open(filename, 'w')
00434     f.write(result)
00435     f.close()
00436     return 1
00437 # end def complete_file

Here is the call graph for this function:

def pindent.complete_filter (   input = sys.stdin,
  output = sys.stdout,
  stepsize = STEPSIZE,
  tabsize = TABSIZE,
  expandtabs = EXPANDTABS 
)

Definition at line 338 of file pindent.py.

00338 
00339                     stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
00340     pi = PythonIndenter(input, output, stepsize, tabsize, expandtabs)
00341     pi.complete()
00342 # end def complete_filter

Here is the call graph for this function:

Here is the caller graph for this function:

def pindent.complete_string (   source,
  stepsize = STEPSIZE,
  tabsize = TABSIZE,
  expandtabs = EXPANDTABS 
)

Definition at line 399 of file pindent.py.

00399 
00400 def complete_string(source, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
00401     input = StringReader(source)
00402     output = StringWriter()
00403     pi = PythonIndenter(input, output, stepsize, tabsize, expandtabs)
00404     pi.complete()
00405     return output.getvalue()
00406 # end def complete_string

Here is the caller graph for this function:

def pindent.delete_file (   filename,
  stepsize = STEPSIZE,
  tabsize = TABSIZE,
  expandtabs = EXPANDTABS 
)

Definition at line 438 of file pindent.py.

00438 
00439 def delete_file(filename, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
00440     source = open(filename, 'r').read()
00441     result = delete_string(source, stepsize, tabsize, expandtabs)
00442     if source == result: return 0
00443     # end if
00444     import os
00445     try: os.rename(filename, filename + '~')
00446     except os.error: pass
00447     # end try
00448     f = open(filename, 'w')
00449     f.write(result)
00450     f.close()
00451     return 1
00452 # end def delete_file

Here is the call graph for this function:

def pindent.delete_filter (   input = sys.stdin,
  output = sys.stdout,
  stepsize = STEPSIZE,
  tabsize = TABSIZE,
  expandtabs = EXPANDTABS 
)

Definition at line 344 of file pindent.py.

00344 
00345                         stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
00346     pi = PythonIndenter(input, output, stepsize, tabsize, expandtabs)
00347     pi.delete()
00348 # end def delete_filter

Here is the call graph for this function:

Here is the caller graph for this function:

def pindent.delete_string (   source,
  stepsize = STEPSIZE,
  tabsize = TABSIZE,
  expandtabs = EXPANDTABS 
)

Definition at line 407 of file pindent.py.

00407 
00408 def delete_string(source, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
00409     input = StringReader(source)
00410     output = StringWriter()
00411     pi = PythonIndenter(input, output, stepsize, tabsize, expandtabs)
00412     pi.delete()
00413     return output.getvalue()
00414 # end def delete_string

Here is the caller graph for this function:

def pindent.error_both (   op1,
  op2 
)

Definition at line 483 of file pindent.py.

00483 
00484 def error_both(op1, op2):
00485     sys.stderr.write('Error: You can not specify both '+op1+' and -'+op2[0]+' at the same time\n')
00486     sys.stderr.write(usage)
00487     sys.exit(2)
00488 # end def error_both

Here is the caller graph for this function:

def pindent.reformat_file (   filename,
  stepsize = STEPSIZE,
  tabsize = TABSIZE,
  expandtabs = EXPANDTABS 
)

Definition at line 453 of file pindent.py.

00453 
00454 def reformat_file(filename, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
00455     source = open(filename, 'r').read()
00456     result = reformat_string(source, stepsize, tabsize, expandtabs)
00457     if source == result: return 0
00458     # end if
00459     import os
00460     try: os.rename(filename, filename + '~')
00461     except os.error: pass
00462     # end try
00463     f = open(filename, 'w')
00464     f.write(result)
00465     f.close()
00466     return 1
00467 # end def reformat_file
00468 
00469 # Test program when called as a script

Here is the call graph for this function:

def pindent.reformat_filter (   input = sys.stdin,
  output = sys.stdout,
  stepsize = STEPSIZE,
  tabsize = TABSIZE,
  expandtabs = EXPANDTABS 
)

Definition at line 350 of file pindent.py.

00350 
00351                     stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
00352     pi = PythonIndenter(input, output, stepsize, tabsize, expandtabs)
00353     pi.reformat()
00354 # end def reformat_filter

Here is the caller graph for this function:

def pindent.reformat_string (   source,
  stepsize = STEPSIZE,
  tabsize = TABSIZE,
  expandtabs = EXPANDTABS 
)

Definition at line 415 of file pindent.py.

00415 
00416 def reformat_string(source, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
00417     input = StringReader(source)
00418     output = StringWriter()
00419     pi = PythonIndenter(input, output, stepsize, tabsize, expandtabs)
00420     pi.reformat()
00421     return output.getvalue()
00422 # end def reformat_string

Here is the caller graph for this function:

def pindent.test ( )

Definition at line 489 of file pindent.py.

00489 
00490 def test():
00491     import getopt
00492     try:
00493         opts, args = getopt.getopt(sys.argv[1:], 'cdrs:t:e')
00494     except getopt.error as msg:
00495         sys.stderr.write('Error: %s\n' % msg)
00496         sys.stderr.write(usage)
00497         sys.exit(2)
00498     # end try
00499     action = None
00500     stepsize = STEPSIZE
00501     tabsize = TABSIZE
00502     expandtabs = EXPANDTABS
00503     for o, a in opts:
00504         if o == '-c':
00505             if action: error_both(o, action)
00506             # end if
00507             action = 'complete'
00508         elif o == '-d':
00509             if action: error_both(o, action)
00510             # end if
00511             action = 'delete'
00512         elif o == '-r':
00513             if action: error_both(o, action)
00514             # end if
00515             action = 'reformat'
00516         elif o == '-s':
00517             stepsize = int(a)
00518         elif o == '-t':
00519             tabsize = int(a)
00520         elif o == '-e':
00521             expandtabs = 1
00522         # end if
00523     # end for
00524     if not action:
00525         sys.stderr.write(
00526                 'You must specify -c(omplete), -d(elete) or -r(eformat)\n')
00527         sys.stderr.write(usage)
00528         sys.exit(2)
00529     # end if
00530     if not args or args == ['-']:
00531         action = eval(action + '_filter')
00532         action(sys.stdin, sys.stdout, stepsize, tabsize, expandtabs)
00533     else:
00534         action = eval(action + '_file')
00535         for filename in args:
00536             action(filename, stepsize, tabsize, expandtabs)
00537         # end for
00538     # end if
00539 # end def test

Here is the call graph for this function:


Variable Documentation

Definition at line 82 of file pindent.py.

Definition at line 87 of file pindent.py.

Definition at line 94 of file pindent.py.

Definition at line 80 of file pindent.py.

Definition at line 81 of file pindent.py.

Initial value:
00001 """
00002 usage: pindent (-c|-d|-r) [-s stepsize] [-t tabsize] [-e] [file] ...
00003 -c         : complete a correctly indented program (add #end directives)
00004 -d         : delete #end directives
00005 -r         : reformat a completed program (use #end directives)
00006 -s stepsize: indentation step (default %(STEPSIZE)d)
00007 -t tabsize : the worth in spaces of a tab (default %(TABSIZE)d)
00008 -e         : expand TABs into spaces (defailt OFF)
00009 [file] ... : files are changed in place, with backups in file~
00010 If no files are specified or a single - is given,
00011 the program acts as a filter (reads stdin, writes stdout).
00012 """

Definition at line 470 of file pindent.py.