def __sample_neighbor_nodes(self, sample_size, nodeId):
     '''
     Sample subset of neighborhood nodes. 
     '''    
     p = sample_size
     neighbor_nodes = Set()
     held_out_set = self._network.get_held_out_set()
     test_set = self._network.get_test_set()
     
     while p > 0:
         nodeList = random.sample_range("neighbor sampler", self._N, sample_size * 2)
         if self._compatibility_mode:  # to be able to replay from C++
             nodeList = sorted(nodeList)
         for neighborId in nodeList:
                 if p < 0:
                     if False:
                         print sys._getframe().f_code.co_name + ": Are you sure p < 0 is a good idea?"
                     break
                 if neighborId == nodeId:
                     continue
                 # check condition, and insert into mini_batch_set if it is valid. 
                 edge = (min(nodeId, neighborId), max(nodeId, neighborId))
                 if edge in held_out_set or edge in test_set or neighborId in neighbor_nodes:
                     continue
                 else:
                     # add it into mini_batch_set
                     neighbor_nodes.add(neighborId)
                     p -= 1
                     
     if self._compatibility_mode:  # to be able to replay from C++
         neighbor_nodes = sorted(neighbor_nodes)
     return neighbor_nodes
Example #2
0
def set_trace():
    from IPython.core.debugger import Pdb
    try:
        Pdb(color_scheme='Linux').set_trace(sys._getframe().f_back)
    except:
        from pdb import Pdb as OldPdb
        OldPdb().set_trace(sys._getframe().f_back)
Example #3
0
def dump_packet(data):
    def is_ascii(data):
        if 65 <= byte2int(data) <= 122:
            if isinstance(data, int):
                return chr(data)
            return data
        return '.'

    try:
        print("packet length:", len(data))
        print("method call[1]:", sys._getframe(1).f_code.co_name)
        print("method call[2]:", sys._getframe(2).f_code.co_name)
        print("method call[3]:", sys._getframe(3).f_code.co_name)
        print("method call[4]:", sys._getframe(4).f_code.co_name)
        print("method call[5]:", sys._getframe(5).f_code.co_name)
        print("-" * 88)
    except ValueError:
        pass
    dump_data = [data[i:i+16] for i in range_type(0, min(len(data), 256), 16)]
    for d in dump_data:
        print(' '.join(map(lambda x: "{:02X}".format(byte2int(x)), d)) +
              '   ' * (16 - len(d)) + ' ' * 2 +
              ' '.join(map(lambda x: "{}".format(is_ascii(x)), d)))
    print("-" * 88)
    print()
Example #4
0
 def update_newdevice(self,res):
     '''添加新的小机到数据库'''
     dbcon = QueryDB().get_dbconn()
     mirco_devices = QueryDB.get_devices_table(res.vendor)
     if not mirco_devices.exists(engine):
         mirco_devices.create(engine)
     s = sql.select([mirco_devices.c.devid]).where(mirco_devices.c.devid == res.tuid)
     row = ''
     try:
         result = dbcon.execute(s)
         row = result.fetchall()
     except:
         self.errqueue.send(','.join([LOG_ERROR_DB,res.tuid,str(sys._getframe().f_lineno)]))
     ipadr = int(binascii.hexlify(socket.inet_aton(res.host[0])),16) & 0xFFFFFFFF
     ipprt = res.host[1] & 0xFFFF
     #print "host %d:%d" % (ipadr,ipprt)
     data = ''
     if res.attrs.has_key(STUN_ATTRIBUTE_DATA):
         data = res.attrs[STUN_ATTRIBUTE_DATA][-1]
 
     if not row: # 找不到这个UUID 就插入新的
         ins = mirco_devices.insert().values(devid=res.tuid,is_active=True,
                 is_online=True,chost=[ipadr,ipprt],data=data,last_login_time=datetime.now())
         try:
             result = dbcon.execute(ins)
         except:
             self.errqueue.send(','.join([LOG_ERROR_DB,res.tuid,str(sys._getframe().f_lineno)]))
         #print "insert new devices result fetchall"
     else:
         upd = mirco_devices.update().values(is_online=True,chost = [ipadr,ipprt],data=data,
                 last_login_time=datetime.now()).where(mirco_devices.c.devid == res.tuid)
         try:
             result = dbcon.execute(upd)
         except:
             self.errqueue.send(','.join([LOG_ERROR_DB,res.tuid,str(sys._getframe().f_lineno)]))
