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


Python Session.close方法代码示例

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


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

示例1: post

# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import close [as 别名]
  def post(self, id_):
    """ Publish to BBS
    """
    errors = {}

    username = self.get_argument("username", "名無し")
    if username == "":
      username = "名無し"
    mail = self.get_argument("mail")

    text = self.get_argument("text")
    if text == "":
      errors["text"] = True

    if not errors:
      session = Session()
      res = Response(text, username)
      res.bbs_id = id_
      session.add(res)
      session.commit()
      session.close()

    responses = self.get_responses(id_)

    self.render("BBS/index.html",
        responses=responses,
        errors=errors
    )
开发者ID:kouki-dan,项目名称:ShootingStarChecker,代码行数:30,代码来源:BBSHandler.py

示例2: stopProcess

# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import close [as 别名]
def stopProcess(address, port, dbPassword):
    s = Session(address, port=port, service="Monitor")
    s.authorize("Cloud", dbPassword)
    s.doConnect()

    s.send("<Request Action=\"shutdown\"/>")

    s.close()
开发者ID:DukeNuoDB,项目名称:nuodb-python,代码行数:10,代码来源:util.py

示例3: doDatabaseAction

# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import close [as 别名]
def doDatabaseAction(broker, user, password, db_name, action, child=None):
    s = Session(broker, service="ChorusManagement")
    s.authorize(user, password)

    if child is not None:
        child = [ child ]
    s.doConnect(attributes={"Database" : db_name, "Action" : action}, children=child)
    response = s.recv()
    checkForError(response)

    s.close()

    return response
开发者ID:DukeNuoDB,项目名称:nuodb-python,代码行数:15,代码来源:util.py

示例4: upgrade

# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import close [as 别名]
    def upgrade(self):
        cnx = connector.connect(
            host=self.config.host,
            user=self.config.username,
            password=self.config.password)

        db_cursor = cnx.cursor()

        db_cursor.execute("SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '{0}'".format(self.config.database))
        db_exists = db_cursor.fetchone()

        if not db_exists:
            try:
                db_cursor.execute("CREATE DATABASE {0}".format(self.config.database))
            except Exception as ex:
                message = 'Could not create database: ' + ex.msg
                logging.error(message)
                raise Exception(message)

        cnx.database = self.config.database

        session = Session(cnx)

        # do it.
        session.execute("""
            CREATE TABLE IF NOT EXISTS upgrade_history (
              id INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL,
              upgrade_date DATETIME,
              version INTEGER
            )""")

        session.execute("SELECT IFNULL(MAX(version),0) FROM upgrade_history")
        db_version = session.fetch_results()[0][0]  # first row first col

        script = self.__create_upgrade_script()

        max_version = 0
        for query in script:
            if query['version'] > db_version:
                if query['version'] > max_version:
                    max_version = query['version']
                session.execute(query['sql'])

        if max_version > db_version:
            session.execute("""INSERT INTO upgrade_history (upgrade_date, version)
                          VALUES('{date}', '{version}');""".format(date=datetime.now().isoformat(), version=max_version))
            logginghelper.log_debug('Upgraded database to version ' + str(max_version))

        session.commit()
        session.close()
开发者ID:Shaggy84675,项目名称:ottdstats,代码行数:52,代码来源:mysql_database.py

示例5: get_responses

# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import close [as 别名]
  def get_responses(self, id_=1, less_than=None, more_than=None):
    session = Session()
    bbs = session.query(BBS).filter(BBS.id == id_).one()

    responses = session.query(Response).filter(Response.bbs_id == id_)
    if less_than:
      responses = responses.filter(Response.id < less_than)
    if more_than:
      responses = responses.filter(Response.id > more_than)
    responses = responses.order_by(Response.id.desc()).limit(30).all()

    responses = [res.toDict() for res in responses]

    session.close()
    return responses
