Lines Matching +full:file +full:- +full:lines

1 # -*- coding: iso-8859-1 -*-
12 isroutine() - check object types
13 getmembers() - get members of an object that satisfy a given condition
15 getfile(), getsourcefile(), getsource() - find an object's source code
16 getdoc(), getcomments() - get documentation on an object
17 getmodule() - determine the module that an object came from
18 getclasstree() - arrange classes so as to represent their hierarchy
20 getargspec(), getargvalues(), getcallargs() - get info about function arguments
21 formatargspec(), formatargvalues() - format an argument spec
22 getouterframes(), getinnerframes() - get info about frames
23 currentframe() - get the current stack frame
24 stack(), trace() - get info about frames on the stack or in a traceback
29 __author__ = 'Ka-Ping Yee <[email protected]>'
50 # ----------------------------------------------------------- type-checking
56 __file__ filename (missing for built-in modules)"""
90 the other tests promise more -- you can, e.g., count on having the
143 """Return true if the object is a user-defined function.
156 """Return true if the object is a user-defined generator function.
176 the result of the current yield-expression
195 f_builtins built-in namespace seen by this frame
215 co_filename name of file in which this code object was created
227 """Return true if the object is a built-in function or method.
229 Built-in functions and methods provide these attributes:
263 """Return list of attribute-descriptor tuples.
265 For each name in dir(cls), the return list contains a 4-tuple
330 # ----------------------------------------------------------- class helpers
348 # -------------------------------------------------- source code extraction
352 return len(expline) - len(string.lstrip(expline))
374 lines = string.split(string.expandtabs(doc), '\n')
378 # Find minimum indentation of any non-blank lines after first line.
380 for line in lines[1:]:
383 indent = len(line) - content
386 if lines:
387 lines[0] = lines[0].lstrip()
389 for i in range(1, len(lines)): lines[i] = lines[i][margin:]
390 # Remove any trailing or leading blank lines.
391 while lines and not lines[-1]:
392 lines.pop()
393 while lines and not lines[0]:
394 lines.pop(0)
395 return string.join(lines, '\n')
398 """Work out which source or compiled file an object was defined in."""
402 raise TypeError('{!r} is a built-in module'.format(object))
407 raise TypeError('{!r} is a built-in class'.format(object))
424 """Get the module name, suffix, mode, and module type for a given file."""
427 (-len(info[0]), info[0], info[1], info[2]),
435 """Return the module name for a given file, or None."""
444 if string.lower(filename[-4:]) in ('.pyc', '.pyo'):
445 filename = filename[:-4] + '.py'
447 if 'b' in mode and string.lower(filename[-len(suffix):]) == suffix:
448 # Looks like a binary file. We want to only return a text file.
452 # only return a non-existent filename if the module has a PEP 302 loader
460 """Return an absolute path to the source or compiled file for an object.
480 # Try the cache again with the absolute file name
482 file = getabsfile(object, _filename)
485 if file in modulesbyfile:
486 return sys.modules.get(modulesbyfile[file])
500 if file in modulesbyfile:
501 return sys.modules.get(modulesbyfile[file])
518 """Return the entire source file and starting line number for an object.
521 or code object. The source code is returned as a list of all the lines
522 in the file and the line number indexes a line in that list. An IOError
525 file = getfile(object)
527 if not sourcefile and file[:1] + file[-1:] != '<>':
529 file = sourcefile if sourcefile else file
531 module = getmodule(object, file)
533 lines = linecache.getlines(file, module.__dict__)
535 lines = linecache.getlines(file)
536 if not lines:
540 return lines, 0
549 for i in range(len(lines)):
550 match = pat.match(lines[i])
553 if lines[i][0] == 'c':
554 return lines, i
561 return lines, candidates[0][1]
576 lnum = object.co_firstlineno - 1
579 if pat.match(lines[lnum]): break
580 lnum = lnum - 1
581 return lines, lnum
585 """Get lines of comments immediately preceding an object's source code.
590 lines, lnum = findsource(object)
595 # Look for a comment block at the top of the file.
597 if lines and lines[0][:2] == '#!': start = 1
598 while start < len(lines) and string.strip(lines[start]) in ('', '#'):
600 if start < len(lines) and lines[start][:1] == '#':
603 while end < len(lines) and lines[end][:1] == '#':
604 comments.append(string.expandtabs(lines[end]))
610 indent = indentsize(lines[lnum])
611 end = lnum - 1
612 if end >= 0 and string.lstrip(lines[end])[:1] == '#' and \
613 indentsize(lines[end]) == indent:
614 comments = [string.lstrip(string.expandtabs(lines[end]))]
616 end = end - 1
617 comment = string.lstrip(string.expandtabs(lines[end]))
618 while comment[:1] == '#' and indentsize(lines[end]) == indent:
620 end = end - 1
622 comment = string.lstrip(string.expandtabs(lines[end]))
625 while comments and string.strip(comments[-1]) == '#':
626 comments[-1:] = []
661 self.indent = self.indent - 1
669 # block as well, except the pseudo-tokens COMMENT and NL.
672 def getblock(lines): argument
673 """Extract the block of code at the top of the given list of lines."""
676 tokenize.tokenize(iter(lines).next, blockfinder.tokeneater)
679 return lines[:blockfinder.last]
682 """Return a list of source lines and starting line number for an object.
685 or code object. The source code is returned as a list of the lines
687 original source file the first line of code was found. An IOError is
689 lines, lnum = findsource(object)
694 # for module or frame that corresponds to module, return all source lines
697 return lines, 0
699 return getblock(lines[lnum:]), lnum + 1
707 lines, lnum = getsourcelines(object)
708 return string.join(lines, '')
710 # --------------------------------------------------- class tree extraction
725 whose entry immediately precedes the list. Each entry is a 2-tuple
747 # ------------------------------------------------ argument list extraction
792 remain[-1] = remain[-1] - 1
793 while remain[-1] == 0:
796 stack[-size:] = [stack[-size:]]
798 remain[-1] = remain[-1] - 1
819 'defaults' is an n-tuple of the default values of the last n arguments.
868 firstdefault = len(args) - len(defaults)
872 spec = spec + formatvalue(defaults[i - firstdefault])
950 assign(varargs, positional[-(num_pos-num_args):])
974 for arg, value in zip(args[-num_defaults:], defaults):
990 unassigned = num_args - len([arg for arg in args if is_assigned(arg)])
992 num_required = num_args - num_defaults
998 # -------------------------------------------------- stack frame extraction
1006 the current line, the function name, a list of lines of context from
1008 The optional second argument specifies the number of lines of context
1020 start = lineno - 1 - context//2
1022 lines, lnum = findsource(frame)
1024 lines = index = None
1027 start = max(0, min(start, len(lines) - context))
1028 lines = lines[start:start+context]
1029 index = lineno - 1 - start
1031 lines = index = None
1033 return Traceback(filename, lineno, frame.f_code.co_name, lines, index)
1044 name, a list of lines of context, and index within the context."""
1055 name, a list of lines of context, and index within the context."""