Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, config):
ApplicationSession.__init__(self)
service.AsyncMultiService.__init__(self)
self.config = config
self.leaving = False
self.setServiceParent(config.extra['parent'])
self.height = height
self.b64 = b64
class Frame(object):
def __init__(self):
self.time = None
self.score = None
self.reset_reason = None
self.game_state = None
self.subimages = None
self.coordinates = None
self.half_passed = None
class Component(ApplicationSession):
"""
AI Base + Rule Based Algorithm
"""
def __init__(self, config):
ApplicationSession.__init__(self, config)
def printConsole(self, message):
print(message)
sys.__stdout__.flush()
def onConnect(self):
self.join(self.config.realm)
@inlineCallbacks
def onJoin(self, details):
import signal
def alarm_handle(signal_number, current_stack_frame):
crossref_push.output_heartbeat
logging.info('pushed output heartbeat')
signal.alarm(alarm_interval)
signal.signal(signal.SIGALRM, alarm_handle)
signal.siginterrupt(signal.SIGALRM, False)
signal.alarm(alarm_interval)
redis_con = Redis(REDIS_LOCATION)
queue = Queue('changes', connection = redis_con, default_timeout = 10) #seconds
class WikiCiteServer(ApplicationSession):
@inlineCallbacks
def onJoin(self, details):
logging.info("session ready")
counter = 0
while True:
for change in queue.jobs:
self.publish(u'com.cocytus.onchange', change)
yield sleep(1)
#from autobahn.twisted.wamp import ApplicationRunner
#runner = ApplicationRunner(url = "ws://0.0.0.0:12345/citeserver", realm = "realm1")
#runner.run(WikiCiteServer) # this doesn't return
while True:
job = queue.dequeue()
if job is None:
# add the webhook session to the router
#
self._router_session_factory.add(webhook_session, authrole=path_config.get('role', 'anonymous'))
# now create the webhook Twisted Web resource
#
return WebhookResource(path_config.get('options', {}), webhook_session)
# Caller resource (part of REST-bridge)
#
elif path_config['type'] == 'caller':
# create a vanilla session: the caller will use this to inject calls
#
caller_session_config = ComponentConfig(realm=path_config['realm'], extra=None)
caller_session = ApplicationSession(caller_session_config)
# add the calling session to the router
#
self._router_session_factory.add(caller_session, authrole=path_config.get('role', 'anonymous'))
# now create the caller Twisted Web resource
#
return CallerResource(path_config.get('options', {}), caller_session)
# File Upload resource
#
elif path_config['type'] == 'upload':
upload_directory = os.path.abspath(os.path.join(self.config.extra.cbdir, path_config['directory']))
upload_directory = upload_directory.encode('ascii', 'ignore') # http://stackoverflow.com/a/20433918/884770
if not os.path.isdir(upload_directory):
# THE SOFTWARE.
#
###############################################################################
from __future__ import print_function
from os import environ
from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks
from twisted.python.failure import Failure
from autobahn import wamp
from autobahn.twisted.wamp import ApplicationSession, ApplicationRunner
class Component(ApplicationSession):
"""
An application component that subscribes and receives events,
and stop after having received 5 events.
"""
@inlineCallbacks
def onJoin(self, details):
print("session attached")
# subscribe all methods on this object decorated with "@wamp.subscribe"
# as PubSub event handlers
results = yield self.subscribe(self)
# check we didn't have any errors
for sub in results:
# add the publisher session to the router
#
self._router_session_factory.add(publisher_session, authrole=path_config.get('role', 'anonymous'))
# now create the publisher Twisted Web resource
#
return PublisherResource(path_config.get('options', {}), publisher_session)
# Webhook resource (part of REST-bridge)
#
elif path_config['type'] == 'webhook':
# create a vanilla session: the webhook will use this to inject events
#
webhook_session_config = ComponentConfig(realm=path_config['realm'], extra=None)
webhook_session = ApplicationSession(webhook_session_config)
# add the webhook session to the router
#
self._router_session_factory.add(webhook_session, authrole=path_config.get('role', 'anonymous'))
# now create the webhook Twisted Web resource
#
return WebhookResource(path_config.get('options', {}), webhook_session)
# Caller resource (part of REST-bridge)
#
elif path_config['type'] == 'caller':
# create a vanilla session: the caller will use this to inject calls
#
caller_session_config = ComponentConfig(realm=path_config['realm'], extra=None)
#!/usr/bin/python
# -*- coding: utf-8 -*-
from multiprocessing import Process, Queue
from multiprocessing.dummy import Process as Thread
from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks
from autobahn.twisted.wamp import ApplicationSession, ApplicationRunner
import poloniex
queue = Queue()
class TickPitcher(ApplicationSession):
""" WAMP application """
@inlineCallbacks
def onJoin(self, details):
yield self.subscribe(self.onTick, 'ticker')
print('Subscribed to Ticker')
def onTick(self, *tick):
queue.put(tick)
def onDisconnect(self):
if reactor.running:
reactor.stop()
class Ticker(object):
def build_bridge_class(magics_instance):
class WampConnectionComponent(ApplicationSession):
_wamp_prefix = ""
_ipython = get_ipython()
_msg_id_lut = deque(maxlen=10)
_machine_callbacks = []
_iopub_sub = None
_machine_sub = None
@inlineCallbacks
def reset_prefix(self):
if self._iopub_sub:
yield self._iopub_sub.unsubscribe()
self._iopub_sub = None
if self._machine_sub:
yield self._machine_sub.unsubscribe()
self._machine_sub = None
returnValue(None)
from twisted.internet.defer import inlineCallbacks
from autobahn import wamp
from autobahn.wamp.exception import ApplicationError
from autobahn.twisted.wamp import ApplicationSession, ApplicationRunner
@wamp.error(u"com.myapp.error1")
class AppError1(Exception):
"""
An application specific exception that is decorated with a WAMP URI,
and hence can be automapped by Autobahn.
"""
class Component(ApplicationSession):
"""
Example WAMP application frontend that catches exceptions.
"""
@inlineCallbacks
def onJoin(self, details):
print("session attached")
# catching standard exceptions
##
for x in [2, 0, -2]:
try:
res = yield self.call(u'com.myapp.sqrt', x)
except Exception as e:
print("Error: {} {}".format(e, e.args))
else:
from mdstudio.api.api_result import APIResult
from mdstudio.api.context import UserContext, GroupRoleContext, GroupContext
from mdstudio.api.converter import convert_obj_to_json
from mdstudio.api.exception import CallException
from mdstudio.api.request_hash import request_hash
from mdstudio.api.schema import validate_json_schema
from mdstudio.collection import merge_dicts, dict_property
from mdstudio.deferred.chainable import chainable, Chainable
from mdstudio.deferred.return_value import return_value
from mdstudio.logging.impl.session_observer import SessionLogObserver
from mdstudio.logging.log_type import LogType
from mdstudio.logging.logger import Logger
from mdstudio.util.exception import MDStudioException
class CommonSession(ApplicationSession):
class Config(object):
class Static(dict):
vendor = dict_property('vendor')
component = dict_property('component')
class Session(dict):
username = dict_property('username')
password = dict_property('password')
realm = dict_property('realm')
role = dict_property('role')
session_id = dict_property('session_id')
def __init__(self):
self.static = self.Static()
self.session = self.Session()
self.settings = {}