Example #5
0
  def write_hash_manifests(self):
    if not self.manifests_updated:
      return False

    today = datetime.datetime.strftime(
      datetime.datetime.now(), "%Y%m%d%H%M%S")
    for alg in set(self.algorithms):
      manifest_path = os.path.join(self.path, 'manifest-{}.txt'.format(alg))
      copy_manifest_path = os.path.join(self.path, 'manifest-{}-{}.old'.format(alg, today))
      try:
        shutil.copyfile(manifest_path, copy_manifest_path)
      except:
        LOGGER.error("Do not have permission to write new manifests")
      else:
        self.add_premisevent(process = "Copy Bag Manifest",
          msg = "{} copied to {} before writing new manifest".format(
            os.path.basename(manifest_path),
            os.path.basename(copy_manifest_path)),
          outcome = "Pass", sw_agent = sys._getframe().f_code.co_name)

      try:
        with open(manifest_path, 'w') as manifest:
          for payload_file, hashes in self.entries.items():
            if payload_file.startswith("data" + os.sep):
              manifest.write("{} {}\n".format(hashes[alg], bagit._encode_filename(payload_file)))
      except:
        LOGGER.error("Do not have permission to overwrite hash manifests")
      else:
        LOGGER.info("{} written".format(manifest_path))
        self.add_premisevent(process = "Write Bag Manifest",
          msg = "{} written as a result of new or updated payload files".format(
            os.path.basename(manifest_path)),
          outcome = "Pass", sw_agent = sys._getframe().f_code.co_name)

    return True
 def GetShowBanner(self, show_id, update=False):
     image = None
     if show_id == '0':
         return ''
     file_path = xbmc.translatePath('special://temp/sb/cache/images/'+show_id+'.banner.jpg')
     if not os.path.exists(file_path) or update:
         # Download image from SB server.
         try:
             image = GetUrlData(url=settings.__url__+'?cmd=show.getbanner&tvdbid='+str(show_id), add_useragent=True, encodeType=None)
             if (image == None) or (len(image) < 1024):
                 # Get generic image instead.
                 with open(xbmc.translatePath('special://home/addons/plugin.video.sickrage/resources/images/missing_banner.jpg'), mode='rb') as f:
                     image = f.read()
         except Exception, e:
             settings.errorWindow(sys._getframe().f_code.co_name, self.CONNECT_ERROR+str(e))
             return ''
         # Write image file to local cache.
         try:
             if not os.path.exists(os.path.dirname(file_path)):
                 os.makedirs(os.path.dirname(file_path))
             f = open(file_path, 'wb+')
             f.write(image)
             f.close()
         except Exception, e:
             settings.errorWindow(sys._getframe().f_code.co_name, str(e))
Example #7
0
def find_chain(obj, predicate, edge_func, max_depth=20, extra_ignore=()):
    queue = [obj]
    depth = {id(obj): 0}
    parent = {id(obj): None}
    ignore = set(extra_ignore)
    ignore.add(id(extra_ignore))
    ignore.add(id(queue))
    ignore.add(id(depth))
    ignore.add(id(parent))
    ignore.add(id(ignore))
    ignore.add(id(sys._getframe()))  # this function
    ignore.add(id(sys._getframe(1))) # find_chain/find_backref_chain, most likely
    gc.collect()
    while queue:
        target = queue.pop(0)
        if predicate(target):
            chain = [target]
            while parent[id(target)] is not None:
                target = parent[id(target)]
                chain.append(target)
            return chain
        tdepth = depth[id(target)]
        if tdepth < max_depth:
            referrers = edge_func(target)
            ignore.add(id(referrers))
            for source in referrers:
                if id(source) in ignore:
                    continue
                if id(source) not in depth:
                    depth[id(source)] = tdepth + 1
                    parent[id(source)] = target
                    queue.append(source)
    return [obj] # not found
Example #8
0
 def execfile(self,filename,globals=None,locals=None):
     if globals is None:
         globals = sys._getframe(1).f_globals
     if locals is None:
         locals = sys._getframe(1).f_locals
     with open(filename,"r") as fh:
         exec(fh.read()+"\n",globals,locals)
Example #9
0
    def __init__(self, depth=1, moduleLevel = False, allowed_scope=None):
        scope, module, f_locals, f_globals, codeinfo = \
            getFrameInfo(sys._getframe(depth+1))

        if allowed_scope and scope not in allowed_scope:
            raise TypeError("This directive is not allowed "
                            "to run in this scope: %s"%scope)

        if scope == 'module':
            self.name = f_locals['__name__']
        else:
            self.name = codeinfo[2]

        self.locals = f_locals
        self.scope = scope
        self.module = module
        self.codeinfo = codeinfo

        api.mods.add(self.module.__name__)

        if depth > 1:
            _, mod, _, _, ci = getFrameInfo(sys._getframe(2))
            self.hash = (module.__name__, codeinfo[1], mod.__name__, ci[1])
        else:
            self.hash = (module.__name__, codeinfo[1])
