当前位置: 首页>>代码示例>>Python>>正文


Python Emulator.run方法代码示例

本文整理汇总了Python中emulator.Emulator.run方法的典型用法代码示例。如果您正苦于以下问题:Python Emulator.run方法的具体用法?Python Emulator.run怎么用?Python Emulator.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在emulator.Emulator的用法示例。


在下文中一共展示了Emulator.run方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: launch

# 需要导入模块: from emulator import Emulator [as 别名]
# 或者: from emulator.Emulator import run [as 别名]
def launch():
    if request.headers.get('authorization', None) != settings.LAUNCH_AUTH_HEADER:
        abort(403)
    if len(emulators) >= settings.EMULATOR_LIMIT:
        abort(503)
    uuid = uuid4()
    if '/' in request.form['platform'] or '/' in request.form['version']:
        abort(400)
    emu = Emulator(
        request.form['token'],
        request.form['platform'],
        request.form['version'],
        tz_offset=(int(request.form['tz_offset']) if 'tz_offset' in request.form else None),
        oauth=request.form.get('oauth', None)
    )
    emulators[uuid] = emu
    emu.last_ping = now()
    emu.run()
    return jsonify(uuid=uuid, ws_port=emu.ws_port, vnc_display=emu.vnc_display, vnc_ws_port=emu.vnc_ws_port)
开发者ID:boredwookie,项目名称:cloudpebble-qemu-controller,代码行数:21,代码来源:controller.py

示例2: Application

# 需要导入模块: from emulator import Emulator [as 别名]
# 或者: from emulator.Emulator import run [as 别名]
class Application(object):
    OAUTH_ACCESS_TOKEN_URL = "https://accounts.google.com/o/oauth2/token"
    OAUTH_AUTHORIZE_URL = "https://accounts.google.com/o/oauth2/auth"
    OAUTH_REDIRECT_URI = "authentification/google"
    OAUTH_API_BASE_URL = "https://www.googleapis.com/"
    OAUTH_SCOPES = [
        'https://www.googleapis.com/auth/glass.location',
        'https://www.googleapis.com/auth/glass.timeline',
        'https://www.googleapis.com/auth/userinfo.profile',
        'https://www.googleapis.com/auth/userinfo.email'
    ]

    def __init__(self, 
                name="",
                client_id=None,
                client_secret=None,
                emulator=False,
                debug=True,
                template_folder='templates'):
        self.name = name
        self.emulator = emulator
        self.debug = debug
        self.web = flask.Flask(self.name,
            static_folder=os.path.join(os.path.dirname(os.path.abspath(__file__)), 'emulator'),
            static_url_path='/emulator')
        self.template_folder = template_folder
        self.logger = self.web.logger
        self.emulator_service = Emulator(app=self)
        self.subscriptions = Subscriptions(app=self)
        self.oauth = rauth.OAuth2Service(name=self.name,
                                  client_id=client_id,
                                  client_secret=client_secret,
                                  access_token_url=self.OAUTH_ACCESS_TOKEN_URL,
                                  authorize_url=self.OAUTH_AUTHORIZE_URL,
                                  base_url=self.OAUTH_API_BASE_URL)

    @property
    def oauth_redirect_uri(self):
        return "%s/glass/oauth/callback" % (self.host)

    def _oauth_authorize(self):
        """
        (view) Display the authorization window for Google Glass
        """
        params = {
            'approval_prompt': 'force',
            'scope': " ".join(self.OAUTH_SCOPES),
            'state': '/profile',
            'redirect_uri': self.oauth_redirect_uri,
            'response_type': 'code'
        }
        url = self.oauth.get_authorize_url(**params)
        return flask.redirect(url)

    def _oauth_callback(self):
        """
        (view) Callback for the oauth
        """
        token = self.oauth.get_access_token(data={
            'code': flask.request.args.get('code', ''),
            'redirect_uri': self.oauth_redirect_uri,
            'grant_type': 'authorization_code'
        }, decoder=json.loads)
        user = User(token=token, app=self)

        # Add subscriptions
        self.subscriptions.init_user(user)

        # Call endpoint for user login
        self.subscriptions.call_endpoint("login", user)

        return token

    def run(self, host="http://localhost", port=8080, debug=None):
        """
        Start the application server
        """
        if self.emulator:
            self.emulator_service.run()

        self.port = port
        self.host = host
        if port != 80:
            self.host = "%s:%i" % (self.host, self.port)

        # OAUTH
        self.web.add_url_rule('/glass/oauth/authorize', 'oauth_authorize', self._oauth_authorize)
        self.web.add_url_rule('/glass/oauth/callback', 'oauth_callback', self._oauth_callback)

        self.web.debug = debug or self.debug

        # Run webserver
        self.web.run(port=self.port)
开发者ID:Valay,项目名称:glass.py,代码行数:95,代码来源:app.py


注:本文中的emulator.Emulator.run方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。