开发者ID:kouki-dan,项目名称:ShootingStarChecker,代码行数:17,代码来源:BBSHandler.py

示例6: end_session

# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import close [as 别名]
def end_session(sid):
    """End a robot control session.  After session is ended, another party
    can then acquire a new session."""
    try:
        # TODO can we move this port stuff to hangouts.py?
        #  The issue was that Session.close deletes the session directory,
        #  which clears out the port storage file.  But we don't want to
        #  stop the hangout before we validate sid & close session.
        session = Session(sid)
        port = session.get('hangout_control_port')
        session.close()
        control.stop_controlserver()
        stop_hangout(port)
        heartbeats.send_session_ended()
        return {'message': "Session ended successfully."}
    except SessionConflict, e:
        abort(409, "Unable to end control session: %s" % str(e))
开发者ID:davemt,项目名称:vistorvebot,代码行数:19,代码来源:server.py

示例7: getCloudEntry

# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import close [as 别名]
def getCloudEntry(broker, db_name, attrs=None):
    if not attrs:
        attrs = dict()
    attrs["Database"] = db_name

    s = Session(broker, service="SQL2")

    s.doConnect(attributes=attrs)
    connectDetail = s.recv()
    s.close()

    checkForError(connectDetail)

    root = ElementTree.fromstring(connectDetail)
    if root.tag != "Cloud":
        raise SessionException("Unexpecetd response type: " + root.tag)

    return (root.get("Address"), int(root.get("Port")))
开发者ID:DukeNuoDB,项目名称:nuodb-python,代码行数:20,代码来源:util.py

示例8: queryEngine

# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import close [as 别名]
def queryEngine(address, port, target, dbPassword, msgBody=None):
    s = Session(address, port=port, service="Query")
    s.authorize("Cloud", dbPassword)
    s.doConnect()

    msg = "<Query Target=\"%s\"/>" % target
    if msgBody is not None:
        xml = ElementTree.fromstring(msg)
        xml.append(msgBody)
        msg = ElementTree.tostring(xml)

    s.send(msg)
    response = s.recv()

    checkForError(response)

    s.close()

    return response
开发者ID:DukeNuoDB,项目名称:nuodb-python,代码行数:21,代码来源:util.py

示例9:

# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import close [as 别名]
      <node lat="46.5059522910652" lon="6.674499182942514" changeset="%(changeset)s" />
</osm>"""%{'changeset': changeset_id})
    n4 = api.put("/api/0.6/node/create", """<?xml version="1.0" encoding="UTF-8"?>
<osm>
      <node lat="46.50601259859745" lon="6.674312944430097" changeset="%(changeset)s" />
</osm>"""%{'changeset': changeset_id})

    print api.put("/api/0.6/way/create", """<?xml version="1.0" encoding="UTF-8"?>
<osm>
      <way changeset="%(changeset)s">
        <nd ref="%(n1)s" />
        <nd ref="%(n2)s" />
        <nd ref="%(n3)s" />
        <nd ref="%(n4)s" />
        <nd ref="%(n1)s" />
        <tag k="test" v="test" />
      </way>