Example #10
0
 def get_netns(self):
     """
     Get all the network namespace in each network node.
     """
     count = 0
     start = time.time()
     try:
         for agent in self.agents:
             c = "ssh %s -o 'StrictHostKeyChecking=no' 'ip netns | grep qdhcp'" % (
                 self.agents[agent]['host'])
             pipe = subprocess.Popen(c, shell=True, stdout=subprocess.PIPE).stdout
             for line in pipe:
                 s = line.strip().split('qdhcp-')
                 self.net_in_ns[agent].append(s[1])
                 count = count + 1
     except:
         logger.warning("%s:%s() %d: %s %s", self.__class__.__name__,
                        sys._getframe().f_code.co_name, sys._getframe().f_lineno,
                        sys.exc_info()[0], sys.exc_info()[1])
         raise
     finally:
         duration = time.time() - start
         logger.info("%s:%s() %d: found %d IP network namespace in %.3f seconds",
                     self.__class__.__name__,
                     sys._getframe().f_code.co_name, sys._getframe().f_lineno,
                     count, duration)
Example #11
0
 def find_diff(self):
     """
     Find the difference between the set from mySQL and ip network namespace.
     """
     count = 0
     try:
         for agent in self.agents:
             in_agent = [x for x in self.net_in_agent[agent] if x not in self.net_in_ns[agent]]
             in_ns = [x for x in self.net_in_ns[agent] if x not in self.net_in_agent[agent]]
             if len(in_agent) + len(in_ns) > 0:
                 print("DHCP agent in %s:" % self.agents[agent]['host'])
                 for net in in_agent:
                     if net in self.networks:
                         print("  %s %s is in mySQL but not in ip-netns" %
                              (net, self.networks[net]))
                     else:
                         print("  %s is in mySQL but not in net-list" % net)
                     count = count + 1
                 for net in in_ns:
                     if net in self.networks:
                         print("  %s %s is in ip-netns but not in mySQL" %
                              (net, self.networks[net]))
                     else:
                         print("  %s is in ip-netns but not in net-list" % net)
                     count = count + 1
     except:
         logger.warning("%s:%s() %d: %s %s", self.__class__.__name__,
                        sys._getframe().f_code.co_name, sys._getframe().f_lineno,
                        sys.exc_info()[0], sys.exc_info()[1])
         raise
     finally:
         print("Found %d discrepancies in network-to-agent between mySQL and IP network namespace" % count)
Example #12
0
   def __getattr2( self, name ):             # "running" getattr
    # handle "from ROOT import *" ... can be called multiple times
      if name == '__all__':
         caller = sys.modules[ sys._getframe( 1 ).f_globals[ '__name__' ] ]

       # we may be calling in from __getattr1, verify and if so, go one frame up
         if caller == self:
            caller = sys.modules[ sys._getframe( 2 ).f_globals[ '__name__' ] ]

       # setup the pre-defined globals
         for name in self.module.__pseudo__all__:
            caller.__dict__[ name ] = getattr( _root, name )

       # install the hook
         _root.SetRootLazyLookup( caller.__dict__ )

       # return empty list, to prevent further copying
         return self.module.__all__

    # lookup into ROOT (which may cause python-side enum/class/global creation)
      attr = _root.LookupRootEntity( name )

    # the call above will raise AttributeError as necessary; so if we get here,
    # attr is valid: cache as appropriate, so we don't come back
      if type(attr) == _root.PropertyProxy:
         setattr( self.__class__, name, attr )         # descriptor
         return getattr( self, name )
      else:
         self.__dict__[ name ] = attr                  # normal member
         return attr

    # reaching this point means failure ...
      raise AttributeError( name )
Example #13
0
	def pl(value):
		print sys._getframe().f_code.co_name
		print 'value'
		print type(value)
		print value
		print 'length: ' + str( len(value))
		sys.exit('X')
def allow_self_input_http(blackholing, domainname):
    if blackholing == True:
        proc = subprocess.Popen(
            "ifconfig | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}' | uniq | grep -v %s"
            % current_ip(domainname),
            shell=True,
            stdout=subprocess.PIPE,
        )
    else:
        proc = subprocess.Popen(
            "ifconfig | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}' | uniq", shell=True, stdout=subprocess.PIPE
        )
    stdout_str = proc.stdout.read()
    vps_ips = return_ips(stdout_str, sys._getframe().f_code.co_name)
    for vps_ip in vps_ips:
        if blackholing == True:
            proc2 = subprocess.Popen(
                "/sbin/iptables -A INPUT -s {0} -p tcp -m multiport --dport 80,443 -j ACCEPT".format(vps_ip),
                shell=True,
                stdout=subprocess.PIPE,
            )
        else:
            proc2 = subprocess.Popen(
                "/sbin/iptables -A INPUT -s {0} -p tcp -m multiport --dport 80,443 -j ACCEPT".format(vps_ip),
                shell=True,
                stdout=subprocess.PIPE,
            )
        proc_check(proc2, sys._getframe().f_code.co_name)
