Changeset 5700

Show
Ignore:
Timestamp:
08/17/12 17:44:53 (7 years ago)
Author:
mkaplan
Message:

Replaced creating duplicates with iterators to lowere memory consumption by the safety check

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • seattle/branches/repy_v2/repy/safe.py

    r5606 r5700  
    224224    raise exception_hierarchy.CheckNodeException(node.lineno,node.__class__.__name__) 
    225225   
    226   for attribute, value in node.__dict__.items(): 
     226  for attribute, value in node.__dict__.iteritems(): 
    227227    # Don't allow the construction of unicode literals 
    228228    if type(value) == unicode: 
     
    270270    Runs safe_check() in a subprocess. This is done because the AST safe_check() 
    271271    creates uses a large amount of RAM. By running safe_check() in a subprocess 
    272     we can guarantee that teh memory will be reclaimed when the process ends. 
     272    we can guarantee that the memory will be reclaimed when the process ends. 
    273273   
    274274  <Arguments> 
     
    424424# Populates `_builtin_globals` with keys for every built-in function 
    425425# The values will either be the actual function (if safe), a replacement  
    426 # function, or a function that raises an exception. 
     426# function, or a stub function that raises an exception. 
    427427def _builtin_init(): 
    428428  global _builtin_globals, _builtin_globals_backup 
     
    437437  _builtin_globals = {} 
    438438 
    439   for builtin in __builtin__.__dict__.keys(): 
     439  for builtin in __builtin__.__dict__.iterkeys(): 
    440440    # It's important to check _BUILTIN_REPLACE before _BUILTIN_OK because 
    441441    # even if the name is defined in both, there must be a security reason 
     
    464464def _builtin_destroy(): 
    465465  _builtin_init() 
    466   for builtin_name, builtin in _builtin_globals.items(): 
     466  for builtin_name, builtin in _builtin_globals.iteritems(): 
    467467    __builtin__.__dict__[builtin_name] = builtin 
    468468 
    469469# Restore every function in __builtin__ with the backup from _builtin_globals_backup. 
    470470def _builtin_restore(): 
    471   for builtin_name, builtin in _builtin_globals_backup.items(): 
     471  for builtin_name, builtin in _builtin_globals_backup.iteritems(): 
    472472    __builtin__.__dict__[builtin_name] = builtin 
    473473 
     
    572572 
    573573    # If we are given a dict, try to copy its keys 
    574     for key,value in from_dict.items(): 
     574    for key,value in from_dict.iteritems(): 
    575575      # Skip __builtins__ and __doc__ since safe_run/python inserts that 
    576576      if key in ["__builtins__","__doc__"]: 
     
    627627  # Return the key set 
    628628  def keys(self): 
    629     # Get the keys from the underlying dict 
    630     keys = self.__under__.keys() 
    631  
    632     # Filter out the unsafe keys 
     629 
     630    # Filter out the unsafe keys from the underlying dict 
    633631    safe_keys = [] 
    634632 
    635     for key in keys: 
     633    for key in self.__under__.iterkeys(): 
    636634      if _is_string_safe(key): 
    637635        safe_keys.append(key)