</osm>"""%{'changeset': changeset_id, 'n1': n1, 'n2': n2, 'n3': n3, 'n4': n4})

    # close changeset
    api.put("/api/0.6/changeset/%s/close"%changeset_id)

    print
    print "Writing changes to " + OSMOAuth.API_URL + "/browse/changeset/" + changeset_id

else:
    print
    print "No valid query."

session.close()
开发者ID:sbrunner,项目名称:map,代码行数:32,代码来源:osm.py

示例10: MainFrame

# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import close [as 别名]
class MainFrame(wx.Frame):
    """Main Frame  of the app."""
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)

        self.session = Session()

        self.SetBackgroundColour(BGD_COLOR)

        # List of timers so we can stop them when we quit.
        # Avoids PyDeadObjectError.
        self.timers = set()
        Publisher().subscribe(self.new_timer, "new_timer")

        # Build the menu bar
        menu_bar = wx.MenuBar()

        file_menu = wx.Menu()
        exit_item = file_menu.Append(wx.ID_EXIT, text="E&xit")
        self.Bind(wx.EVT_MENU, self.on_quit, exit_item)

        help_menu = wx.Menu()
        about_item = help_menu.Append(wx.ID_ABOUT, text="&About",
                                      help="Information about this program")
        self.Bind(wx.EVT_MENU, self.on_about, about_item)

        menu_bar.Append(file_menu, "&File")
        menu_bar.Append(help_menu, "&Help")
        self.SetMenuBar(menu_bar)

        self.CreateStatusBar(style=0)
        Publisher().subscribe(self.change_statusbar, "change_statusbar")

        # Add panels
        connections_panel = ConnectionsPanel(self, self.session, BGD_COLOR)
        clipboard_panel = ClipboardPanel(self, self.session, BGD_COLOR)
        status_panel = StatusPanel(self, BGD_COLOR)

        new_btn = wx.Button(self, label="New Connection")
        new_btn.Bind(wx.EVT_BUTTON, self.on_new)

        auto_sync_cb = wx.CheckBox(self, id=wx.ID_ANY,
                                       label="Automatically Sync")
        self.Bind(wx.EVT_CHECKBOX, self.on_toggle_auto, auto_sync_cb)
        auto_sync_cb.Bind(wx.EVT_ENTER_WINDOW, self.on_enter_auto)
        auto_sync_cb.Bind(wx.EVT_LEAVE_WINDOW, self.on_leave_auto)

        main_sizer = wx.BoxSizer(wx.VERTICAL)
        top_row_sizer = wx.BoxSizer(wx.HORIZONTAL)
        board_sizer = wx.BoxSizer(wx.VERTICAL)

        btn_flags = wx.SizerFlags().Proportion(0).Border(wx.ALL, 5).Bottom()
        status_flags = wx.SizerFlags().Proportion(1).Expand().Border(wx.ALL, 5).Top()
        flags = wx.SizerFlags().Proportion(0).Expand().Border(wx.ALL, 5)
        board_flags = wx.SizerFlags().Proportion(0).Border(wx.ALL, 5).Right()
        top_flags = wx.SizerFlags().Proportion(0).Expand().Border(wx.ALL, 5)
        conn_flags = wx.SizerFlags().Proportion(1).Expand().Border(wx.ALL, 5)
        
        board_sizer.AddF(auto_sync_cb, flags)
        board_sizer.AddF(clipboard_panel, flags)

        top_row_sizer.AddF(new_btn, btn_flags)
        top_row_sizer.AddF(status_panel, status_flags)
        top_row_sizer.AddF(board_sizer, board_flags)

        main_sizer.AddF(top_row_sizer, top_flags)
        main_sizer.AddF(connections_panel, conn_flags)

        self.SetSizer(main_sizer)

    def new_timer(self, msg):
        self.timers.add(msg.data)

    def change_statusbar(self, msg):
        self.SetStatusText(msg.data)

    def on_new(self, event):
        Publisher().sendMessage(("new_connection"))

    def on_toggle_auto(self, event):
        Publisher().sendMessage(("auto_toggle"), event.IsChecked())

    def on_enter_auto(self, event):
        Publisher().sendMessage(("change_statusbar"),
            "Automatically copy/paste new items to/from your clipboard")
        event.Skip()

    def on_leave_auto(self, event):
        Publisher().sendMessage(("change_statusbar"), "")
        event.Skip()

    def on_about(self, event):
        aboutbox = AboutDialog(self)
        aboutbox.ShowModal()
        aboutbox.Destroy()

    def on_quit(self, event):
        for timer in self.timers():
            timer.Stop()
        self.session.close()
#.........这里部分代码省略.........
开发者ID:syncboard,项目名称:syncboard,代码行数:103,代码来源:gui.py


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