Example #15
0
    def stop_download(download_id):
        log.log(__name__, sys._getframe().f_code.co_name, 'download_id %d' % download_id, log.LEVEL_DEBUG)

        download_to_stop = ManageDownload.get_download_by_id(download_id)
        log.log(__name__, sys._getframe().f_code.co_name, 'download to stop %s' % (download_to_stop.to_string()), log.LEVEL_DEBUG)

        ManageDownload.stop_download(download_to_stop)
Example #16
0
def interp(string):
  locals  = sys._getframe(1).f_locals
  globals = sys._getframe(1).f_globals
  for item in re.findall(r'#\{([^}]*)\}', string):
    string = string.replace('#{%s}' % item,
                            str(eval(item, globals, locals)))
  return string
Example #17
0
def unpacktype(binstr, member, mtype):
    offset = member[1]
    size = member[2]
    fmt = ''

    if mtype == STR:
        fmt = str(size) + 's'
    elif mtype == INT:
        fmt = 'I' if size == 4 else 'Q'
    elif mtype == SHT:
        fmt = 'H'
    else:
        calling_fxn = sys._getframe(1)
        stderr.write("ERROR %s.%s tried to unpack the unknown type %d.\n" % (
        callingclass(calling_fxn), calling_fxn.f_code.co_name, mtype))
        return None

    if struct.calcsize(fmt) != len(binstr[offset:size + offset]):
        calling_fxn = sys._getframe(1)
        stderr.write("ERROR %s.%s tried to unpack '%s' (fmt size: %d) from %d bytes.\n" % (
        callingclass(calling_fxn), calling_fxn.f_code.co_name, fmt, struct.calcsize(fmt),
        len(binstr[offset:size + offset])))
        return None

    return struct.unpack(fmt, binstr[offset:size + offset])[0]
Example #18
0
def _test_timer_with_threads(timer, sleep, spawn, join=lambda x: x.join()):
    def light():
        factorial(10)
        sleep(0.1)
        factorial(10)
    def heavy():
        factorial(10000)
    def profile(profiler):
        with profiler:
            c1 = spawn(light)
            c2 = spawn(heavy)
            for c in [c1, c2]:
                join(c)
        stat1 = find_stats(profiler.stats, 'light')
        stat2 = find_stats(profiler.stats, 'heavy')
        return (stat1, stat2)
    # using the default timer.
    # light() ends later than heavy().  its total time includes heavy's also.
    normal_profiler = TracingProfiler(top_frames=[sys._getframe()])
    stat1, stat2 = profile(normal_profiler)
    assert stat1.deep_time >= stat2.deep_time
    # using the given timer.
    # light() ends later than heavy() like the above case.  but the total time
    # doesn't include heavy's.  each contexts should have isolated cpu time.
    contextual_profiler = TracingProfiler(top_frames=[sys._getframe()],
                                          timer=timer)
    stat1, stat2 = profile(contextual_profiler)
    assert stat1.deep_time < stat2.deep_time
Example #19
0
def downloadSubs(fpath, lang):
    global SVP_REV_NUMBER
    global RETRY
    pathinfo = fpath
    if os.path.sep != "\\":
        #*nix
        pathinfo = "E:\\" + pathinfo.replace(os.path.sep, "\\")
    filehash = genFileHash(fpath)
    shortname = getShortName(fpath)
    vhash = genVHash(SVP_REV_NUMBER, fpath.encode("utf-8"), filehash)
    formdata = []
    formdata.append(("pathinfo", pathinfo.encode("utf-8")))
    formdata.append(("filehash", filehash))
    if vhash:
        formdata.append(("vhash", vhash))
    formdata.append(("shortname", shortname.encode("utf-8")))
    if lang != "chn":
        formdata.append(("lang", lang))

    for server in ["www", "svplayer", "splayer1", "splayer2", "splayer3", "splayer4", "splayer5", "splayer6", "splayer7", "splayer8", "splayer9"]:
        for schema in ["http", "https"]:
            theurl = schema + "://" + server + ".shooter.cn/api/subapi.php"
            for i in range(1, RETRY+1):
                try:
                    log(sys._getframe().f_code.co_name, "Trying %s (retry %d)" % (theurl, i))
                    handle = urlopen(theurl, SVP_REV_NUMBER, formdata)
                    resp = handle.read()
                    if len(resp) > 1024:
                        return resp
                    else:
                        return ''
                except Exception, e:
                    log(sys._getframe().f_code.co_name, "Failed to access %s" % (theurl))
Example #20
0
def _d(msg, *args):
	"""
		Format a debug log message. This function will automatically append calling function name and file/line number.

		:Parameters:

			- `msg`  : Log message formatted using the Python `formatter class <https://docs.python.org/2/library/string.html#custom-string-formatting>`_.
			- `args` : Message arguments.

		:Usage:

			Log an integer or a float variable.

			.. code-block:: python

				_d("Var x has value {0}", x)

				_d("Var y is a float with value {0:0.2f} to 2 decimal places.", y)
	"""
	frame1=sys._getframe(1)
	frame2=sys._getframe(2)
	n=len(args)

	m1="{0} ({{{1}}}:{{{2}}}:{{{3}}}:{{{4}}})".format(msg,n, n+1, n+2, n+3)
	a1=list(args)+[frame1.f_code.co_name, frame2.f_code.co_name, frame2.f_code.co_filename, frame2.f_lineno]
	
	return m1.format(*a1)
