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


Python Network.login方法代码示例

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


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

示例1: Game

# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import login [as 别名]
class Game():
    def __init__(self):
        pygame.init()
        # network
        self.network = Network()
        self.network.connect()
        self.network.login(username)
        netThread = threading.Thread(target=self.update_network)
        netThread.start()
        
        self.screen = pygame.display.set_mode((1024, 768), 0, 32)
        self.load()
        
    def load(self):
        self.background = pygame.image.load(background_image_filename).convert()
        self.image = pygame.image.load(sprite_image_filename).convert_alpha()
        self.update()
        
    def update(self):
        global pos
        while True:
            for event in pygame.event.get():
                if event.type == QUIT:
                    pygame.quit()
                    exit()
                if event.type == MOUSEBUTTONDOWN:
                    pos[0] += 5
            self.draw()
                    
    def draw(self):
        self.screen.blit(self.background, (0,0))
        
        # network data draw
        if network_received is not None:
            for player in network_received:
                sp = Sprite(self, sprite_image_filename)
                sp.image = self.image
                sp.position = Vector2(player['pos'][0], player['pos'][1])
                sp.draw()
        
        pygame.display.update()
        
    def update_network(self):
        global network_received
        while True:
            data = {'action': 'update', 'id': username, 'pos': pos}
            network_received = json.loads(self.network.update(json.dumps(data)))
            time.sleep(0.05)
开发者ID:leotada,项目名称:pygame-async,代码行数:50,代码来源:main.py

示例2: Betfair

# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import login [as 别名]
class Betfair(object):
    """Betfair API client.

    :param str app_key: Optional application identifier
    :param str cert_file: Path to self-signed SSL certificate file(s); may be
        a *.pem file or a tuple of (*.crt, *.key) files


    JCV - I think we use exchange to specify Australian. Can leave balnk otherwise.
    """
    def __init__(self, app_key, cert_file, exchange):
        self.app_key = app_key
        self.cert_file = cert_file
        self.exchange = exchange
        self.network_client = Network(app_key)


    # Authentication methods
    def login(self, username, password):
        """Log in to Betfair. Sets `session_token` if successful.

        :param str username: Username
        :param str password: Password
        :raises: BetfairLoginError

        """
        self.network_client.login(username, password)

  
    @utils.requires_login
    def keep_alive(self):
        """Reset session timeout.

        :raises: BetfairAuthError

        """
        self.network_client.keep_alive()


    @utils.requires_login
    def logout(self):
        """Log out and clear `session_token`.

        :raises: BetfairAuthError

        """
        self.network_client.logout()
        self.network_client.session_token = None


    # Bet query methods
    @utils.requires_login
    def list_event_types(self, filter={}, locale=None):
        """

        :param MarketFilter filter:
        :param str locale:

        """
        result = self.network_client.invoke_sync(
            self.exchange,
            Endpoint.Betting,
            LIST_EVENT_TYPES,
            utils.get_kwargs(locals()))
        return utils.process_result(result, models.EventTypeResult)


    @utils.requires_login
    def list_competitions(self, filter={}, locale=None):
        """

        :param MarketFilter filter:
        :param str locale:

        """
        result = self.network_client.invoke_sync(
            self.exchange,
            Endpoint.Betting,
            LIST_COMPETITIONS,
            utils.get_kwargs(locals()))
        return utils.process_result(result, models.CompetitionResult)


    @utils.requires_login
    def list_time_ranges(self, filter, granularity):
        """

        :param MarketFilter filter:
        :param TimeGranularity granularity:

        """
        result = self.network_client.invoke_sync(
            self.exchange,
            Endpoint.Betting,
            LIST_TIME_RANGES,
            utils.get_kwargs(locals()))
        return utils.process_result(result, models.TimeRangeResult)


    @utils.requires_login
#.........这里部分代码省略.........
开发者ID:josephveal,项目名称:betfair.py,代码行数:103,代码来源:betfair.py

示例3: LoginDialog

# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import login [as 别名]
class LoginDialog(gtk.Window):
    default_label_width = 80
    default_entry_width = 200

    def validate_input(self):
        v = Validator()
        v.not_empty(self.domain_entry)
        v.not_empty(self.user_entry)
        v.not_empty(self.pass_entry)
        return v.errors

    def entry_row(self, label_text, entry):
        hbox = gtk.HBox(False, 8)

        label = gtk.Label(label_text)
        label_align = gtk.Alignment(1.0, 0.5, 0,0)
        label_align.add(label)

        _w, h = label_align.size_request()
        label_align.set_size_request(self.default_label_width, h)

        _w, h = entry.size_request()
        entry.set_size_request(self.default_entry_width, h)


        hbox.pack_start(label_align, False)
        hbox.pack_start(entry, True, True)
        entry.connect("activate", self.on_activate)
        entry.label_text = label_text
        return hbox

    def _error(self, msg):
        md = gtk.MessageDialog(self,
                gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR,
                gtk.BUTTONS_CLOSE, msg)
        md.run()
        md.destroy()

    def on_activate(self, btn):
        if not self.ready: return

        errors = self.validate_input()
        if errors:
            widget, msg = errors[0]
            self._error(msg)
            widget.grab_focus()
        else:
            url = Campfire.url_for_subdomain(self.sync.get_value("server.host"))
            print url
            self.network = Network(url=url)

            username = self.sync.get_value("server.username")
            password = self.sync.get_value("server.password")

            self.ready = False
            self.submit_button.set_sensitive(False)
            self.network.login(self.on_login, username, password, fail=self.on_fail_login)

    def on_login(self, me):
        self.sync.save_widget_values()
        self.controller.on_login(self.network, me["user"])

    def on_fail_login(self, err):
        self.submit_button.set_sensitive(True)
        if isinstance(err, urllib2.HTTPError):
            if err.code == 401:
                self._error("Failed to authenticate")
                self.user_entry.grab_focus()
            else:
                self._error(str(err))
        elif isinstance(err, urllib2.URLError):
            self._error("Failed to connect")
        else:
            raise err

    def __init__(self, controller):
        super(LoginDialog, self).__init__()
        self.controller = controller
        self.set_border_width(8)
        self.set_title("Connect to Campfire")

        self.domain_entry = gtk.Entry()
        self.user_entry = gtk.Entry()
        self.pass_entry = gtk.Entry()
        self.pass_entry.set_visibility(False)

        self.connect("delete_event", self.controller.on_delete)
        self.connect("destroy", self.controller.exit)

        self.ready = True

        vbox = gtk.VBox(False, 2)
        vbox.pack_start(self.entry_row("Domain", self.domain_entry), False)
        vbox.pack_start(self.entry_row("Username", self.user_entry), False)
        vbox.pack_start(self.entry_row("Password", self.pass_entry), False)

        button_row = gtk.HBox(False, 8)
        self.submit_button = gtk.Button("Login")
        self.submit_button.connect("clicked", self.on_activate)

#.........这里部分代码省略.........
开发者ID:leafo,项目名称:fireplace,代码行数:103,代码来源:login.py


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