Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
warnings Namespace Reference

Data Structures

class  _OptionError
 

Functions

def warn
 
def warn_explicit
 
def showwarning
 
def formatwarning
 
def filterwarnings
 
def resetwarnings
 

Variables

list __all__
 
string defaultaction = "default"
 
list filters = []
 
dictionary onceregistry = {}
 

Detailed Description

Python part of the warnings subsystem.

Function Documentation

def warnings.filterwarnings (   action,
  message = "",
  category = Warning,
  module = "",
  lineno = 0,
  append = 0 
)
Insert an entry into the list of warnings filters (at the front).

Use assertions to check that all arguments have the right type.

Definition at line 113 of file warnings.py.

114  append=0):
115  """Insert an entry into the list of warnings filters (at the front).
116 
117  Use assertions to check that all arguments have the right type."""
118 # assert action in ("error", "ignore", "always", "default", "module",
119 # "once"), "invalid action: %s" % `action`
120 # assert isinstance(message, types.StringType), "message must be a string"
121 # assert isinstance(category, types.ClassType), "category must be a class"
122 # assert issubclass(category, Warning), "category must be a Warning subclass"
123 # assert type(module) is types.StringType, "module must be a string"
124 # assert type(lineno) is types.IntType and lineno >= 0, \
125 # "lineno must be an int >= 0"
126 # item = (action, re.compile(message, re.I), category,
127 # re.compile(module), lineno)
128 # if append:
129 # filters.append(item)
130 # else:
131 # filters.insert(0, item)
def warnings.formatwarning (   message,
  category,
  filename,
  lineno 
)
Function to format a warning the standard way.

Definition at line 103 of file warnings.py.

References filterwarnings(), linecache.getline(), and string.strip().

104 def formatwarning(message, category, filename, lineno):
105  """Function to format a warning the standard way."""
106  import linecache
107  s = "%s:%s: %s: %s\n" % (filename, lineno, category.__name__, message)
108  line = linecache.getline(filename, lineno).strip()
109  if line:
110  s = s + " " + line + "\n"
111  return s
def warnings.resetwarnings ( )
Reset the list of warnings filters to its default state.

Definition at line 132 of file warnings.py.

133 def resetwarnings():
134  """Reset the list of warnings filters to its default state."""
135  filters[:] = []
def warnings.showwarning (   message,
  category,
  filename,
  lineno,
  file = None 
)
Hook to write a warning to a file; replace if you like.

Definition at line 97 of file warnings.py.

References formatwarning().

97 
98 def showwarning(message, category, filename, lineno, file=None):
99  """Hook to write a warning to a file; replace if you like."""
100  if file is None:
101  file = sys.stderr
102  file.write(formatwarning(message, category, filename, lineno))
def warnings.warn (   message,
  category = None,
  stacklevel = 1 
)
Issue a warning, or maybe ignore it or raise an exception.

Definition at line 12 of file warnings.py.

References warn_explicit().

12 
13 def warn(message, category=None, stacklevel=1):
14  """Issue a warning, or maybe ignore it or raise an exception."""
15  # Check category argument
16  if category is None:
17  category = UserWarning
18  assert issubclass(category, Warning)
19  # Get context information
20  try:
21  caller = sys._getframe(stacklevel)
22  except ValueError:
23  globals = sys.__dict__
24  lineno = 1
25  else:
26  globals = caller.f_globals
27  lineno = caller.f_lineno
28  if globals.has_key('__name__'):
29  module = globals['__name__']
30  else:
31  module = "<string>"
32  filename = globals.get('__file__')
33  if filename:
34  fnl = filename.lower()
35  if fnl.endswith(".pyc") or fnl.endswith(".pyo"):
36  filename = filename[:-1]
37  else:
38  if module == "__main__":
39  filename = sys.argv[0]
40  if not filename:
41  filename = module
42  registry = globals.setdefault("__warningregistry__", {})
43  warn_explicit(message, category, filename, lineno, module, registry)
def warnings.warn_explicit (   message,
  category,
  filename,
  lineno,
  module = None,
  registry = None 
)

Definition at line 45 of file warnings.py.

References string.lower(), showwarning(), and locale.str().

45 
46  module=None, registry=None):
47  if module is None:
48  module = filename
49  if module[-3:].lower() == ".py":
50  module = module[:-3] # XXX What about leading pathname?
51  if registry is None:
52  registry = {}
53  key = (message, category, lineno)
54  # Quick test for common case
55  if registry.get(key):
56  return
57  # Search the filters
58  for item in filters:
59  action, msg, cat, mod, ln = item
60  if (msg.match(message) and
61  issubclass(category, cat) and
62  mod.match(module) and
63  (ln == 0 or lineno == ln)):
64  break
65  else:
66  action = defaultaction
67  # Early exit actions
68  if action == "ignore":
69  registry[key] = 1
70  return
71  if action == "error":
72  raise category(message)
73  # Other actions
74  if action == "once":
75  registry[key] = 1
76  oncekey = (message, category)
77  if onceregistry.get(oncekey):
78  return
79  onceregistry[oncekey] = 1
80  elif action == "always":
81  pass
82  elif action == "module":
83  registry[key] = 1
84  altkey = (message, category, 0)
85  if registry.get(altkey):
86  return
87  registry[altkey] = 1
88  elif action == "default":
89  registry[key] = 1
90  else:
91  # Unrecognized actions are errors
92  raise RuntimeError(
93  "Unrecognized action (%s) in warnings.filters:\n %s" %
94  (`action`, str(item)))
95  # Print message and context
96  showwarning(message, category, filename, lineno)

Variable Documentation

list __all__
Initial value:
1 = ["warn", "showwarning", "formatwarning", "filterwarnings",
2  "resetwarnings"]

Definition at line 5 of file warnings.py.

string defaultaction = "default"

Definition at line 8 of file warnings.py.

list filters = []

Definition at line 9 of file warnings.py.

dictionary onceregistry = {}

Definition at line 10 of file warnings.py.