Example #21
0
 def pr(self, name, a=None, kw=None):
     f = sys._getframe(2)
     if f.f_code.co_filename.endswith('ZODB/utils.py'):
         f = sys._getframe(3)
     f = '%s:%s' % (f.f_code.co_filename, f.f_lineno)
     print(id(self), self._lock, threading.get_ident(), f, name,
           a if a else '', kw if kw else '')
 def test_catch_multiple_models(self):
   print sys._getframe().f_code.co_name
   pdb_id = '203d'
   nob_out =  nbo.run(pdb_id)
   expected = [pdb_id] + ['-3']*3
   expected = ','.join(expected)
   self.assertEqual(nob_out[:len(expected)],expected)
Example #23
0
def send_events_local():
    global results
    client = MongoClient()
    mongodb = client[MONGODB_NAME] 

    start_time = time.time()
    valid_events = 0
    # Store raw event information
    for event in results:
        #entry = {}
        #for key in event.keys():
        #    entry[key] = event[key]
            # flag indicating whether this item has been processed.
        #    entry["processed"] = 0
        event["processed"] = 0
        collection = mongodb[EVENTS_COL]
        # get a list of event types to keep:
        # everything that starts with EVT defined in common.py
        temp_list = [CONF[key] for key in CONF if key.startswith("EVT")]
        events_type_list = list(chain(*temp_list))
        if get_prop(event, "TYPE_EVENT") in events_type_list:
            collection.insert(event)
            valid_events += 1
    print "=========== INCOMING EVENTS", len(results), "total,", valid_events, "valid. ============="
    print sys._getframe().f_code.co_name, "COMPLETED", (time.time() - start_time), "seconds"
Example #24
0
 def me_him(self,value,color="purple"):
     """
     me_him - determines current function prepends class name and displays caller function
     """
     if self.output_caller:
         self.color="".join(color)
         self._me="".join(sys._getframe(1).f_code.co_name)
         self._him="".join(sys._getframe(2).f_code.co_name)
         self._me_him="".join(value)+"."+self._me+self.colors['default']+self._him+"\x1b[00m"
         self._lineno=inspect.currentframe().f_back.f_lineno
         if self.colors_active:
             try:
                 if self.colors[color] and self.has_colors:
                     if self.show_lineno_caller:
                         if self.break_all:
                             sys.stdout.write("\n"+str(self._lineno)+": "+self.colors[self.color] + self._me_him + "\x1b[00m\n")
                             sys.stdout.write(self.colors['default']+" "+"\x1b[00m")#one space seperator
                         else:
                             sys.stdout.write(str(self._lineno)+": "+self.colors[self.color] + self._me_him + "\x1b[00m")
                             sys.stdout.write(self.colors['default']+" "+"\x1b[00m")#one space seperator
                     else:
                         if self.break_all:
                             sys.stdout.write("\n"+self.colors[self.color] + self._me_him + "\x1b[00m\n")
                             sys.stdout.write(self.colors['default']+" "+"\x1b[00m")#one space seperator
                         else:
                             sys.stdout.write(self.colors[self.color] + self._me_him + "\x1b[00m")
                             sys.stdout.write(self.colors['default']+" "+"\x1b[00m")#one space seperator
                 else:
                     sys.stdout.write(self._me_him)
             except (KeyError, e):
                 sys.stdout.write(self._me_him)
         else:
             sys.stdout.write(self._me_him)
Example #25
0
 def _find(self, name, type_=CausalSpace):
     try:
         for frame in range(0,63):
             if name in sys._getframe(frame).f_locals:
                 if isinstance(sys._getframe(frame).f_locals[name], type_):
                     return sys._getframe(frame).f_locals[name]
     except:pass
Example #26
0
File: testing.py Project: psi4/psi4
def _merge_psi4_qcel_apis(args, kwargs):
    """Outer shim to allow both Psi4-style and QCA-style testing interfaces through the same function.

    Notes
    -----
    `kwargs` modified (and returned) in-place

    """

    def process_digits(digits):
        if digits >= 1:
            return 10**-digits
        return digits

    if len(args) == 0:
        kwargs['label'] = sys._getframe().f_back.f_back.f_code.co_name

    elif len(args) == 1:
        if isinstance(args[0], str):
            kwargs['label'] = args[0]

        else:
            kwargs['atol'] = process_digits(args[0])
            kwargs['label'] = sys._getframe().f_back.f_back.f_code.co_name
            if 'verbose' in kwargs:
                kwargs['quiet'] = (kwargs.pop('verbose') < 1)

    elif len(args) == 2:
        kwargs['atol'] = process_digits(args[0])
        kwargs['label'] = args[1]
        if 'verbose' in kwargs:
            kwargs['quiet'] = (kwargs.pop('verbose') < 1)

    else:
        raise ValueError("""Not following either Psi4 or QCElemental API pattern for comparison.""")
