def genops(pickle):
 import cStringIO as StringIO
 if isinstance(pickle, str):
  pickle = StringIO.StringIO(pickle)
 if hasattr(pickle, 'tell'):
  getpos = pickle.tell
 else:
  getpos = (lambda : None)
 while True:
  pos = getpos()
  code = pickle.read(1)
  opcode = code2op.get(code)
  if (opcode is None):
   if (code == ''):
    raise ValueError('pickle exhausted before seeing STOP')
   else:
    raise ValueError(('at position %s, opcode %r unknown' % ((((pos is None) and '<unknown>') or pos), code)))
  if (opcode.arg is None):
   arg = None
  else:
   arg = opcode.arg.reader(pickle)
  (yield (opcode, arg, pos))
  if (code == '.'):
   assert (opcode.name == 'STOP')
   break

def genops ( pickle ) : import cStringIO as StringIO if isinstance ( pickle , str ) : pickle = StringIO . StringIO ( pickle ) if hasattr ( pickle , 'tell' ) : getpos = pickle . tell else : getpos = ( lambda : None ) while True : pos = getpos ( ) code = pickle . read ( 1 ) opcode = code2op . get ( code ) if ( opcode is None ) : if ( code == '' ) : raise ValueError ( 'pickle exhausted before seeing STOP' ) else : raise ValueError ( ( 'at position %s, opcode %r unknown' % ( ( ( ( pos is None ) and '<unknown>' ) or pos ) , code ) ) ) if ( opcode . arg is None ) : arg = None else : arg = opcode . arg . reader ( pickle ) ( yield ( opcode , arg , pos ) ) if ( code == '.' ) : assert ( opcode . name == 'STOP' ) break
generate all the opcodes in a pickle .