Example #27
0
def debug(f):
    if zen_settings.get('debug'):
        # sublime.log_commands(True)
        frame = sys._getframe(1)
        if 'debug' in frame.f_code.co_name : frame = sys._getframe(2)
        line = frame.f_lineno
        print 'debug:ZenCoding.%s:%s:' % (__name__, line), f
 def test_catch_unknown_pairs(self):
   print sys._getframe().f_code.co_name
   pdb_id = '3a3w'
   nob_out =  nbo.run(pdb_id)
   expected = [pdb_id] + ['-2']*3
   expected = ','.join(expected)
   self.assertEqual(nob_out[:len(expected)],expected)
Example #29
0
def get_plugin_source(module=None, stacklevel=None):
    """Returns the :class:`PluginSource` for the current module or the given
    module.  The module can be provided by name (in which case an import
    will be attempted) or as a module object.

    If no plugin source can be discovered, the return value from this method
    is `None`.

    This function can be very useful if additional data has been attached
    to the plugin source.  For instance this could allow plugins to get
    access to a back reference to the application that created them.

    :param module: optionally the module to locate the plugin source of.
    :param stacklevel: defines how many levels up the module should search
                       for before it discovers the plugin frame.  The
                       default is 0.  This can be useful for writing wrappers
                       around this function.
    """
    if module is None:
        frm = sys._getframe((stacklevel or 0) + 1)
        name = frm.f_globals['__name__']
        glob = frm.f_globals
    elif isinstance(module, string_types):
        frm = sys._getframe(1)
        name = module
        glob = __import__(module, frm.f_globals,
                          frm.f_locals, ['__dict__']).__dict__
    else:
        name = module.__name__
        glob = module.__dict__
    return _discover_space(name, glob)
 def test_catch_bad_cryst1(self):
   print sys._getframe().f_code.co_name
   pdb_id = '2bvb'
   nob_out =  nbo.run(pdb_id)
   expected = [pdb_id] + ['-4']*3
   expected = ','.join(expected)
   self.assertEqual(nob_out[:len(expected)],expected)
Example #31
0
File: test.py Project: kool11/vnp
 def marketDataType(self, reqId, marketDataType):
     print(sys._getframe().f_code.co_name)
     print(locals())
Example #32
0
File: test.py Project: kool11/vnp
 def verifyCompleted(self, isSuccessful, errorText):
     print(sys._getframe().f_code.co_name)
     print(locals())
Example #33
0
File: test.py Project: kool11/vnp
 def verifyMessageAPI(self, apiData):
     print(sys._getframe().f_code.co_name)
     print(locals())
Example #34
0
File: test.py Project: kool11/vnp
 def positionEnd(self):
     print(sys._getframe().f_code.co_name)
     print(locals())
Example #35
0
File: test.py Project: kool11/vnp
 def position(self, account, contract, position, avgCost):
     print(sys._getframe().f_code.co_name)
     print(locals())
Example #36
0
File: test.py Project: kool11/vnp
 def commissionReport(self, commissionReport):
     print(sys._getframe().f_code.co_name)
     print(locals())
Example #37
0
File: test.py Project: kool11/vnp
 def nextValidId(self, orderId):
     print(sys._getframe().f_code.co_name)
     print(locals())
Example #38
0
File: test.py Project: kool11/vnp
 def deltaNeutralValidation(self, reqId, underComp):
     print(sys._getframe().f_code.co_name)
     print(locals())
Example #39
0
File: test.py Project: kool11/vnp
 def realtimeBar(self, reqId, time, open_, high, low, close, volume, wap, count):
     print(sys._getframe().f_code.co_name)
     print(locals())
Example #40
0
File: test.py Project: kool11/vnp
 def tickSnapshotEnd(self, reqId):
     print(sys._getframe().f_code.co_name)
     print(locals())
Example #41
0
File: test.py Project: kool11/vnp
 def scannerData(self, reqId, rank, contractDetails, distance, benchmark, projection, legsStr):
     print(sys._getframe().f_code.co_name)
     print(locals())
Example #42
0
File: test.py Project: kool11/vnp
 def fundamentalData(self, reqId, data):
     print(sys._getframe().f_code.co_name)
     print(locals())
Example #43
0
File: test.py Project: kool11/vnp
 def historicalData(self, reqId, date, open_, high, low, close, volume, barCount, WAP, hasGaps):
     print(sys._getframe().f_code.co_name)
     print(locals())
Example #44
0
File: test.py Project: kool11/vnp
 def scannerDataEnd(self, reqId):
     print(sys._getframe().f_code.co_name)
     print(locals())
Example #45
0
File: test.py Project: kool11/vnp
 def managedAccounts(self, accountsList):
     print(sys._getframe().f_code.co_name)
     print(locals())
Example #46
0
File: test.py Project: kool11/vnp
 def scannerParameters(self, xml):
     print(sys._getframe().f_code.co_name)
     print(locals())
Example #47
0
File: test.py Project: kool11/vnp
 def updateMktDepthL2(self, id_, position, marketMaker, operation, side, price, size):
     print(sys._getframe().f_code.co_name)
     print(locals())
Example #48
0
File: test.py Project: kool11/vnp
 def receiveFA(self, pFaDataType, cxml):
     print(sys._getframe().f_code.co_name)
     print(locals())
Example #49
0
File: test.py Project: kool11/vnp
 def execDetails(self, reqId, contract, execution):
     print(sys._getframe().f_code.co_name)
     print(locals())
Example #50
0
File: test.py Project: kool11/vnp
 def updateNewsBulletin(self, msgId, msgType, newsMessage, originExch):
     print(sys._getframe().f_code.co_name)
     print(locals())
Example #51
0
File: test.py Project: kool11/vnp
class TestApi(IbApi):
    print(sys._getframe().f_code.co_name)

    #----------------------------------------------------------------------
    def __init__(self):
        """Constructor"""
        super(TestApi, self).__init__()
        
    #----------------------------------------------------------------------
    def nextValidId(self, orderId):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def currentTime(self, time):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def connectAck(self):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def error(self, id_, errorCode, errorString):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def accountSummary(self, reqId, account, tag, value, curency):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def accountSummaryEnd(self, reqId):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def tickPrice(self, tickerId, field, price, canAutoExecute):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def tickSize(self, tickerId, field, size):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def tickOptionComputation(self, tickerId, tickType, impliedVol, delta, optPrice, pvDividend, gamma, vega, theta, undPrice):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def tickGeneric(self, tickerId, tickType, value):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def tickString(self, tickerId, tickType, value):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def tickEFP(self, tickerId, tickType, basisPoints, formattedBasisPoints, totalDividends, holdDays, futureLastTradeDate, dividendImpact, dividendsToLastTradeDate):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def orderStatus(self, orderId, status, filled, remaining, avgFillPrice, permId, parentId, lastFillPrice, clientId, whyHeld):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def openOrder(self, orderId, contract, order, orderState):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def openOrderEnd(self):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def winError(self, str_, lastError):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def connectionClosed(self):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def updateAccountValue(self, key, val, currency, accountName):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def updatePortfolio(self, contract, position, marketPrice, marketValue, averageCost, unrealizedPNL, realizedPNL, accountName):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def updateAccountTime(self, timeStamp):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def accountDownloadEnd(self, accountName):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def contractDetails(self, reqId, contractDetails):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def bondContractDetails(self, reqId, contractDetails):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def contractDetailsEnd(self, reqId):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def execDetails(self, reqId, contract, execution):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def execDetailsEnd(self, reqId):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def updateMktDepth(self, id_, position, operation, side, price, size):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def updateMktDepthL2(self, id_, position, marketMaker, operation, side, price, size):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def updateNewsBulletin(self, msgId, msgType, newsMessage, originExch):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def managedAccounts(self, accountsList):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def receiveFA(self, pFaDataType, cxml):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def historicalData(self, reqId, date, open_, high, low, close, volume, barCount, WAP, hasGaps):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def scannerParameters(self, xml):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def scannerData(self, reqId, rank, contractDetails, distance, benchmark, projection, legsStr):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def scannerDataEnd(self, reqId):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def realtimeBar(self, reqId, time, open_, high, low, close, volume, wap, count):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def fundamentalData(self, reqId, data):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def deltaNeutralValidation(self, reqId, underComp):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def tickSnapshotEnd(self, reqId):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def marketDataType(self, reqId, marketDataType):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def commissionReport(self, commissionReport):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def position(self, account, contract, position, avgCost):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def positionEnd(self):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def verifyMessageAPI(self, apiData):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def verifyCompleted(self, isSuccessful, errorText):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def displayGroupList(self, reqId, groups):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def displayGroupUpdated(self, reqId, contractInfo):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def verifyAndAuthMessageAPI(self, apiData, xyzChallange):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def verifyAndAuthCompleted(self, isSuccessful, errorText):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def positionMulti(self, reqId, account, modelCode, contract, pos, avgCost):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def positionMultiEnd(self, reqId):	
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def accountUpdateMulti(self, reqId, account, modelCode, key, value, currency):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def accountUpdateMultiEnd(self, reqId):	
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def securityDefinitionOptionalParameter(self, reqId, exchange, underlyingConId, tradingClass, multiplier, expirations, strikes):
        print(sys._getframe().f_code.co_name)
        print(locals())
        
    #----------------------------------------------------------------------
    def securityDefinitionOptionalParameterEnd(self, reqId):
        print(sys._getframe().f_code.co_name)
        print(locals())
    
    #----------------------------------------------------------------------
    def softDollarTiers(self, reqId, tiers):
        print(sys._getframe().f_code.co_name)
        print(locals())
Example #52
0
File: test.py Project: kool11/vnp
 def execDetailsEnd(self, reqId):
     print(sys._getframe().f_code.co_name)
     print(locals())
Example #53
0
File: test.py Project: kool11/vnp
 def updateAccountTime(self, timeStamp):
     print(sys._getframe().f_code.co_name)
     print(locals())
Example #54
0
File: test.py Project: kool11/vnp
 def bondContractDetails(self, reqId, contractDetails):
     print(sys._getframe().f_code.co_name)
     print(locals())
Example #55
0
File: test.py Project: kool11/vnp
 def updateAccountValue(self, key, val, currency, accountName):
     print(sys._getframe().f_code.co_name)
     print(locals())
Example #56
0
File: test.py Project: kool11/vnp
 def accountDownloadEnd(self, accountName):
     print(sys._getframe().f_code.co_name)
     print(locals())
Example #57
0
    def test_20_make_transactions(self):
        print("\n-----", sys._getframe().f_code.co_name, "-----")
        i = 0
        for k, cl in enumerate(clients):
            if k % 10 <= 1:
                continue
            for j in range(5):
                txobj = prepare_transaction(asset_group_id,
                                            cl,
                                            i,
                                            no_cross_ref=True)
                cl['app'].insert_transaction(txobj)
                msg_processor[k].synchronize()
                i += 1
        time.sleep(3)

        global num_assigned_cross_ref
        num_cross_ref_in_clients = 0
        num_distribute_cross_ref_in_domain0 = 0
        num_drop_cross_ref = 0
        for i, cl in enumerate(clients):
            num_cross_ref_in_clients += len(cl['app'].cross_ref_list)
            if i % 2 == 1:
                continue
            cl['app'].get_stats()
            dat = msg_processor[i].synchronize()
            if KeyType.stats in dat:
                stat = dat[KeyType.stats]
                if i % 10 > 1:
                    #print("[%d] transaction.insert_count=%d" % (i, stat[b'transaction'][b'insert_count']))
                    #print("[%d] data_handler.insert_transaction=%d" % (i, stat[b'data_handler'][b'insert_transaction']))
                    assert stat[b'transaction'][
                        b'insert_count'] == 5 * client_per_core
                    assert stat[b'data_handler'][
                        b'insert_transaction'] == 5 * (core_per_domain -
                                                       1) * client_per_core
            if KeyType.stats in dat and b'domain0' in dat[KeyType.stats]:
                if b'domain0' in dat[KeyType.stats]:
                    print("[%d] distribute_cross_ref_in_domain0=%d" %
                          (i, stat[b'domain0'].get(
                              b'distribute_cross_ref_in_domain0', 0)))
                    print("[%d] GET_CROSS_REF_DISTRIBUTION=%d" %
                          (i, stat[b'domain0'].get(
                              b'GET_CROSS_REF_DISTRIBUTION', 0)))
                    print("[%d] assign_cross_ref_to_nodes=%d" %
                          (i, stat[b'domain0'].get(
                              b'assign_cross_ref_to_nodes', 0)))
                    print("[%d] drop_cross_ref_because_exceed_margin=%d" %
                          (i, stat[b'domain0'].get(
                              b'drop_cross_ref_because_exceed_margin', 0)))
                    print(
                        "[%d] cross_ref_registered=%d" %
                        (i, stat[b'domain0'].get(b'cross_ref_registered', 0)))
                    num_distribute_cross_ref_in_domain0 += stat[
                        b'domain0'].get(b'distribute_cross_ref_in_domain0', 0)
                    num_assigned_cross_ref += stat[b'domain0'].get(
                        b'assign_cross_ref_to_nodes', 0)
                    num_drop_cross_ref += stat[b'domain0'].get(
                        b'drop_cross_ref_because_exceed_margin', 0)
                    assert stat[b'domain0'].get(b'cross_ref_registered',
                                                0) == 0
        assert num_distribute_cross_ref_in_domain0 == num_assigned_cross_ref + num_drop_cross_ref
Example #58
0
File: test.py Project: kool11/vnp
 def updatePortfolio(self, contract, position, marketPrice, marketValue, averageCost, unrealizedPNL, realizedPNL, accountName):
     print(sys._getframe().f_code.co_name)
     print(locals())
Example #59
0
 def test_1_register(self):
     print("\n-----", sys._getframe().f_code.co_name, "-----")
     for cl in clients:
         ret = cl['app'].register_to_core()
         assert ret
     time.sleep(1)
Example #60
0
File: test.py Project: kool11/vnp
 def connectionClosed(self):
     print(sys._getframe().f_code.co_name)
     print(locals())