partition stringclasses 3
values | func_name stringlengths 1 134 | docstring stringlengths 1 46.9k | path stringlengths 4 223 | original_string stringlengths 75 104k | code stringlengths 75 104k | docstring_tokens listlengths 1 1.97k | repo stringlengths 7 55 | language stringclasses 1
value | url stringlengths 87 315 | code_tokens listlengths 19 28.4k | sha stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
train | BaseManager.enter_room | Add a client to a room. | socketio/base_manager.py | def enter_room(self, sid, namespace, room):
"""Add a client to a room."""
if namespace not in self.rooms:
self.rooms[namespace] = {}
if room not in self.rooms[namespace]:
self.rooms[namespace][room] = {}
self.rooms[namespace][room][sid] = True | def enter_room(self, sid, namespace, room):
"""Add a client to a room."""
if namespace not in self.rooms:
self.rooms[namespace] = {}
if room not in self.rooms[namespace]:
self.rooms[namespace][room] = {}
self.rooms[namespace][room][sid] = True | [
"Add",
"a",
"client",
"to",
"a",
"room",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/base_manager.py#L89-L95 | [
"def",
"enter_room",
"(",
"self",
",",
"sid",
",",
"namespace",
",",
"room",
")",
":",
"if",
"namespace",
"not",
"in",
"self",
".",
"rooms",
":",
"self",
".",
"rooms",
"[",
"namespace",
"]",
"=",
"{",
"}",
"if",
"room",
"not",
"in",
"self",
".",
... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | BaseManager.leave_room | Remove a client from a room. | socketio/base_manager.py | def leave_room(self, sid, namespace, room):
"""Remove a client from a room."""
try:
del self.rooms[namespace][room][sid]
if len(self.rooms[namespace][room]) == 0:
del self.rooms[namespace][room]
if len(self.rooms[namespace]) == 0:
... | def leave_room(self, sid, namespace, room):
"""Remove a client from a room."""
try:
del self.rooms[namespace][room][sid]
if len(self.rooms[namespace][room]) == 0:
del self.rooms[namespace][room]
if len(self.rooms[namespace]) == 0:
... | [
"Remove",
"a",
"client",
"from",
"a",
"room",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/base_manager.py#L97-L106 | [
"def",
"leave_room",
"(",
"self",
",",
"sid",
",",
"namespace",
",",
"room",
")",
":",
"try",
":",
"del",
"self",
".",
"rooms",
"[",
"namespace",
"]",
"[",
"room",
"]",
"[",
"sid",
"]",
"if",
"len",
"(",
"self",
".",
"rooms",
"[",
"namespace",
"]... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | BaseManager.close_room | Remove all participants from a room. | socketio/base_manager.py | def close_room(self, room, namespace):
"""Remove all participants from a room."""
try:
for sid in self.get_participants(namespace, room):
self.leave_room(sid, namespace, room)
except KeyError:
pass | def close_room(self, room, namespace):
"""Remove all participants from a room."""
try:
for sid in self.get_participants(namespace, room):
self.leave_room(sid, namespace, room)
except KeyError:
pass | [
"Remove",
"all",
"participants",
"from",
"a",
"room",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/base_manager.py#L108-L114 | [
"def",
"close_room",
"(",
"self",
",",
"room",
",",
"namespace",
")",
":",
"try",
":",
"for",
"sid",
"in",
"self",
".",
"get_participants",
"(",
"namespace",
",",
"room",
")",
":",
"self",
".",
"leave_room",
"(",
"sid",
",",
"namespace",
",",
"room",
... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | BaseManager.get_rooms | Return the rooms a client is in. | socketio/base_manager.py | def get_rooms(self, sid, namespace):
"""Return the rooms a client is in."""
r = []
try:
for room_name, room in six.iteritems(self.rooms[namespace]):
if room_name is not None and sid in room and room[sid]:
r.append(room_name)
except KeyError... | def get_rooms(self, sid, namespace):
"""Return the rooms a client is in."""
r = []
try:
for room_name, room in six.iteritems(self.rooms[namespace]):
if room_name is not None and sid in room and room[sid]:
r.append(room_name)
except KeyError... | [
"Return",
"the",
"rooms",
"a",
"client",
"is",
"in",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/base_manager.py#L116-L125 | [
"def",
"get_rooms",
"(",
"self",
",",
"sid",
",",
"namespace",
")",
":",
"r",
"=",
"[",
"]",
"try",
":",
"for",
"room_name",
",",
"room",
"in",
"six",
".",
"iteritems",
"(",
"self",
".",
"rooms",
"[",
"namespace",
"]",
")",
":",
"if",
"room_name",
... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | BaseManager.trigger_callback | Invoke an application callback. | socketio/base_manager.py | def trigger_callback(self, sid, namespace, id, data):
"""Invoke an application callback."""
callback = None
try:
callback = self.callbacks[sid][namespace][id]
except KeyError:
# if we get an unknown callback we just ignore it
self._get_logger().warning... | def trigger_callback(self, sid, namespace, id, data):
"""Invoke an application callback."""
callback = None
try:
callback = self.callbacks[sid][namespace][id]
except KeyError:
# if we get an unknown callback we just ignore it
self._get_logger().warning... | [
"Invoke",
"an",
"application",
"callback",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/base_manager.py#L141-L152 | [
"def",
"trigger_callback",
"(",
"self",
",",
"sid",
",",
"namespace",
",",
"id",
",",
"data",
")",
":",
"callback",
"=",
"None",
"try",
":",
"callback",
"=",
"self",
".",
"callbacks",
"[",
"sid",
"]",
"[",
"namespace",
"]",
"[",
"id",
"]",
"except",
... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | BaseManager._generate_ack_id | Generate a unique identifier for an ACK packet. | socketio/base_manager.py | def _generate_ack_id(self, sid, namespace, callback):
"""Generate a unique identifier for an ACK packet."""
namespace = namespace or '/'
if sid not in self.callbacks:
self.callbacks[sid] = {}
if namespace not in self.callbacks[sid]:
self.callbacks[sid][namespace] ... | def _generate_ack_id(self, sid, namespace, callback):
"""Generate a unique identifier for an ACK packet."""
namespace = namespace or '/'
if sid not in self.callbacks:
self.callbacks[sid] = {}
if namespace not in self.callbacks[sid]:
self.callbacks[sid][namespace] ... | [
"Generate",
"a",
"unique",
"identifier",
"for",
"an",
"ACK",
"packet",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/base_manager.py#L154-L163 | [
"def",
"_generate_ack_id",
"(",
"self",
",",
"sid",
",",
"namespace",
",",
"callback",
")",
":",
"namespace",
"=",
"namespace",
"or",
"'/'",
"if",
"sid",
"not",
"in",
"self",
".",
"callbacks",
":",
"self",
".",
"callbacks",
"[",
"sid",
"]",
"=",
"{",
... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | BaseManager._get_logger | Get the appropriate logger
Prevents uninitialized servers in write-only mode from failing. | socketio/base_manager.py | def _get_logger(self):
"""Get the appropriate logger
Prevents uninitialized servers in write-only mode from failing.
"""
if self.logger:
return self.logger
elif self.server:
return self.server.logger
else:
return default_logger | def _get_logger(self):
"""Get the appropriate logger
Prevents uninitialized servers in write-only mode from failing.
"""
if self.logger:
return self.logger
elif self.server:
return self.server.logger
else:
return default_logger | [
"Get",
"the",
"appropriate",
"logger"
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/base_manager.py#L165-L176 | [
"def",
"_get_logger",
"(",
"self",
")",
":",
"if",
"self",
".",
"logger",
":",
"return",
"self",
".",
"logger",
"elif",
"self",
".",
"server",
":",
"return",
"self",
".",
"server",
".",
"logger",
"else",
":",
"return",
"default_logger"
] | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | Server.on | Register an event handler.
:param event: The event name. It can be any string. The event names
``'connect'``, ``'message'`` and ``'disconnect'`` are
reserved and should not be used.
:param handler: The function that should be invoked to handle the
... | socketio/server.py | def on(self, event, handler=None, namespace=None):
"""Register an event handler.
:param event: The event name. It can be any string. The event names
``'connect'``, ``'message'`` and ``'disconnect'`` are
reserved and should not be used.
:param handler:... | def on(self, event, handler=None, namespace=None):
"""Register an event handler.
:param event: The event name. It can be any string. The event names
``'connect'``, ``'message'`` and ``'disconnect'`` are
reserved and should not be used.
:param handler:... | [
"Register",
"an",
"event",
"handler",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/server.py#L140-L187 | [
"def",
"on",
"(",
"self",
",",
"event",
",",
"handler",
"=",
"None",
",",
"namespace",
"=",
"None",
")",
":",
"namespace",
"=",
"namespace",
"or",
"'/'",
"def",
"set_handler",
"(",
"handler",
")",
":",
"if",
"namespace",
"not",
"in",
"self",
".",
"ha... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | Server.register_namespace | Register a namespace handler object.
:param namespace_handler: An instance of a :class:`Namespace`
subclass that handles all the event traffic
for a namespace. | socketio/server.py | def register_namespace(self, namespace_handler):
"""Register a namespace handler object.
:param namespace_handler: An instance of a :class:`Namespace`
subclass that handles all the event traffic
for a namespace.
"""
if ... | def register_namespace(self, namespace_handler):
"""Register a namespace handler object.
:param namespace_handler: An instance of a :class:`Namespace`
subclass that handles all the event traffic
for a namespace.
"""
if ... | [
"Register",
"a",
"namespace",
"handler",
"object",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/server.py#L189-L202 | [
"def",
"register_namespace",
"(",
"self",
",",
"namespace_handler",
")",
":",
"if",
"not",
"isinstance",
"(",
"namespace_handler",
",",
"namespace",
".",
"Namespace",
")",
":",
"raise",
"ValueError",
"(",
"'Not a namespace instance'",
")",
"if",
"self",
".",
"is... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | Server.enter_room | Enter a room.
This function adds the client to a room. The :func:`emit` and
:func:`send` functions can optionally broadcast events to all the
clients in a room.
:param sid: Session ID of the client.
:param room: Room name. If the room does not exist it is created.
:para... | socketio/server.py | def enter_room(self, sid, room, namespace=None):
"""Enter a room.
This function adds the client to a room. The :func:`emit` and
:func:`send` functions can optionally broadcast events to all the
clients in a room.
:param sid: Session ID of the client.
:param room: Room n... | def enter_room(self, sid, room, namespace=None):
"""Enter a room.
This function adds the client to a room. The :func:`emit` and
:func:`send` functions can optionally broadcast events to all the
clients in a room.
:param sid: Session ID of the client.
:param room: Room n... | [
"Enter",
"a",
"room",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/server.py#L324-L338 | [
"def",
"enter_room",
"(",
"self",
",",
"sid",
",",
"room",
",",
"namespace",
"=",
"None",
")",
":",
"namespace",
"=",
"namespace",
"or",
"'/'",
"self",
".",
"logger",
".",
"info",
"(",
"'%s is entering room %s [%s]'",
",",
"sid",
",",
"room",
",",
"names... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | Server.leave_room | Leave a room.
This function removes the client from a room.
:param sid: Session ID of the client.
:param room: Room name.
:param namespace: The Socket.IO namespace for the event. If this
argument is omitted the default namespace is used. | socketio/server.py | def leave_room(self, sid, room, namespace=None):
"""Leave a room.
This function removes the client from a room.
:param sid: Session ID of the client.
:param room: Room name.
:param namespace: The Socket.IO namespace for the event. If this
argument is o... | def leave_room(self, sid, room, namespace=None):
"""Leave a room.
This function removes the client from a room.
:param sid: Session ID of the client.
:param room: Room name.
:param namespace: The Socket.IO namespace for the event. If this
argument is o... | [
"Leave",
"a",
"room",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/server.py#L340-L352 | [
"def",
"leave_room",
"(",
"self",
",",
"sid",
",",
"room",
",",
"namespace",
"=",
"None",
")",
":",
"namespace",
"=",
"namespace",
"or",
"'/'",
"self",
".",
"logger",
".",
"info",
"(",
"'%s is leaving room %s [%s]'",
",",
"sid",
",",
"room",
",",
"namesp... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | Server.rooms | Return the rooms a client is in.
:param sid: Session ID of the client.
:param namespace: The Socket.IO namespace for the event. If this
argument is omitted the default namespace is used. | socketio/server.py | def rooms(self, sid, namespace=None):
"""Return the rooms a client is in.
:param sid: Session ID of the client.
:param namespace: The Socket.IO namespace for the event. If this
argument is omitted the default namespace is used.
"""
namespace = namespace... | def rooms(self, sid, namespace=None):
"""Return the rooms a client is in.
:param sid: Session ID of the client.
:param namespace: The Socket.IO namespace for the event. If this
argument is omitted the default namespace is used.
"""
namespace = namespace... | [
"Return",
"the",
"rooms",
"a",
"client",
"is",
"in",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/server.py#L367-L375 | [
"def",
"rooms",
"(",
"self",
",",
"sid",
",",
"namespace",
"=",
"None",
")",
":",
"namespace",
"=",
"namespace",
"or",
"'/'",
"return",
"self",
".",
"manager",
".",
"get_rooms",
"(",
"sid",
",",
"namespace",
")"
] | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | Server.get_session | Return the user session for a client.
:param sid: The session id of the client.
:param namespace: The Socket.IO namespace. If this argument is omitted
the default namespace is used.
The return value is a dictionary. Modifications made to this
dictionary are no... | socketio/server.py | def get_session(self, sid, namespace=None):
"""Return the user session for a client.
:param sid: The session id of the client.
:param namespace: The Socket.IO namespace. If this argument is omitted
the default namespace is used.
The return value is a dictionar... | def get_session(self, sid, namespace=None):
"""Return the user session for a client.
:param sid: The session id of the client.
:param namespace: The Socket.IO namespace. If this argument is omitted
the default namespace is used.
The return value is a dictionar... | [
"Return",
"the",
"user",
"session",
"for",
"a",
"client",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/server.py#L377-L391 | [
"def",
"get_session",
"(",
"self",
",",
"sid",
",",
"namespace",
"=",
"None",
")",
":",
"namespace",
"=",
"namespace",
"or",
"'/'",
"eio_session",
"=",
"self",
".",
"eio",
".",
"get_session",
"(",
"sid",
")",
"return",
"eio_session",
".",
"setdefault",
"... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | Server.save_session | Store the user session for a client.
:param sid: The session id of the client.
:param session: The session dictionary.
:param namespace: The Socket.IO namespace. If this argument is omitted
the default namespace is used. | socketio/server.py | def save_session(self, sid, session, namespace=None):
"""Store the user session for a client.
:param sid: The session id of the client.
:param session: The session dictionary.
:param namespace: The Socket.IO namespace. If this argument is omitted
the default na... | def save_session(self, sid, session, namespace=None):
"""Store the user session for a client.
:param sid: The session id of the client.
:param session: The session dictionary.
:param namespace: The Socket.IO namespace. If this argument is omitted
the default na... | [
"Store",
"the",
"user",
"session",
"for",
"a",
"client",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/server.py#L393-L403 | [
"def",
"save_session",
"(",
"self",
",",
"sid",
",",
"session",
",",
"namespace",
"=",
"None",
")",
":",
"namespace",
"=",
"namespace",
"or",
"'/'",
"eio_session",
"=",
"self",
".",
"eio",
".",
"get_session",
"(",
"sid",
")",
"eio_session",
"[",
"namespa... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | Server.session | Return the user session for a client with context manager syntax.
:param sid: The session id of the client.
This is a context manager that returns the user session dictionary for
the client. Any changes that are made to this dictionary inside the
context manager block are saved back to... | socketio/server.py | def session(self, sid, namespace=None):
"""Return the user session for a client with context manager syntax.
:param sid: The session id of the client.
This is a context manager that returns the user session dictionary for
the client. Any changes that are made to this dictionary inside ... | def session(self, sid, namespace=None):
"""Return the user session for a client with context manager syntax.
:param sid: The session id of the client.
This is a context manager that returns the user session dictionary for
the client. Any changes that are made to this dictionary inside ... | [
"Return",
"the",
"user",
"session",
"for",
"a",
"client",
"with",
"context",
"manager",
"syntax",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/server.py#L405-L443 | [
"def",
"session",
"(",
"self",
",",
"sid",
",",
"namespace",
"=",
"None",
")",
":",
"class",
"_session_context_manager",
"(",
"object",
")",
":",
"def",
"__init__",
"(",
"self",
",",
"server",
",",
"sid",
",",
"namespace",
")",
":",
"self",
".",
"serve... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | Server.start_background_task | Start a background task using the appropriate async model.
This is a utility function that applications can use to start a
background task using the method that is compatible with the
selected async mode.
:param target: the target function to execute.
:param args: arguments to ... | socketio/server.py | def start_background_task(self, target, *args, **kwargs):
"""Start a background task using the appropriate async model.
This is a utility function that applications can use to start a
background task using the method that is compatible with the
selected async mode.
:param targe... | def start_background_task(self, target, *args, **kwargs):
"""Start a background task using the appropriate async model.
This is a utility function that applications can use to start a
background task using the method that is compatible with the
selected async mode.
:param targe... | [
"Start",
"a",
"background",
"task",
"using",
"the",
"appropriate",
"async",
"model",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/server.py#L487-L502 | [
"def",
"start_background_task",
"(",
"self",
",",
"target",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"self",
".",
"eio",
".",
"start_background_task",
"(",
"target",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")"
] | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | Server._emit_internal | Send a message to a client. | socketio/server.py | def _emit_internal(self, sid, event, data, namespace=None, id=None):
"""Send a message to a client."""
if six.PY2 and not self.binary:
binary = False # pragma: nocover
else:
binary = None
# tuples are expanded to multiple arguments, everything else is sent
... | def _emit_internal(self, sid, event, data, namespace=None, id=None):
"""Send a message to a client."""
if six.PY2 and not self.binary:
binary = False # pragma: nocover
else:
binary = None
# tuples are expanded to multiple arguments, everything else is sent
... | [
"Send",
"a",
"message",
"to",
"a",
"client",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/server.py#L514-L528 | [
"def",
"_emit_internal",
"(",
"self",
",",
"sid",
",",
"event",
",",
"data",
",",
"namespace",
"=",
"None",
",",
"id",
"=",
"None",
")",
":",
"if",
"six",
".",
"PY2",
"and",
"not",
"self",
".",
"binary",
":",
"binary",
"=",
"False",
"# pragma: nocove... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | Server._send_packet | Send a Socket.IO packet to a client. | socketio/server.py | def _send_packet(self, sid, pkt):
"""Send a Socket.IO packet to a client."""
encoded_packet = pkt.encode()
if isinstance(encoded_packet, list):
binary = False
for ep in encoded_packet:
self.eio.send(sid, ep, binary=binary)
binary = True
... | def _send_packet(self, sid, pkt):
"""Send a Socket.IO packet to a client."""
encoded_packet = pkt.encode()
if isinstance(encoded_packet, list):
binary = False
for ep in encoded_packet:
self.eio.send(sid, ep, binary=binary)
binary = True
... | [
"Send",
"a",
"Socket",
".",
"IO",
"packet",
"to",
"a",
"client",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/server.py#L530-L539 | [
"def",
"_send_packet",
"(",
"self",
",",
"sid",
",",
"pkt",
")",
":",
"encoded_packet",
"=",
"pkt",
".",
"encode",
"(",
")",
"if",
"isinstance",
"(",
"encoded_packet",
",",
"list",
")",
":",
"binary",
"=",
"False",
"for",
"ep",
"in",
"encoded_packet",
... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | Server._handle_connect | Handle a client connection request. | socketio/server.py | def _handle_connect(self, sid, namespace):
"""Handle a client connection request."""
namespace = namespace or '/'
self.manager.connect(sid, namespace)
if self.always_connect:
self._send_packet(sid, packet.Packet(packet.CONNECT,
... | def _handle_connect(self, sid, namespace):
"""Handle a client connection request."""
namespace = namespace or '/'
self.manager.connect(sid, namespace)
if self.always_connect:
self._send_packet(sid, packet.Packet(packet.CONNECT,
... | [
"Handle",
"a",
"client",
"connection",
"request",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/server.py#L541-L570 | [
"def",
"_handle_connect",
"(",
"self",
",",
"sid",
",",
"namespace",
")",
":",
"namespace",
"=",
"namespace",
"or",
"'/'",
"self",
".",
"manager",
".",
"connect",
"(",
"sid",
",",
"namespace",
")",
"if",
"self",
".",
"always_connect",
":",
"self",
".",
... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | Server._handle_disconnect | Handle a client disconnect. | socketio/server.py | def _handle_disconnect(self, sid, namespace):
"""Handle a client disconnect."""
namespace = namespace or '/'
if namespace == '/':
namespace_list = list(self.manager.get_namespaces())
else:
namespace_list = [namespace]
for n in namespace_list:
i... | def _handle_disconnect(self, sid, namespace):
"""Handle a client disconnect."""
namespace = namespace or '/'
if namespace == '/':
namespace_list = list(self.manager.get_namespaces())
else:
namespace_list = [namespace]
for n in namespace_list:
i... | [
"Handle",
"a",
"client",
"disconnect",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/server.py#L572-L585 | [
"def",
"_handle_disconnect",
"(",
"self",
",",
"sid",
",",
"namespace",
")",
":",
"namespace",
"=",
"namespace",
"or",
"'/'",
"if",
"namespace",
"==",
"'/'",
":",
"namespace_list",
"=",
"list",
"(",
"self",
".",
"manager",
".",
"get_namespaces",
"(",
")",
... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | Server._handle_event | Handle an incoming client event. | socketio/server.py | def _handle_event(self, sid, namespace, id, data):
"""Handle an incoming client event."""
namespace = namespace or '/'
self.logger.info('received event "%s" from %s [%s]', data[0], sid,
namespace)
if self.async_handlers:
self.start_background_task(sel... | def _handle_event(self, sid, namespace, id, data):
"""Handle an incoming client event."""
namespace = namespace or '/'
self.logger.info('received event "%s" from %s [%s]', data[0], sid,
namespace)
if self.async_handlers:
self.start_background_task(sel... | [
"Handle",
"an",
"incoming",
"client",
"event",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/server.py#L587-L596 | [
"def",
"_handle_event",
"(",
"self",
",",
"sid",
",",
"namespace",
",",
"id",
",",
"data",
")",
":",
"namespace",
"=",
"namespace",
"or",
"'/'",
"self",
".",
"logger",
".",
"info",
"(",
"'received event \"%s\" from %s [%s]'",
",",
"data",
"[",
"0",
"]",
... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | Server._trigger_event | Invoke an application event handler. | socketio/server.py | def _trigger_event(self, event, namespace, *args):
"""Invoke an application event handler."""
# first see if we have an explicit handler for the event
if namespace in self.handlers and event in self.handlers[namespace]:
return self.handlers[namespace][event](*args)
# or else... | def _trigger_event(self, event, namespace, *args):
"""Invoke an application event handler."""
# first see if we have an explicit handler for the event
if namespace in self.handlers and event in self.handlers[namespace]:
return self.handlers[namespace][event](*args)
# or else... | [
"Invoke",
"an",
"application",
"event",
"handler",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/server.py#L624-L633 | [
"def",
"_trigger_event",
"(",
"self",
",",
"event",
",",
"namespace",
",",
"*",
"args",
")",
":",
"# first see if we have an explicit handler for the event",
"if",
"namespace",
"in",
"self",
".",
"handlers",
"and",
"event",
"in",
"self",
".",
"handlers",
"[",
"n... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | Server._handle_eio_connect | Handle the Engine.IO connection event. | socketio/server.py | def _handle_eio_connect(self, sid, environ):
"""Handle the Engine.IO connection event."""
if not self.manager_initialized:
self.manager_initialized = True
self.manager.initialize()
self.environ[sid] = environ
return self._handle_connect(sid, '/') | def _handle_eio_connect(self, sid, environ):
"""Handle the Engine.IO connection event."""
if not self.manager_initialized:
self.manager_initialized = True
self.manager.initialize()
self.environ[sid] = environ
return self._handle_connect(sid, '/') | [
"Handle",
"the",
"Engine",
".",
"IO",
"connection",
"event",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/server.py#L635-L641 | [
"def",
"_handle_eio_connect",
"(",
"self",
",",
"sid",
",",
"environ",
")",
":",
"if",
"not",
"self",
".",
"manager_initialized",
":",
"self",
".",
"manager_initialized",
"=",
"True",
"self",
".",
"manager",
".",
"initialize",
"(",
")",
"self",
".",
"envir... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | Server._handle_eio_message | Dispatch Engine.IO messages. | socketio/server.py | def _handle_eio_message(self, sid, data):
"""Dispatch Engine.IO messages."""
if sid in self._binary_packet:
pkt = self._binary_packet[sid]
if pkt.add_attachment(data):
del self._binary_packet[sid]
if pkt.packet_type == packet.BINARY_EVENT:
... | def _handle_eio_message(self, sid, data):
"""Dispatch Engine.IO messages."""
if sid in self._binary_packet:
pkt = self._binary_packet[sid]
if pkt.add_attachment(data):
del self._binary_packet[sid]
if pkt.packet_type == packet.BINARY_EVENT:
... | [
"Dispatch",
"Engine",
".",
"IO",
"messages",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/server.py#L643-L669 | [
"def",
"_handle_eio_message",
"(",
"self",
",",
"sid",
",",
"data",
")",
":",
"if",
"sid",
"in",
"self",
".",
"_binary_packet",
":",
"pkt",
"=",
"self",
".",
"_binary_packet",
"[",
"sid",
"]",
"if",
"pkt",
".",
"add_attachment",
"(",
"data",
")",
":",
... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | Server._handle_eio_disconnect | Handle Engine.IO disconnect event. | socketio/server.py | def _handle_eio_disconnect(self, sid):
"""Handle Engine.IO disconnect event."""
self._handle_disconnect(sid, '/')
if sid in self.environ:
del self.environ[sid] | def _handle_eio_disconnect(self, sid):
"""Handle Engine.IO disconnect event."""
self._handle_disconnect(sid, '/')
if sid in self.environ:
del self.environ[sid] | [
"Handle",
"Engine",
".",
"IO",
"disconnect",
"event",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/server.py#L671-L675 | [
"def",
"_handle_eio_disconnect",
"(",
"self",
",",
"sid",
")",
":",
"self",
".",
"_handle_disconnect",
"(",
"sid",
",",
"'/'",
")",
"if",
"sid",
"in",
"self",
".",
"environ",
":",
"del",
"self",
".",
"environ",
"[",
"sid",
"]"
] | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | AsyncPubSubManager.emit | Emit a message to a single client, a room, or all the clients
connected to the namespace.
This method takes care or propagating the message to all the servers
that are connected through the message queue.
The parameters are the same as in :meth:`.Server.emit`.
Note: this metho... | socketio/asyncio_pubsub_manager.py | async def emit(self, event, data, namespace=None, room=None, skip_sid=None,
callback=None, **kwargs):
"""Emit a message to a single client, a room, or all the clients
connected to the namespace.
This method takes care or propagating the message to all the servers
that... | async def emit(self, event, data, namespace=None, room=None, skip_sid=None,
callback=None, **kwargs):
"""Emit a message to a single client, a room, or all the clients
connected to the namespace.
This method takes care or propagating the message to all the servers
that... | [
"Emit",
"a",
"message",
"to",
"a",
"single",
"client",
"a",
"room",
"or",
"all",
"the",
"clients",
"connected",
"to",
"the",
"namespace",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/asyncio_pubsub_manager.py#L40-L70 | [
"async",
"def",
"emit",
"(",
"self",
",",
"event",
",",
"data",
",",
"namespace",
"=",
"None",
",",
"room",
"=",
"None",
",",
"skip_sid",
"=",
"None",
",",
"callback",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"kwargs",
".",
"get",
"(... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | AsyncClient.connect | Connect to a Socket.IO server.
:param url: The URL of the Socket.IO server. It can include custom
query string parameters if required by the server.
:param headers: A dictionary with custom headers to send with the
connection request.
:param transport... | socketio/asyncio_client.py | async def connect(self, url, headers={}, transports=None,
namespaces=None, socketio_path='socket.io'):
"""Connect to a Socket.IO server.
:param url: The URL of the Socket.IO server. It can include custom
query string parameters if required by the server.
... | async def connect(self, url, headers={}, transports=None,
namespaces=None, socketio_path='socket.io'):
"""Connect to a Socket.IO server.
:param url: The URL of the Socket.IO server. It can include custom
query string parameters if required by the server.
... | [
"Connect",
"to",
"a",
"Socket",
".",
"IO",
"server",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/asyncio_client.py#L59-L104 | [
"async",
"def",
"connect",
"(",
"self",
",",
"url",
",",
"headers",
"=",
"{",
"}",
",",
"transports",
"=",
"None",
",",
"namespaces",
"=",
"None",
",",
"socketio_path",
"=",
"'socket.io'",
")",
":",
"self",
".",
"connection_url",
"=",
"url",
"self",
".... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | AsyncClient.wait | Wait until the connection with the server ends.
Client applications can use this function to block the main thread
during the life of the connection.
Note: this method is a coroutine. | socketio/asyncio_client.py | async def wait(self):
"""Wait until the connection with the server ends.
Client applications can use this function to block the main thread
during the life of the connection.
Note: this method is a coroutine.
"""
while True:
await self.eio.wait()
... | async def wait(self):
"""Wait until the connection with the server ends.
Client applications can use this function to block the main thread
during the life of the connection.
Note: this method is a coroutine.
"""
while True:
await self.eio.wait()
... | [
"Wait",
"until",
"the",
"connection",
"with",
"the",
"server",
"ends",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/asyncio_client.py#L106-L121 | [
"async",
"def",
"wait",
"(",
"self",
")",
":",
"while",
"True",
":",
"await",
"self",
".",
"eio",
".",
"wait",
"(",
")",
"await",
"self",
".",
"sleep",
"(",
"1",
")",
"# give the reconnect task time to start up",
"if",
"not",
"self",
".",
"_reconnect_task"... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | Client.register_namespace | Register a namespace handler object.
:param namespace_handler: An instance of a :class:`Namespace`
subclass that handles all the event traffic
for a namespace. | socketio/client.py | def register_namespace(self, namespace_handler):
"""Register a namespace handler object.
:param namespace_handler: An instance of a :class:`Namespace`
subclass that handles all the event traffic
for a namespace.
"""
if ... | def register_namespace(self, namespace_handler):
"""Register a namespace handler object.
:param namespace_handler: An instance of a :class:`Namespace`
subclass that handles all the event traffic
for a namespace.
"""
if ... | [
"Register",
"a",
"namespace",
"handler",
"object",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/client.py#L153-L166 | [
"def",
"register_namespace",
"(",
"self",
",",
"namespace_handler",
")",
":",
"if",
"not",
"isinstance",
"(",
"namespace_handler",
",",
"namespace",
".",
"ClientNamespace",
")",
":",
"raise",
"ValueError",
"(",
"'Not a namespace instance'",
")",
"if",
"self",
".",... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | Client.emit | Emit a custom event to one or more connected clients.
:param event: The event name. It can be any string. The event names
``'connect'``, ``'message'`` and ``'disconnect'`` are
reserved and should not be used.
:param data: The data to send to the client or cli... | socketio/client.py | def emit(self, event, data=None, namespace=None, callback=None):
"""Emit a custom event to one or more connected clients.
:param event: The event name. It can be any string. The event names
``'connect'``, ``'message'`` and ``'disconnect'`` are
reserved and sh... | def emit(self, event, data=None, namespace=None, callback=None):
"""Emit a custom event to one or more connected clients.
:param event: The event name. It can be any string. The event names
``'connect'``, ``'message'`` and ``'disconnect'`` are
reserved and sh... | [
"Emit",
"a",
"custom",
"event",
"to",
"one",
"or",
"more",
"connected",
"clients",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/client.py#L227-L265 | [
"def",
"emit",
"(",
"self",
",",
"event",
",",
"data",
"=",
"None",
",",
"namespace",
"=",
"None",
",",
"callback",
"=",
"None",
")",
":",
"namespace",
"=",
"namespace",
"or",
"'/'",
"self",
".",
"logger",
".",
"info",
"(",
"'Emitting event \"%s\" [%s]'"... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | Client.send | Send a message to one or more connected clients.
This function emits an event with the name ``'message'``. Use
:func:`emit` to issue custom event names.
:param data: The data to send to the client or clients. Data can be of
type ``str``, ``bytes``, ``list`` or ``dict``. If... | socketio/client.py | def send(self, data, namespace=None, callback=None):
"""Send a message to one or more connected clients.
This function emits an event with the name ``'message'``. Use
:func:`emit` to issue custom event names.
:param data: The data to send to the client or clients. Data can be of
... | def send(self, data, namespace=None, callback=None):
"""Send a message to one or more connected clients.
This function emits an event with the name ``'message'``. Use
:func:`emit` to issue custom event names.
:param data: The data to send to the client or clients. Data can be of
... | [
"Send",
"a",
"message",
"to",
"one",
"or",
"more",
"connected",
"clients",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/client.py#L267-L286 | [
"def",
"send",
"(",
"self",
",",
"data",
",",
"namespace",
"=",
"None",
",",
"callback",
"=",
"None",
")",
":",
"self",
".",
"emit",
"(",
"'message'",
",",
"data",
"=",
"data",
",",
"namespace",
"=",
"namespace",
",",
"callback",
"=",
"callback",
")"... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | Client.call | Emit a custom event to a client and wait for the response.
:param event: The event name. It can be any string. The event names
``'connect'``, ``'message'`` and ``'disconnect'`` are
reserved and should not be used.
:param data: The data to send to the client o... | socketio/client.py | def call(self, event, data=None, namespace=None, timeout=60):
"""Emit a custom event to a client and wait for the response.
:param event: The event name. It can be any string. The event names
``'connect'``, ``'message'`` and ``'disconnect'`` are
reserved and ... | def call(self, event, data=None, namespace=None, timeout=60):
"""Emit a custom event to a client and wait for the response.
:param event: The event name. It can be any string. The event names
``'connect'``, ``'message'`` and ``'disconnect'`` are
reserved and ... | [
"Emit",
"a",
"custom",
"event",
"to",
"a",
"client",
"and",
"wait",
"for",
"the",
"response",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/client.py#L288-L317 | [
"def",
"call",
"(",
"self",
",",
"event",
",",
"data",
"=",
"None",
",",
"namespace",
"=",
"None",
",",
"timeout",
"=",
"60",
")",
":",
"callback_event",
"=",
"self",
".",
"eio",
".",
"create_event",
"(",
")",
"callback_args",
"=",
"[",
"]",
"def",
... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | Client.disconnect | Disconnect from the server. | socketio/client.py | def disconnect(self):
"""Disconnect from the server."""
# here we just request the disconnection
# later in _handle_eio_disconnect we invoke the disconnect handler
for n in self.namespaces:
self._send_packet(packet.Packet(packet.DISCONNECT, namespace=n))
self._send_pa... | def disconnect(self):
"""Disconnect from the server."""
# here we just request the disconnection
# later in _handle_eio_disconnect we invoke the disconnect handler
for n in self.namespaces:
self._send_packet(packet.Packet(packet.DISCONNECT, namespace=n))
self._send_pa... | [
"Disconnect",
"from",
"the",
"server",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/client.py#L319-L327 | [
"def",
"disconnect",
"(",
"self",
")",
":",
"# here we just request the disconnection",
"# later in _handle_eio_disconnect we invoke the disconnect handler",
"for",
"n",
"in",
"self",
".",
"namespaces",
":",
"self",
".",
"_send_packet",
"(",
"packet",
".",
"Packet",
"(",
... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | Client._handle_eio_disconnect | Handle the Engine.IO disconnection event. | socketio/client.py | def _handle_eio_disconnect(self):
"""Handle the Engine.IO disconnection event."""
self.logger.info('Engine.IO connection dropped')
for n in self.namespaces:
self._trigger_event('disconnect', namespace=n)
self._trigger_event('disconnect', namespace='/')
self.callbacks ... | def _handle_eio_disconnect(self):
"""Handle the Engine.IO disconnection event."""
self.logger.info('Engine.IO connection dropped')
for n in self.namespaces:
self._trigger_event('disconnect', namespace=n)
self._trigger_event('disconnect', namespace='/')
self.callbacks ... | [
"Handle",
"the",
"Engine",
".",
"IO",
"disconnection",
"event",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/client.py#L516-L526 | [
"def",
"_handle_eio_disconnect",
"(",
"self",
")",
":",
"self",
".",
"logger",
".",
"info",
"(",
"'Engine.IO connection dropped'",
")",
"for",
"n",
"in",
"self",
".",
"namespaces",
":",
"self",
".",
"_trigger_event",
"(",
"'disconnect'",
",",
"namespace",
"=",... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | Packet.encode | Encode the packet for transmission.
If the packet contains binary elements, this function returns a list
of packets where the first is the original packet with placeholders for
the binary components and the remaining ones the binary attachments. | socketio/packet.py | def encode(self):
"""Encode the packet for transmission.
If the packet contains binary elements, this function returns a list
of packets where the first is the original packet with placeholders for
the binary components and the remaining ones the binary attachments.
"""
... | def encode(self):
"""Encode the packet for transmission.
If the packet contains binary elements, this function returns a list
of packets where the first is the original packet with placeholders for
the binary components and the remaining ones the binary attachments.
"""
... | [
"Encode",
"the",
"packet",
"for",
"transmission",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/packet.py#L45-L74 | [
"def",
"encode",
"(",
"self",
")",
":",
"encoded_packet",
"=",
"six",
".",
"text_type",
"(",
"self",
".",
"packet_type",
")",
"if",
"self",
".",
"packet_type",
"==",
"BINARY_EVENT",
"or",
"self",
".",
"packet_type",
"==",
"BINARY_ACK",
":",
"data",
",",
... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | Packet.decode | Decode a transmitted package.
The return value indicates how many binary attachment packets are
necessary to fully decode the packet. | socketio/packet.py | def decode(self, encoded_packet):
"""Decode a transmitted package.
The return value indicates how many binary attachment packets are
necessary to fully decode the packet.
"""
ep = encoded_packet
try:
self.packet_type = int(ep[0:1])
except TypeError:
... | def decode(self, encoded_packet):
"""Decode a transmitted package.
The return value indicates how many binary attachment packets are
necessary to fully decode the packet.
"""
ep = encoded_packet
try:
self.packet_type = int(ep[0:1])
except TypeError:
... | [
"Decode",
"a",
"transmitted",
"package",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/packet.py#L76-L114 | [
"def",
"decode",
"(",
"self",
",",
"encoded_packet",
")",
":",
"ep",
"=",
"encoded_packet",
"try",
":",
"self",
".",
"packet_type",
"=",
"int",
"(",
"ep",
"[",
"0",
":",
"1",
"]",
")",
"except",
"TypeError",
":",
"self",
".",
"packet_type",
"=",
"ep"... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | Packet.reconstruct_binary | Reconstruct a decoded packet using the given list of binary
attachments. | socketio/packet.py | def reconstruct_binary(self, attachments):
"""Reconstruct a decoded packet using the given list of binary
attachments.
"""
self.data = self._reconstruct_binary_internal(self.data,
self.attachments) | def reconstruct_binary(self, attachments):
"""Reconstruct a decoded packet using the given list of binary
attachments.
"""
self.data = self._reconstruct_binary_internal(self.data,
self.attachments) | [
"Reconstruct",
"a",
"decoded",
"packet",
"using",
"the",
"given",
"list",
"of",
"binary",
"attachments",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/packet.py#L125-L130 | [
"def",
"reconstruct_binary",
"(",
"self",
",",
"attachments",
")",
":",
"self",
".",
"data",
"=",
"self",
".",
"_reconstruct_binary_internal",
"(",
"self",
".",
"data",
",",
"self",
".",
"attachments",
")"
] | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | Packet._deconstruct_binary | Extract binary components in the packet. | socketio/packet.py | def _deconstruct_binary(self, data):
"""Extract binary components in the packet."""
attachments = []
data = self._deconstruct_binary_internal(data, attachments)
return data, attachments | def _deconstruct_binary(self, data):
"""Extract binary components in the packet."""
attachments = []
data = self._deconstruct_binary_internal(data, attachments)
return data, attachments | [
"Extract",
"binary",
"components",
"in",
"the",
"packet",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/packet.py#L146-L150 | [
"def",
"_deconstruct_binary",
"(",
"self",
",",
"data",
")",
":",
"attachments",
"=",
"[",
"]",
"data",
"=",
"self",
".",
"_deconstruct_binary_internal",
"(",
"data",
",",
"attachments",
")",
"return",
"data",
",",
"attachments"
] | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | Packet._data_is_binary | Check if the data contains binary components. | socketio/packet.py | def _data_is_binary(self, data):
"""Check if the data contains binary components."""
if isinstance(data, six.binary_type):
return True
elif isinstance(data, list):
return functools.reduce(
lambda a, b: a or b, [self._data_is_binary(item)
... | def _data_is_binary(self, data):
"""Check if the data contains binary components."""
if isinstance(data, six.binary_type):
return True
elif isinstance(data, list):
return functools.reduce(
lambda a, b: a or b, [self._data_is_binary(item)
... | [
"Check",
"if",
"the",
"data",
"contains",
"binary",
"components",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/packet.py#L165-L179 | [
"def",
"_data_is_binary",
"(",
"self",
",",
"data",
")",
":",
"if",
"isinstance",
"(",
"data",
",",
"six",
".",
"binary_type",
")",
":",
"return",
"True",
"elif",
"isinstance",
"(",
"data",
",",
"list",
")",
":",
"return",
"functools",
".",
"reduce",
"... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | AsyncNamespace.trigger_event | Dispatch an event to the proper handler method.
In the most common usage, this method is not overloaded by subclasses,
as it performs the routing of events to methods. However, this
method can be overriden if special dispatching rules are needed, or if
having a single method that catche... | socketio/asyncio_namespace.py | async def trigger_event(self, event, *args):
"""Dispatch an event to the proper handler method.
In the most common usage, this method is not overloaded by subclasses,
as it performs the routing of events to methods. However, this
method can be overriden if special dispatching rules are ... | async def trigger_event(self, event, *args):
"""Dispatch an event to the proper handler method.
In the most common usage, this method is not overloaded by subclasses,
as it performs the routing of events to methods. However, this
method can be overriden if special dispatching rules are ... | [
"Dispatch",
"an",
"event",
"to",
"the",
"proper",
"handler",
"method",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/asyncio_namespace.py#L22-L42 | [
"async",
"def",
"trigger_event",
"(",
"self",
",",
"event",
",",
"*",
"args",
")",
":",
"handler_name",
"=",
"'on_'",
"+",
"event",
"if",
"hasattr",
"(",
"self",
",",
"handler_name",
")",
":",
"handler",
"=",
"getattr",
"(",
"self",
",",
"handler_name",
... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | AsyncNamespace.close_room | Close a room.
The only difference with the :func:`socketio.Server.close_room` method
is that when the ``namespace`` argument is not given the namespace
associated with the class is used.
Note: this method is a coroutine. | socketio/asyncio_namespace.py | async def close_room(self, room, namespace=None):
"""Close a room.
The only difference with the :func:`socketio.Server.close_room` method
is that when the ``namespace`` argument is not given the namespace
associated with the class is used.
Note: this method is a coroutine.
... | async def close_room(self, room, namespace=None):
"""Close a room.
The only difference with the :func:`socketio.Server.close_room` method
is that when the ``namespace`` argument is not given the namespace
associated with the class is used.
Note: this method is a coroutine.
... | [
"Close",
"a",
"room",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/asyncio_namespace.py#L73-L83 | [
"async",
"def",
"close_room",
"(",
"self",
",",
"room",
",",
"namespace",
"=",
"None",
")",
":",
"return",
"await",
"self",
".",
"server",
".",
"close_room",
"(",
"room",
",",
"namespace",
"=",
"namespace",
"or",
"self",
".",
"namespace",
")"
] | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | AsyncNamespace.disconnect | Disconnect a client.
The only difference with the :func:`socketio.Server.disconnect` method
is that when the ``namespace`` argument is not given the namespace
associated with the class is used.
Note: this method is a coroutine. | socketio/asyncio_namespace.py | async def disconnect(self, sid, namespace=None):
"""Disconnect a client.
The only difference with the :func:`socketio.Server.disconnect` method
is that when the ``namespace`` argument is not given the namespace
associated with the class is used.
Note: this method is a coroutine... | async def disconnect(self, sid, namespace=None):
"""Disconnect a client.
The only difference with the :func:`socketio.Server.disconnect` method
is that when the ``namespace`` argument is not given the namespace
associated with the class is used.
Note: this method is a coroutine... | [
"Disconnect",
"a",
"client",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/asyncio_namespace.py#L118-L128 | [
"async",
"def",
"disconnect",
"(",
"self",
",",
"sid",
",",
"namespace",
"=",
"None",
")",
":",
"return",
"await",
"self",
".",
"server",
".",
"disconnect",
"(",
"sid",
",",
"namespace",
"=",
"namespace",
"or",
"self",
".",
"namespace",
")"
] | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | AsyncClientNamespace.emit | Emit a custom event to the server.
The only difference with the :func:`socketio.Client.emit` method is
that when the ``namespace`` argument is not given the namespace
associated with the class is used.
Note: this method is a coroutine. | socketio/asyncio_namespace.py | async def emit(self, event, data=None, namespace=None, callback=None):
"""Emit a custom event to the server.
The only difference with the :func:`socketio.Client.emit` method is
that when the ``namespace`` argument is not given the namespace
associated with the class is used.
No... | async def emit(self, event, data=None, namespace=None, callback=None):
"""Emit a custom event to the server.
The only difference with the :func:`socketio.Client.emit` method is
that when the ``namespace`` argument is not given the namespace
associated with the class is used.
No... | [
"Emit",
"a",
"custom",
"event",
"to",
"the",
"server",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/asyncio_namespace.py#L169-L180 | [
"async",
"def",
"emit",
"(",
"self",
",",
"event",
",",
"data",
"=",
"None",
",",
"namespace",
"=",
"None",
",",
"callback",
"=",
"None",
")",
":",
"return",
"await",
"self",
".",
"client",
".",
"emit",
"(",
"event",
",",
"data",
"=",
"data",
",",
... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | AsyncClientNamespace.send | Send a message to the server.
The only difference with the :func:`socketio.Client.send` method is
that when the ``namespace`` argument is not given the namespace
associated with the class is used.
Note: this method is a coroutine. | socketio/asyncio_namespace.py | async def send(self, data, namespace=None, callback=None):
"""Send a message to the server.
The only difference with the :func:`socketio.Client.send` method is
that when the ``namespace`` argument is not given the namespace
associated with the class is used.
Note: this method i... | async def send(self, data, namespace=None, callback=None):
"""Send a message to the server.
The only difference with the :func:`socketio.Client.send` method is
that when the ``namespace`` argument is not given the namespace
associated with the class is used.
Note: this method i... | [
"Send",
"a",
"message",
"to",
"the",
"server",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/asyncio_namespace.py#L182-L193 | [
"async",
"def",
"send",
"(",
"self",
",",
"data",
",",
"namespace",
"=",
"None",
",",
"callback",
"=",
"None",
")",
":",
"return",
"await",
"self",
".",
"client",
".",
"send",
"(",
"data",
",",
"namespace",
"=",
"namespace",
"or",
"self",
".",
"names... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | BaseNamespace.trigger_event | Dispatch an event to the proper handler method.
In the most common usage, this method is not overloaded by subclasses,
as it performs the routing of events to methods. However, this
method can be overriden if special dispatching rules are needed, or if
having a single method that catche... | socketio/namespace.py | def trigger_event(self, event, *args):
"""Dispatch an event to the proper handler method.
In the most common usage, this method is not overloaded by subclasses,
as it performs the routing of events to methods. However, this
method can be overriden if special dispatching rules are needed... | def trigger_event(self, event, *args):
"""Dispatch an event to the proper handler method.
In the most common usage, this method is not overloaded by subclasses,
as it performs the routing of events to methods. However, this
method can be overriden if special dispatching rules are needed... | [
"Dispatch",
"an",
"event",
"to",
"the",
"proper",
"handler",
"method",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/namespace.py#L8-L18 | [
"def",
"trigger_event",
"(",
"self",
",",
"event",
",",
"*",
"args",
")",
":",
"handler_name",
"=",
"'on_'",
"+",
"event",
"if",
"hasattr",
"(",
"self",
",",
"handler_name",
")",
":",
"return",
"getattr",
"(",
"self",
",",
"handler_name",
")",
"(",
"*"... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | Namespace.emit | Emit a custom event to one or more connected clients.
The only difference with the :func:`socketio.Server.emit` method is
that when the ``namespace`` argument is not given the namespace
associated with the class is used. | socketio/namespace.py | def emit(self, event, data=None, room=None, skip_sid=None, namespace=None,
callback=None):
"""Emit a custom event to one or more connected clients.
The only difference with the :func:`socketio.Server.emit` method is
that when the ``namespace`` argument is not given the namespace
... | def emit(self, event, data=None, room=None, skip_sid=None, namespace=None,
callback=None):
"""Emit a custom event to one or more connected clients.
The only difference with the :func:`socketio.Server.emit` method is
that when the ``namespace`` argument is not given the namespace
... | [
"Emit",
"a",
"custom",
"event",
"to",
"one",
"or",
"more",
"connected",
"clients",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/namespace.py#L40-L50 | [
"def",
"emit",
"(",
"self",
",",
"event",
",",
"data",
"=",
"None",
",",
"room",
"=",
"None",
",",
"skip_sid",
"=",
"None",
",",
"namespace",
"=",
"None",
",",
"callback",
"=",
"None",
")",
":",
"return",
"self",
".",
"server",
".",
"emit",
"(",
... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | Namespace.send | Send a message to one or more connected clients.
The only difference with the :func:`socketio.Server.send` method is
that when the ``namespace`` argument is not given the namespace
associated with the class is used. | socketio/namespace.py | def send(self, data, room=None, skip_sid=None, namespace=None,
callback=None):
"""Send a message to one or more connected clients.
The only difference with the :func:`socketio.Server.send` method is
that when the ``namespace`` argument is not given the namespace
associated ... | def send(self, data, room=None, skip_sid=None, namespace=None,
callback=None):
"""Send a message to one or more connected clients.
The only difference with the :func:`socketio.Server.send` method is
that when the ``namespace`` argument is not given the namespace
associated ... | [
"Send",
"a",
"message",
"to",
"one",
"or",
"more",
"connected",
"clients",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/namespace.py#L52-L62 | [
"def",
"send",
"(",
"self",
",",
"data",
",",
"room",
"=",
"None",
",",
"skip_sid",
"=",
"None",
",",
"namespace",
"=",
"None",
",",
"callback",
"=",
"None",
")",
":",
"return",
"self",
".",
"server",
".",
"send",
"(",
"data",
",",
"room",
"=",
"... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | Namespace.enter_room | Enter a room.
The only difference with the :func:`socketio.Server.enter_room` method
is that when the ``namespace`` argument is not given the namespace
associated with the class is used. | socketio/namespace.py | def enter_room(self, sid, room, namespace=None):
"""Enter a room.
The only difference with the :func:`socketio.Server.enter_room` method
is that when the ``namespace`` argument is not given the namespace
associated with the class is used.
"""
return self.server.enter_roo... | def enter_room(self, sid, room, namespace=None):
"""Enter a room.
The only difference with the :func:`socketio.Server.enter_room` method
is that when the ``namespace`` argument is not given the namespace
associated with the class is used.
"""
return self.server.enter_roo... | [
"Enter",
"a",
"room",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/namespace.py#L64-L72 | [
"def",
"enter_room",
"(",
"self",
",",
"sid",
",",
"room",
",",
"namespace",
"=",
"None",
")",
":",
"return",
"self",
".",
"server",
".",
"enter_room",
"(",
"sid",
",",
"room",
",",
"namespace",
"=",
"namespace",
"or",
"self",
".",
"namespace",
")"
] | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | Namespace.leave_room | Leave a room.
The only difference with the :func:`socketio.Server.leave_room` method
is that when the ``namespace`` argument is not given the namespace
associated with the class is used. | socketio/namespace.py | def leave_room(self, sid, room, namespace=None):
"""Leave a room.
The only difference with the :func:`socketio.Server.leave_room` method
is that when the ``namespace`` argument is not given the namespace
associated with the class is used.
"""
return self.server.leave_roo... | def leave_room(self, sid, room, namespace=None):
"""Leave a room.
The only difference with the :func:`socketio.Server.leave_room` method
is that when the ``namespace`` argument is not given the namespace
associated with the class is used.
"""
return self.server.leave_roo... | [
"Leave",
"a",
"room",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/namespace.py#L74-L82 | [
"def",
"leave_room",
"(",
"self",
",",
"sid",
",",
"room",
",",
"namespace",
"=",
"None",
")",
":",
"return",
"self",
".",
"server",
".",
"leave_room",
"(",
"sid",
",",
"room",
",",
"namespace",
"=",
"namespace",
"or",
"self",
".",
"namespace",
")"
] | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | Namespace.rooms | Return the rooms a client is in.
The only difference with the :func:`socketio.Server.rooms` method is
that when the ``namespace`` argument is not given the namespace
associated with the class is used. | socketio/namespace.py | def rooms(self, sid, namespace=None):
"""Return the rooms a client is in.
The only difference with the :func:`socketio.Server.rooms` method is
that when the ``namespace`` argument is not given the namespace
associated with the class is used.
"""
return self.server.rooms(... | def rooms(self, sid, namespace=None):
"""Return the rooms a client is in.
The only difference with the :func:`socketio.Server.rooms` method is
that when the ``namespace`` argument is not given the namespace
associated with the class is used.
"""
return self.server.rooms(... | [
"Return",
"the",
"rooms",
"a",
"client",
"is",
"in",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/namespace.py#L94-L101 | [
"def",
"rooms",
"(",
"self",
",",
"sid",
",",
"namespace",
"=",
"None",
")",
":",
"return",
"self",
".",
"server",
".",
"rooms",
"(",
"sid",
",",
"namespace",
"=",
"namespace",
"or",
"self",
".",
"namespace",
")"
] | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | Namespace.get_session | Return the user session for a client.
The only difference with the :func:`socketio.Server.get_session`
method is that when the ``namespace`` argument is not given the
namespace associated with the class is used. | socketio/namespace.py | def get_session(self, sid, namespace=None):
"""Return the user session for a client.
The only difference with the :func:`socketio.Server.get_session`
method is that when the ``namespace`` argument is not given the
namespace associated with the class is used.
"""
return s... | def get_session(self, sid, namespace=None):
"""Return the user session for a client.
The only difference with the :func:`socketio.Server.get_session`
method is that when the ``namespace`` argument is not given the
namespace associated with the class is used.
"""
return s... | [
"Return",
"the",
"user",
"session",
"for",
"a",
"client",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/namespace.py#L103-L111 | [
"def",
"get_session",
"(",
"self",
",",
"sid",
",",
"namespace",
"=",
"None",
")",
":",
"return",
"self",
".",
"server",
".",
"get_session",
"(",
"sid",
",",
"namespace",
"=",
"namespace",
"or",
"self",
".",
"namespace",
")"
] | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | Namespace.save_session | Store the user session for a client.
The only difference with the :func:`socketio.Server.save_session`
method is that when the ``namespace`` argument is not given the
namespace associated with the class is used. | socketio/namespace.py | def save_session(self, sid, session, namespace=None):
"""Store the user session for a client.
The only difference with the :func:`socketio.Server.save_session`
method is that when the ``namespace`` argument is not given the
namespace associated with the class is used.
"""
... | def save_session(self, sid, session, namespace=None):
"""Store the user session for a client.
The only difference with the :func:`socketio.Server.save_session`
method is that when the ``namespace`` argument is not given the
namespace associated with the class is used.
"""
... | [
"Store",
"the",
"user",
"session",
"for",
"a",
"client",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/namespace.py#L113-L121 | [
"def",
"save_session",
"(",
"self",
",",
"sid",
",",
"session",
",",
"namespace",
"=",
"None",
")",
":",
"return",
"self",
".",
"server",
".",
"save_session",
"(",
"sid",
",",
"session",
",",
"namespace",
"=",
"namespace",
"or",
"self",
".",
"namespace",... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | ClientNamespace.send | Send a message to the server.
The only difference with the :func:`socketio.Client.send` method is
that when the ``namespace`` argument is not given the namespace
associated with the class is used. | socketio/namespace.py | def send(self, data, room=None, skip_sid=None, namespace=None,
callback=None):
"""Send a message to the server.
The only difference with the :func:`socketio.Client.send` method is
that when the ``namespace`` argument is not given the namespace
associated with the class is u... | def send(self, data, room=None, skip_sid=None, namespace=None,
callback=None):
"""Send a message to the server.
The only difference with the :func:`socketio.Client.send` method is
that when the ``namespace`` argument is not given the namespace
associated with the class is u... | [
"Send",
"a",
"message",
"to",
"the",
"server",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/namespace.py#L173-L182 | [
"def",
"send",
"(",
"self",
",",
"data",
",",
"room",
"=",
"None",
",",
"skip_sid",
"=",
"None",
",",
"namespace",
"=",
"None",
",",
"callback",
"=",
"None",
")",
":",
"return",
"self",
".",
"client",
".",
"send",
"(",
"data",
",",
"namespace",
"="... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | AsyncManager.emit | Emit a message to a single client, a room, or all the clients
connected to the namespace.
Note: this method is a coroutine. | socketio/asyncio_manager.py | async def emit(self, event, data, namespace, room=None, skip_sid=None,
callback=None, **kwargs):
"""Emit a message to a single client, a room, or all the clients
connected to the namespace.
Note: this method is a coroutine.
"""
if namespace not in self.rooms o... | async def emit(self, event, data, namespace, room=None, skip_sid=None,
callback=None, **kwargs):
"""Emit a message to a single client, a room, or all the clients
connected to the namespace.
Note: this method is a coroutine.
"""
if namespace not in self.rooms o... | [
"Emit",
"a",
"message",
"to",
"a",
"single",
"client",
"a",
"room",
"or",
"all",
"the",
"clients",
"connected",
"to",
"the",
"namespace",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/asyncio_manager.py#L8-L28 | [
"async",
"def",
"emit",
"(",
"self",
",",
"event",
",",
"data",
",",
"namespace",
",",
"room",
"=",
"None",
",",
"skip_sid",
"=",
"None",
",",
"callback",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"namespace",
"not",
"in",
"self",
".",
... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | AsyncManager.trigger_callback | Invoke an application callback.
Note: this method is a coroutine. | socketio/asyncio_manager.py | async def trigger_callback(self, sid, namespace, id, data):
"""Invoke an application callback.
Note: this method is a coroutine.
"""
callback = None
try:
callback = self.callbacks[sid][namespace][id]
except KeyError:
# if we get an unknown callbac... | async def trigger_callback(self, sid, namespace, id, data):
"""Invoke an application callback.
Note: this method is a coroutine.
"""
callback = None
try:
callback = self.callbacks[sid][namespace][id]
except KeyError:
# if we get an unknown callbac... | [
"Invoke",
"an",
"application",
"callback",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/asyncio_manager.py#L37-L56 | [
"async",
"def",
"trigger_callback",
"(",
"self",
",",
"sid",
",",
"namespace",
",",
"id",
",",
"data",
")",
":",
"callback",
"=",
"None",
"try",
":",
"callback",
"=",
"self",
".",
"callbacks",
"[",
"sid",
"]",
"[",
"namespace",
"]",
"[",
"id",
"]",
... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | AsyncServer.emit | Emit a custom event to one or more connected clients.
:param event: The event name. It can be any string. The event names
``'connect'``, ``'message'`` and ``'disconnect'`` are
reserved and should not be used.
:param data: The data to send to the client or cli... | socketio/asyncio_server.py | async def emit(self, event, data=None, room=None, skip_sid=None,
namespace=None, callback=None, **kwargs):
"""Emit a custom event to one or more connected clients.
:param event: The event name. It can be any string. The event names
``'connect'``, ``'message'`` a... | async def emit(self, event, data=None, room=None, skip_sid=None,
namespace=None, callback=None, **kwargs):
"""Emit a custom event to one or more connected clients.
:param event: The event name. It can be any string. The event names
``'connect'``, ``'message'`` a... | [
"Emit",
"a",
"custom",
"event",
"to",
"one",
"or",
"more",
"connected",
"clients",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/asyncio_server.py#L78-L119 | [
"async",
"def",
"emit",
"(",
"self",
",",
"event",
",",
"data",
"=",
"None",
",",
"room",
"=",
"None",
",",
"skip_sid",
"=",
"None",
",",
"namespace",
"=",
"None",
",",
"callback",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"namespace",
"=",
... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | AsyncServer.send | Send a message to one or more connected clients.
This function emits an event with the name ``'message'``. Use
:func:`emit` to issue custom event names.
:param data: The data to send to the client or clients. Data can be of
type ``str``, ``bytes``, ``list`` or ``dict``. If... | socketio/asyncio_server.py | async def send(self, data, room=None, skip_sid=None, namespace=None,
callback=None, **kwargs):
"""Send a message to one or more connected clients.
This function emits an event with the name ``'message'``. Use
:func:`emit` to issue custom event names.
:param data: The... | async def send(self, data, room=None, skip_sid=None, namespace=None,
callback=None, **kwargs):
"""Send a message to one or more connected clients.
This function emits an event with the name ``'message'``. Use
:func:`emit` to issue custom event names.
:param data: The... | [
"Send",
"a",
"message",
"to",
"one",
"or",
"more",
"connected",
"clients",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/asyncio_server.py#L121-L158 | [
"async",
"def",
"send",
"(",
"self",
",",
"data",
",",
"room",
"=",
"None",
",",
"skip_sid",
"=",
"None",
",",
"namespace",
"=",
"None",
",",
"callback",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"await",
"self",
".",
"emit",
"(",
"'message'"... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | AsyncServer.close_room | Close a room.
This function removes all the clients from the given room.
:param room: Room name.
:param namespace: The Socket.IO namespace for the event. If this
argument is omitted the default namespace is used.
Note: this method is a coroutine. | socketio/asyncio_server.py | async def close_room(self, room, namespace=None):
"""Close a room.
This function removes all the clients from the given room.
:param room: Room name.
:param namespace: The Socket.IO namespace for the event. If this
argument is omitted the default namespace is ... | async def close_room(self, room, namespace=None):
"""Close a room.
This function removes all the clients from the given room.
:param room: Room name.
:param namespace: The Socket.IO namespace for the event. If this
argument is omitted the default namespace is ... | [
"Close",
"a",
"room",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/asyncio_server.py#L205-L218 | [
"async",
"def",
"close_room",
"(",
"self",
",",
"room",
",",
"namespace",
"=",
"None",
")",
":",
"namespace",
"=",
"namespace",
"or",
"'/'",
"self",
".",
"logger",
".",
"info",
"(",
"'room %s is closing [%s]'",
",",
"room",
",",
"namespace",
")",
"await",
... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | AsyncServer.disconnect | Disconnect a client.
:param sid: Session ID of the client.
:param namespace: The Socket.IO namespace to disconnect. If this
argument is omitted the default namespace is used.
Note: this method is a coroutine. | socketio/asyncio_server.py | async def disconnect(self, sid, namespace=None):
"""Disconnect a client.
:param sid: Session ID of the client.
:param namespace: The Socket.IO namespace to disconnect. If this
argument is omitted the default namespace is used.
Note: this method is a coroutine.... | async def disconnect(self, sid, namespace=None):
"""Disconnect a client.
:param sid: Session ID of the client.
:param namespace: The Socket.IO namespace to disconnect. If this
argument is omitted the default namespace is used.
Note: this method is a coroutine.... | [
"Disconnect",
"a",
"client",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/asyncio_server.py#L287-L303 | [
"async",
"def",
"disconnect",
"(",
"self",
",",
"sid",
",",
"namespace",
"=",
"None",
")",
":",
"namespace",
"=",
"namespace",
"or",
"'/'",
"if",
"self",
".",
"manager",
".",
"is_connected",
"(",
"sid",
",",
"namespace",
"=",
"namespace",
")",
":",
"se... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | AsyncServer._handle_ack | Handle ACK packets from the client. | socketio/asyncio_server.py | async def _handle_ack(self, sid, namespace, id, data):
"""Handle ACK packets from the client."""
namespace = namespace or '/'
self.logger.info('received ack from %s [%s]', sid, namespace)
await self.manager.trigger_callback(sid, namespace, id, data) | async def _handle_ack(self, sid, namespace, id, data):
"""Handle ACK packets from the client."""
namespace = namespace or '/'
self.logger.info('received ack from %s [%s]', sid, namespace)
await self.manager.trigger_callback(sid, namespace, id, data) | [
"Handle",
"ACK",
"packets",
"from",
"the",
"client",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/asyncio_server.py#L440-L444 | [
"async",
"def",
"_handle_ack",
"(",
"self",
",",
"sid",
",",
"namespace",
",",
"id",
",",
"data",
")",
":",
"namespace",
"=",
"namespace",
"or",
"'/'",
"self",
".",
"logger",
".",
"info",
"(",
"'received ack from %s [%s]'",
",",
"sid",
",",
"namespace",
... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | AsyncServer._trigger_event | Invoke an application event handler. | socketio/asyncio_server.py | async def _trigger_event(self, event, namespace, *args):
"""Invoke an application event handler."""
# first see if we have an explicit handler for the event
if namespace in self.handlers and event in self.handlers[namespace]:
if asyncio.iscoroutinefunction(self.handlers[namespace][ev... | async def _trigger_event(self, event, namespace, *args):
"""Invoke an application event handler."""
# first see if we have an explicit handler for the event
if namespace in self.handlers and event in self.handlers[namespace]:
if asyncio.iscoroutinefunction(self.handlers[namespace][ev... | [
"Invoke",
"an",
"application",
"event",
"handler",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/asyncio_server.py#L446-L463 | [
"async",
"def",
"_trigger_event",
"(",
"self",
",",
"event",
",",
"namespace",
",",
"*",
"args",
")",
":",
"# first see if we have an explicit handler for the event",
"if",
"namespace",
"in",
"self",
".",
"handlers",
"and",
"event",
"in",
"self",
".",
"handlers",
... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | should_set_tablename | Determine whether ``__tablename__`` should be automatically generated
for a model.
* If no class in the MRO sets a name, one should be generated.
* If a declared attr is found, it should be used instead.
* If a name is found, it should be used if the class is a mixin, otherwise
one should be gene... | flask_sqlalchemy/model.py | def should_set_tablename(cls):
"""Determine whether ``__tablename__`` should be automatically generated
for a model.
* If no class in the MRO sets a name, one should be generated.
* If a declared attr is found, it should be used instead.
* If a name is found, it should be used if the class is a mix... | def should_set_tablename(cls):
"""Determine whether ``__tablename__`` should be automatically generated
for a model.
* If no class in the MRO sets a name, one should be generated.
* If a declared attr is found, it should be used instead.
* If a name is found, it should be used if the class is a mix... | [
"Determine",
"whether",
"__tablename__",
"should",
"be",
"automatically",
"generated",
"for",
"a",
"model",
"."
] | pallets/flask-sqlalchemy | python | https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/flask_sqlalchemy/model.py#L11-L44 | [
"def",
"should_set_tablename",
"(",
"cls",
")",
":",
"if",
"(",
"cls",
".",
"__dict__",
".",
"get",
"(",
"'__abstract__'",
",",
"False",
")",
"or",
"not",
"any",
"(",
"isinstance",
"(",
"b",
",",
"DeclarativeMeta",
")",
"for",
"b",
"in",
"cls",
".",
... | 3d3261f4fc6d28f5bf407cf7d523e36a09a8c144 |
train | login_required | View decorator that redirects anonymous users to the login page. | examples/flaskr/flaskr/auth/views.py | def login_required(view):
"""View decorator that redirects anonymous users to the login page."""
@functools.wraps(view)
def wrapped_view(**kwargs):
if g.user is None:
return redirect(url_for("auth.login"))
return view(**kwargs)
return wrapped_view | def login_required(view):
"""View decorator that redirects anonymous users to the login page."""
@functools.wraps(view)
def wrapped_view(**kwargs):
if g.user is None:
return redirect(url_for("auth.login"))
return view(**kwargs)
return wrapped_view | [
"View",
"decorator",
"that",
"redirects",
"anonymous",
"users",
"to",
"the",
"login",
"page",
"."
] | pallets/flask-sqlalchemy | python | https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/examples/flaskr/flaskr/auth/views.py#L18-L28 | [
"def",
"login_required",
"(",
"view",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"view",
")",
"def",
"wrapped_view",
"(",
"*",
"*",
"kwargs",
")",
":",
"if",
"g",
".",
"user",
"is",
"None",
":",
"return",
"redirect",
"(",
"url_for",
"(",
"\"auth.... | 3d3261f4fc6d28f5bf407cf7d523e36a09a8c144 |
train | load_logged_in_user | If a user id is stored in the session, load the user object from
the database into ``g.user``. | examples/flaskr/flaskr/auth/views.py | def load_logged_in_user():
"""If a user id is stored in the session, load the user object from
the database into ``g.user``."""
user_id = session.get("user_id")
g.user = User.query.get(user_id) if user_id is not None else None | def load_logged_in_user():
"""If a user id is stored in the session, load the user object from
the database into ``g.user``."""
user_id = session.get("user_id")
g.user = User.query.get(user_id) if user_id is not None else None | [
"If",
"a",
"user",
"id",
"is",
"stored",
"in",
"the",
"session",
"load",
"the",
"user",
"object",
"from",
"the",
"database",
"into",
"g",
".",
"user",
"."
] | pallets/flask-sqlalchemy | python | https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/examples/flaskr/flaskr/auth/views.py#L32-L36 | [
"def",
"load_logged_in_user",
"(",
")",
":",
"user_id",
"=",
"session",
".",
"get",
"(",
"\"user_id\"",
")",
"g",
".",
"user",
"=",
"User",
".",
"query",
".",
"get",
"(",
"user_id",
")",
"if",
"user_id",
"is",
"not",
"None",
"else",
"None"
] | 3d3261f4fc6d28f5bf407cf7d523e36a09a8c144 |
train | register | Register a new user.
Validates that the username is not already taken. Hashes the
password for security. | examples/flaskr/flaskr/auth/views.py | def register():
"""Register a new user.
Validates that the username is not already taken. Hashes the
password for security.
"""
if request.method == "POST":
username = request.form["username"]
password = request.form["password"]
error = None
if not username:
... | def register():
"""Register a new user.
Validates that the username is not already taken. Hashes the
password for security.
"""
if request.method == "POST":
username = request.form["username"]
password = request.form["password"]
error = None
if not username:
... | [
"Register",
"a",
"new",
"user",
"."
] | pallets/flask-sqlalchemy | python | https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/examples/flaskr/flaskr/auth/views.py#L40-L68 | [
"def",
"register",
"(",
")",
":",
"if",
"request",
".",
"method",
"==",
"\"POST\"",
":",
"username",
"=",
"request",
".",
"form",
"[",
"\"username\"",
"]",
"password",
"=",
"request",
".",
"form",
"[",
"\"password\"",
"]",
"error",
"=",
"None",
"if",
"... | 3d3261f4fc6d28f5bf407cf7d523e36a09a8c144 |
train | login | Log in a registered user by adding the user id to the session. | examples/flaskr/flaskr/auth/views.py | def login():
"""Log in a registered user by adding the user id to the session."""
if request.method == "POST":
username = request.form["username"]
password = request.form["password"]
error = None
user = User.query.filter_by(username=username).first()
if user is None:
... | def login():
"""Log in a registered user by adding the user id to the session."""
if request.method == "POST":
username = request.form["username"]
password = request.form["password"]
error = None
user = User.query.filter_by(username=username).first()
if user is None:
... | [
"Log",
"in",
"a",
"registered",
"user",
"by",
"adding",
"the",
"user",
"id",
"to",
"the",
"session",
"."
] | pallets/flask-sqlalchemy | python | https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/examples/flaskr/flaskr/auth/views.py#L72-L93 | [
"def",
"login",
"(",
")",
":",
"if",
"request",
".",
"method",
"==",
"\"POST\"",
":",
"username",
"=",
"request",
".",
"form",
"[",
"\"username\"",
"]",
"password",
"=",
"request",
".",
"form",
"[",
"\"password\"",
"]",
"error",
"=",
"None",
"user",
"=... | 3d3261f4fc6d28f5bf407cf7d523e36a09a8c144 |
train | index | Show all the posts, most recent first. | examples/flaskr/flaskr/blog/views.py | def index():
"""Show all the posts, most recent first."""
posts = Post.query.order_by(Post.created.desc()).all()
return render_template("blog/index.html", posts=posts) | def index():
"""Show all the posts, most recent first."""
posts = Post.query.order_by(Post.created.desc()).all()
return render_template("blog/index.html", posts=posts) | [
"Show",
"all",
"the",
"posts",
"most",
"recent",
"first",
"."
] | pallets/flask-sqlalchemy | python | https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/examples/flaskr/flaskr/blog/views.py#L18-L21 | [
"def",
"index",
"(",
")",
":",
"posts",
"=",
"Post",
".",
"query",
".",
"order_by",
"(",
"Post",
".",
"created",
".",
"desc",
"(",
")",
")",
".",
"all",
"(",
")",
"return",
"render_template",
"(",
"\"blog/index.html\"",
",",
"posts",
"=",
"posts",
")... | 3d3261f4fc6d28f5bf407cf7d523e36a09a8c144 |
train | get_post | Get a post and its author by id.
Checks that the id exists and optionally that the current user is
the author.
:param id: id of post to get
:param check_author: require the current user to be the author
:return: the post with author information
:raise 404: if a post with the given id doesn't e... | examples/flaskr/flaskr/blog/views.py | def get_post(id, check_author=True):
"""Get a post and its author by id.
Checks that the id exists and optionally that the current user is
the author.
:param id: id of post to get
:param check_author: require the current user to be the author
:return: the post with author information
:rais... | def get_post(id, check_author=True):
"""Get a post and its author by id.
Checks that the id exists and optionally that the current user is
the author.
:param id: id of post to get
:param check_author: require the current user to be the author
:return: the post with author information
:rais... | [
"Get",
"a",
"post",
"and",
"its",
"author",
"by",
"id",
"."
] | pallets/flask-sqlalchemy | python | https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/examples/flaskr/flaskr/blog/views.py#L24-L41 | [
"def",
"get_post",
"(",
"id",
",",
"check_author",
"=",
"True",
")",
":",
"post",
"=",
"Post",
".",
"query",
".",
"get_or_404",
"(",
"id",
",",
"f\"Post id {id} doesn't exist.\"",
")",
"if",
"check_author",
"and",
"post",
".",
"author",
"!=",
"g",
".",
"... | 3d3261f4fc6d28f5bf407cf7d523e36a09a8c144 |
train | create | Create a new post for the current user. | examples/flaskr/flaskr/blog/views.py | def create():
"""Create a new post for the current user."""
if request.method == "POST":
title = request.form["title"]
body = request.form["body"]
error = None
if not title:
error = "Title is required."
if error is not None:
flash(error)
... | def create():
"""Create a new post for the current user."""
if request.method == "POST":
title = request.form["title"]
body = request.form["body"]
error = None
if not title:
error = "Title is required."
if error is not None:
flash(error)
... | [
"Create",
"a",
"new",
"post",
"for",
"the",
"current",
"user",
"."
] | pallets/flask-sqlalchemy | python | https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/examples/flaskr/flaskr/blog/views.py#L46-L63 | [
"def",
"create",
"(",
")",
":",
"if",
"request",
".",
"method",
"==",
"\"POST\"",
":",
"title",
"=",
"request",
".",
"form",
"[",
"\"title\"",
"]",
"body",
"=",
"request",
".",
"form",
"[",
"\"body\"",
"]",
"error",
"=",
"None",
"if",
"not",
"title",... | 3d3261f4fc6d28f5bf407cf7d523e36a09a8c144 |
train | update | Update a post if the current user is the author. | examples/flaskr/flaskr/blog/views.py | def update(id):
"""Update a post if the current user is the author."""
post = get_post(id)
if request.method == "POST":
title = request.form["title"]
body = request.form["body"]
error = None
if not title:
error = "Title is required."
if error is not Non... | def update(id):
"""Update a post if the current user is the author."""
post = get_post(id)
if request.method == "POST":
title = request.form["title"]
body = request.form["body"]
error = None
if not title:
error = "Title is required."
if error is not Non... | [
"Update",
"a",
"post",
"if",
"the",
"current",
"user",
"is",
"the",
"author",
"."
] | pallets/flask-sqlalchemy | python | https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/examples/flaskr/flaskr/blog/views.py#L68-L88 | [
"def",
"update",
"(",
"id",
")",
":",
"post",
"=",
"get_post",
"(",
"id",
")",
"if",
"request",
".",
"method",
"==",
"\"POST\"",
":",
"title",
"=",
"request",
".",
"form",
"[",
"\"title\"",
"]",
"body",
"=",
"request",
".",
"form",
"[",
"\"body\"",
... | 3d3261f4fc6d28f5bf407cf7d523e36a09a8c144 |
train | delete | Delete a post.
Ensures that the post exists and that the logged in user is the
author of the post. | examples/flaskr/flaskr/blog/views.py | def delete(id):
"""Delete a post.
Ensures that the post exists and that the logged in user is the
author of the post.
"""
post = get_post(id)
db.session.delete(post)
db.session.commit()
return redirect(url_for("blog.index")) | def delete(id):
"""Delete a post.
Ensures that the post exists and that the logged in user is the
author of the post.
"""
post = get_post(id)
db.session.delete(post)
db.session.commit()
return redirect(url_for("blog.index")) | [
"Delete",
"a",
"post",
"."
] | pallets/flask-sqlalchemy | python | https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/examples/flaskr/flaskr/blog/views.py#L93-L102 | [
"def",
"delete",
"(",
"id",
")",
":",
"post",
"=",
"get_post",
"(",
"id",
")",
"db",
".",
"session",
".",
"delete",
"(",
"post",
")",
"db",
".",
"session",
".",
"commit",
"(",
")",
"return",
"redirect",
"(",
"url_for",
"(",
"\"blog.index\"",
")",
"... | 3d3261f4fc6d28f5bf407cf7d523e36a09a8c144 |
train | parse_version | Take a string version and conver it to a tuple (for easier comparison), e.g.:
"1.2.3" --> (1, 2, 3)
"1.2" --> (1, 2, 0)
"1" --> (1, 0, 0) | flask_sqlalchemy/utils.py | def parse_version(v):
"""
Take a string version and conver it to a tuple (for easier comparison), e.g.:
"1.2.3" --> (1, 2, 3)
"1.2" --> (1, 2, 0)
"1" --> (1, 0, 0)
"""
parts = v.split(".")
# Pad the list to make sure there is three elements so that we get maj... | def parse_version(v):
"""
Take a string version and conver it to a tuple (for easier comparison), e.g.:
"1.2.3" --> (1, 2, 3)
"1.2" --> (1, 2, 0)
"1" --> (1, 0, 0)
"""
parts = v.split(".")
# Pad the list to make sure there is three elements so that we get maj... | [
"Take",
"a",
"string",
"version",
"and",
"conver",
"it",
"to",
"a",
"tuple",
"(",
"for",
"easier",
"comparison",
")",
"e",
".",
"g",
".",
":"
] | pallets/flask-sqlalchemy | python | https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/flask_sqlalchemy/utils.py#L6-L18 | [
"def",
"parse_version",
"(",
"v",
")",
":",
"parts",
"=",
"v",
".",
"split",
"(",
"\".\"",
")",
"# Pad the list to make sure there is three elements so that we get major, minor, point",
"# comparisons that default to \"0\" if not given. I.e. \"1.2\" --> (1, 2, 0)",
"parts",
"=",
... | 3d3261f4fc6d28f5bf407cf7d523e36a09a8c144 |
train | SignallingSession.get_bind | Return the engine or connection for a given model or
table, using the ``__bind_key__`` if it is set. | flask_sqlalchemy/__init__.py | def get_bind(self, mapper=None, clause=None):
"""Return the engine or connection for a given model or
table, using the ``__bind_key__`` if it is set.
"""
# mapper is None if someone tries to just get a connection
if mapper is not None:
try:
# SA >= 1.3... | def get_bind(self, mapper=None, clause=None):
"""Return the engine or connection for a given model or
table, using the ``__bind_key__`` if it is set.
"""
# mapper is None if someone tries to just get a connection
if mapper is not None:
try:
# SA >= 1.3... | [
"Return",
"the",
"engine",
"or",
"connection",
"for",
"a",
"given",
"model",
"or",
"table",
"using",
"the",
"__bind_key__",
"if",
"it",
"is",
"set",
"."
] | pallets/flask-sqlalchemy | python | https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/flask_sqlalchemy/__init__.py#L149-L167 | [
"def",
"get_bind",
"(",
"self",
",",
"mapper",
"=",
"None",
",",
"clause",
"=",
"None",
")",
":",
"# mapper is None if someone tries to just get a connection",
"if",
"mapper",
"is",
"not",
"None",
":",
"try",
":",
"# SA >= 1.3",
"persist_selectable",
"=",
"mapper"... | 3d3261f4fc6d28f5bf407cf7d523e36a09a8c144 |
train | Pagination.pages | The total number of pages | flask_sqlalchemy/__init__.py | def pages(self):
"""The total number of pages"""
if self.per_page == 0 or self.total is None:
pages = 0
else:
pages = int(ceil(self.total / float(self.per_page)))
return pages | def pages(self):
"""The total number of pages"""
if self.per_page == 0 or self.total is None:
pages = 0
else:
pages = int(ceil(self.total / float(self.per_page)))
return pages | [
"The",
"total",
"number",
"of",
"pages"
] | pallets/flask-sqlalchemy | python | https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/flask_sqlalchemy/__init__.py#L331-L337 | [
"def",
"pages",
"(",
"self",
")",
":",
"if",
"self",
".",
"per_page",
"==",
"0",
"or",
"self",
".",
"total",
"is",
"None",
":",
"pages",
"=",
"0",
"else",
":",
"pages",
"=",
"int",
"(",
"ceil",
"(",
"self",
".",
"total",
"/",
"float",
"(",
"sel... | 3d3261f4fc6d28f5bf407cf7d523e36a09a8c144 |
train | Pagination.next | Returns a :class:`Pagination` object for the next page. | flask_sqlalchemy/__init__.py | def next(self, error_out=False):
"""Returns a :class:`Pagination` object for the next page."""
assert self.query is not None, 'a query object is required ' \
'for this method to work'
return self.query.paginate(self.page + 1, self.per_page, error_out) | def next(self, error_out=False):
"""Returns a :class:`Pagination` object for the next page."""
assert self.query is not None, 'a query object is required ' \
'for this method to work'
return self.query.paginate(self.page + 1, self.per_page, error_out) | [
"Returns",
"a",
":",
"class",
":",
"Pagination",
"object",
"for",
"the",
"next",
"page",
"."
] | pallets/flask-sqlalchemy | python | https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/flask_sqlalchemy/__init__.py#L357-L361 | [
"def",
"next",
"(",
"self",
",",
"error_out",
"=",
"False",
")",
":",
"assert",
"self",
".",
"query",
"is",
"not",
"None",
",",
"'a query object is required '",
"'for this method to work'",
"return",
"self",
".",
"query",
".",
"paginate",
"(",
"self",
".",
"... | 3d3261f4fc6d28f5bf407cf7d523e36a09a8c144 |
train | BaseQuery.get_or_404 | Like :meth:`get` but aborts with 404 if not found instead of returning ``None``. | flask_sqlalchemy/__init__.py | def get_or_404(self, ident, description=None):
"""Like :meth:`get` but aborts with 404 if not found instead of returning ``None``."""
rv = self.get(ident)
if rv is None:
abort(404, description=description)
return rv | def get_or_404(self, ident, description=None):
"""Like :meth:`get` but aborts with 404 if not found instead of returning ``None``."""
rv = self.get(ident)
if rv is None:
abort(404, description=description)
return rv | [
"Like",
":",
"meth",
":",
"get",
"but",
"aborts",
"with",
"404",
"if",
"not",
"found",
"instead",
"of",
"returning",
"None",
"."
] | pallets/flask-sqlalchemy | python | https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/flask_sqlalchemy/__init__.py#L419-L425 | [
"def",
"get_or_404",
"(",
"self",
",",
"ident",
",",
"description",
"=",
"None",
")",
":",
"rv",
"=",
"self",
".",
"get",
"(",
"ident",
")",
"if",
"rv",
"is",
"None",
":",
"abort",
"(",
"404",
",",
"description",
"=",
"description",
")",
"return",
... | 3d3261f4fc6d28f5bf407cf7d523e36a09a8c144 |
train | BaseQuery.first_or_404 | Like :meth:`first` but aborts with 404 if not found instead of returning ``None``. | flask_sqlalchemy/__init__.py | def first_or_404(self, description=None):
"""Like :meth:`first` but aborts with 404 if not found instead of returning ``None``."""
rv = self.first()
if rv is None:
abort(404, description=description)
return rv | def first_or_404(self, description=None):
"""Like :meth:`first` but aborts with 404 if not found instead of returning ``None``."""
rv = self.first()
if rv is None:
abort(404, description=description)
return rv | [
"Like",
":",
"meth",
":",
"first",
"but",
"aborts",
"with",
"404",
"if",
"not",
"found",
"instead",
"of",
"returning",
"None",
"."
] | pallets/flask-sqlalchemy | python | https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/flask_sqlalchemy/__init__.py#L427-L433 | [
"def",
"first_or_404",
"(",
"self",
",",
"description",
"=",
"None",
")",
":",
"rv",
"=",
"self",
".",
"first",
"(",
")",
"if",
"rv",
"is",
"None",
":",
"abort",
"(",
"404",
",",
"description",
"=",
"description",
")",
"return",
"rv"
] | 3d3261f4fc6d28f5bf407cf7d523e36a09a8c144 |
train | BaseQuery.paginate | Returns ``per_page`` items from page ``page``.
If ``page`` or ``per_page`` are ``None``, they will be retrieved from
the request query. If ``max_per_page`` is specified, ``per_page`` will
be limited to that value. If there is no request or they aren't in the
query, they default to 1 and... | flask_sqlalchemy/__init__.py | def paginate(self, page=None, per_page=None, error_out=True, max_per_page=None, count=True):
"""Returns ``per_page`` items from page ``page``.
If ``page`` or ``per_page`` are ``None``, they will be retrieved from
the request query. If ``max_per_page`` is specified, ``per_page`` will
be ... | def paginate(self, page=None, per_page=None, error_out=True, max_per_page=None, count=True):
"""Returns ``per_page`` items from page ``page``.
If ``page`` or ``per_page`` are ``None``, they will be retrieved from
the request query. If ``max_per_page`` is specified, ``per_page`` will
be ... | [
"Returns",
"per_page",
"items",
"from",
"page",
"page",
"."
] | pallets/flask-sqlalchemy | python | https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/flask_sqlalchemy/__init__.py#L435-L512 | [
"def",
"paginate",
"(",
"self",
",",
"page",
"=",
"None",
",",
"per_page",
"=",
"None",
",",
"error_out",
"=",
"True",
",",
"max_per_page",
"=",
"None",
",",
"count",
"=",
"True",
")",
":",
"if",
"request",
":",
"if",
"page",
"is",
"None",
":",
"tr... | 3d3261f4fc6d28f5bf407cf7d523e36a09a8c144 |
train | SQLAlchemy.create_scoped_session | Create a :class:`~sqlalchemy.orm.scoping.scoped_session`
on the factory from :meth:`create_session`.
An extra key ``'scopefunc'`` can be set on the ``options`` dict to
specify a custom scope function. If it's not provided, Flask's app
context stack identity is used. This will ensure th... | flask_sqlalchemy/__init__.py | def create_scoped_session(self, options=None):
"""Create a :class:`~sqlalchemy.orm.scoping.scoped_session`
on the factory from :meth:`create_session`.
An extra key ``'scopefunc'`` can be set on the ``options`` dict to
specify a custom scope function. If it's not provided, Flask's app
... | def create_scoped_session(self, options=None):
"""Create a :class:`~sqlalchemy.orm.scoping.scoped_session`
on the factory from :meth:`create_session`.
An extra key ``'scopefunc'`` can be set on the ``options`` dict to
specify a custom scope function. If it's not provided, Flask's app
... | [
"Create",
"a",
":",
"class",
":",
"~sqlalchemy",
".",
"orm",
".",
"scoping",
".",
"scoped_session",
"on",
"the",
"factory",
"from",
":",
"meth",
":",
"create_session",
"."
] | pallets/flask-sqlalchemy | python | https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/flask_sqlalchemy/__init__.py#L735-L756 | [
"def",
"create_scoped_session",
"(",
"self",
",",
"options",
"=",
"None",
")",
":",
"if",
"options",
"is",
"None",
":",
"options",
"=",
"{",
"}",
"scopefunc",
"=",
"options",
".",
"pop",
"(",
"'scopefunc'",
",",
"_app_ctx_stack",
".",
"__ident_func__",
")"... | 3d3261f4fc6d28f5bf407cf7d523e36a09a8c144 |
train | SQLAlchemy.create_session | Create the session factory used by :meth:`create_scoped_session`.
The factory **must** return an object that SQLAlchemy recognizes as a session,
or registering session events may raise an exception.
Valid factories include a :class:`~sqlalchemy.orm.session.Session`
class or a :class:`~... | flask_sqlalchemy/__init__.py | def create_session(self, options):
"""Create the session factory used by :meth:`create_scoped_session`.
The factory **must** return an object that SQLAlchemy recognizes as a session,
or registering session events may raise an exception.
Valid factories include a :class:`~sqlalchemy.orm... | def create_session(self, options):
"""Create the session factory used by :meth:`create_scoped_session`.
The factory **must** return an object that SQLAlchemy recognizes as a session,
or registering session events may raise an exception.
Valid factories include a :class:`~sqlalchemy.orm... | [
"Create",
"the",
"session",
"factory",
"used",
"by",
":",
"meth",
":",
"create_scoped_session",
"."
] | pallets/flask-sqlalchemy | python | https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/flask_sqlalchemy/__init__.py#L758-L772 | [
"def",
"create_session",
"(",
"self",
",",
"options",
")",
":",
"return",
"orm",
".",
"sessionmaker",
"(",
"class_",
"=",
"SignallingSession",
",",
"db",
"=",
"self",
",",
"*",
"*",
"options",
")"
] | 3d3261f4fc6d28f5bf407cf7d523e36a09a8c144 |
train | SQLAlchemy.make_declarative_base | Creates the declarative base that all models will inherit from.
:param model: base model class (or a tuple of base classes) to pass
to :func:`~sqlalchemy.ext.declarative.declarative_base`. Or a class
returned from ``declarative_base``, in which case a new base class
is not c... | flask_sqlalchemy/__init__.py | def make_declarative_base(self, model, metadata=None):
"""Creates the declarative base that all models will inherit from.
:param model: base model class (or a tuple of base classes) to pass
to :func:`~sqlalchemy.ext.declarative.declarative_base`. Or a class
returned from ``decla... | def make_declarative_base(self, model, metadata=None):
"""Creates the declarative base that all models will inherit from.
:param model: base model class (or a tuple of base classes) to pass
to :func:`~sqlalchemy.ext.declarative.declarative_base`. Or a class
returned from ``decla... | [
"Creates",
"the",
"declarative",
"base",
"that",
"all",
"models",
"will",
"inherit",
"from",
"."
] | pallets/flask-sqlalchemy | python | https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/flask_sqlalchemy/__init__.py#L774-L805 | [
"def",
"make_declarative_base",
"(",
"self",
",",
"model",
",",
"metadata",
"=",
"None",
")",
":",
"if",
"not",
"isinstance",
"(",
"model",
",",
"DeclarativeMeta",
")",
":",
"model",
"=",
"declarative_base",
"(",
"cls",
"=",
"model",
",",
"name",
"=",
"'... | 3d3261f4fc6d28f5bf407cf7d523e36a09a8c144 |
train | SQLAlchemy.init_app | This callback can be used to initialize an application for the
use with this database setup. Never use a database in the context
of an application not initialized that way or connections will
leak. | flask_sqlalchemy/__init__.py | def init_app(self, app):
"""This callback can be used to initialize an application for the
use with this database setup. Never use a database in the context
of an application not initialized that way or connections will
leak.
"""
if (
'SQLALCHEMY_DATABASE_URI... | def init_app(self, app):
"""This callback can be used to initialize an application for the
use with this database setup. Never use a database in the context
of an application not initialized that way or connections will
leak.
"""
if (
'SQLALCHEMY_DATABASE_URI... | [
"This",
"callback",
"can",
"be",
"used",
"to",
"initialize",
"an",
"application",
"for",
"the",
"use",
"with",
"this",
"database",
"setup",
".",
"Never",
"use",
"a",
"database",
"in",
"the",
"context",
"of",
"an",
"application",
"not",
"initialized",
"that",... | pallets/flask-sqlalchemy | python | https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/flask_sqlalchemy/__init__.py#L807-L859 | [
"def",
"init_app",
"(",
"self",
",",
"app",
")",
":",
"if",
"(",
"'SQLALCHEMY_DATABASE_URI'",
"not",
"in",
"app",
".",
"config",
"and",
"'SQLALCHEMY_BINDS'",
"not",
"in",
"app",
".",
"config",
")",
":",
"warnings",
".",
"warn",
"(",
"'Neither SQLALCHEMY_DATA... | 3d3261f4fc6d28f5bf407cf7d523e36a09a8c144 |
train | SQLAlchemy.apply_driver_hacks | This method is called before engine creation and used to inject
driver specific hacks into the options. The `options` parameter is
a dictionary of keyword arguments that will then be used to call
the :func:`sqlalchemy.create_engine` function.
The default implementation provides some sa... | flask_sqlalchemy/__init__.py | def apply_driver_hacks(self, app, sa_url, options):
"""This method is called before engine creation and used to inject
driver specific hacks into the options. The `options` parameter is
a dictionary of keyword arguments that will then be used to call
the :func:`sqlalchemy.create_engine`... | def apply_driver_hacks(self, app, sa_url, options):
"""This method is called before engine creation and used to inject
driver specific hacks into the options. The `options` parameter is
a dictionary of keyword arguments that will then be used to call
the :func:`sqlalchemy.create_engine`... | [
"This",
"method",
"is",
"called",
"before",
"engine",
"creation",
"and",
"used",
"to",
"inject",
"driver",
"specific",
"hacks",
"into",
"the",
"options",
".",
"The",
"options",
"parameter",
"is",
"a",
"dictionary",
"of",
"keyword",
"arguments",
"that",
"will",... | pallets/flask-sqlalchemy | python | https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/flask_sqlalchemy/__init__.py#L871-L931 | [
"def",
"apply_driver_hacks",
"(",
"self",
",",
"app",
",",
"sa_url",
",",
"options",
")",
":",
"if",
"sa_url",
".",
"drivername",
".",
"startswith",
"(",
"'mysql'",
")",
":",
"sa_url",
".",
"query",
".",
"setdefault",
"(",
"'charset'",
",",
"'utf8'",
")"... | 3d3261f4fc6d28f5bf407cf7d523e36a09a8c144 |
train | SQLAlchemy.make_connector | Creates the connector for a given state and bind. | flask_sqlalchemy/__init__.py | def make_connector(self, app=None, bind=None):
"""Creates the connector for a given state and bind."""
return _EngineConnector(self, self.get_app(app), bind) | def make_connector(self, app=None, bind=None):
"""Creates the connector for a given state and bind."""
return _EngineConnector(self, self.get_app(app), bind) | [
"Creates",
"the",
"connector",
"for",
"a",
"given",
"state",
"and",
"bind",
"."
] | pallets/flask-sqlalchemy | python | https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/flask_sqlalchemy/__init__.py#L943-L945 | [
"def",
"make_connector",
"(",
"self",
",",
"app",
"=",
"None",
",",
"bind",
"=",
"None",
")",
":",
"return",
"_EngineConnector",
"(",
"self",
",",
"self",
".",
"get_app",
"(",
"app",
")",
",",
"bind",
")"
] | 3d3261f4fc6d28f5bf407cf7d523e36a09a8c144 |
train | SQLAlchemy.get_engine | Returns a specific engine. | flask_sqlalchemy/__init__.py | def get_engine(self, app=None, bind=None):
"""Returns a specific engine."""
app = self.get_app(app)
state = get_state(app)
with self._engine_lock:
connector = state.connectors.get(bind)
if connector is None:
connector = self.make_connector(app, ... | def get_engine(self, app=None, bind=None):
"""Returns a specific engine."""
app = self.get_app(app)
state = get_state(app)
with self._engine_lock:
connector = state.connectors.get(bind)
if connector is None:
connector = self.make_connector(app, ... | [
"Returns",
"a",
"specific",
"engine",
"."
] | pallets/flask-sqlalchemy | python | https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/flask_sqlalchemy/__init__.py#L947-L960 | [
"def",
"get_engine",
"(",
"self",
",",
"app",
"=",
"None",
",",
"bind",
"=",
"None",
")",
":",
"app",
"=",
"self",
".",
"get_app",
"(",
"app",
")",
"state",
"=",
"get_state",
"(",
"app",
")",
"with",
"self",
".",
"_engine_lock",
":",
"connector",
"... | 3d3261f4fc6d28f5bf407cf7d523e36a09a8c144 |
train | SQLAlchemy.get_app | Helper method that implements the logic to look up an
application. | flask_sqlalchemy/__init__.py | def get_app(self, reference_app=None):
"""Helper method that implements the logic to look up an
application."""
if reference_app is not None:
return reference_app
if current_app:
return current_app._get_current_object()
if self.app is not None:
... | def get_app(self, reference_app=None):
"""Helper method that implements the logic to look up an
application."""
if reference_app is not None:
return reference_app
if current_app:
return current_app._get_current_object()
if self.app is not None:
... | [
"Helper",
"method",
"that",
"implements",
"the",
"logic",
"to",
"look",
"up",
"an",
"application",
"."
] | pallets/flask-sqlalchemy | python | https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/flask_sqlalchemy/__init__.py#L972-L989 | [
"def",
"get_app",
"(",
"self",
",",
"reference_app",
"=",
"None",
")",
":",
"if",
"reference_app",
"is",
"not",
"None",
":",
"return",
"reference_app",
"if",
"current_app",
":",
"return",
"current_app",
".",
"_get_current_object",
"(",
")",
"if",
"self",
"."... | 3d3261f4fc6d28f5bf407cf7d523e36a09a8c144 |
train | SQLAlchemy.get_tables_for_bind | Returns a list of all tables relevant for a bind. | flask_sqlalchemy/__init__.py | def get_tables_for_bind(self, bind=None):
"""Returns a list of all tables relevant for a bind."""
result = []
for table in itervalues(self.Model.metadata.tables):
if table.info.get('bind_key') == bind:
result.append(table)
return result | def get_tables_for_bind(self, bind=None):
"""Returns a list of all tables relevant for a bind."""
result = []
for table in itervalues(self.Model.metadata.tables):
if table.info.get('bind_key') == bind:
result.append(table)
return result | [
"Returns",
"a",
"list",
"of",
"all",
"tables",
"relevant",
"for",
"a",
"bind",
"."
] | pallets/flask-sqlalchemy | python | https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/flask_sqlalchemy/__init__.py#L991-L997 | [
"def",
"get_tables_for_bind",
"(",
"self",
",",
"bind",
"=",
"None",
")",
":",
"result",
"=",
"[",
"]",
"for",
"table",
"in",
"itervalues",
"(",
"self",
".",
"Model",
".",
"metadata",
".",
"tables",
")",
":",
"if",
"table",
".",
"info",
".",
"get",
... | 3d3261f4fc6d28f5bf407cf7d523e36a09a8c144 |
train | SQLAlchemy.get_binds | Returns a dictionary with a table->engine mapping.
This is suitable for use of sessionmaker(binds=db.get_binds(app)). | flask_sqlalchemy/__init__.py | def get_binds(self, app=None):
"""Returns a dictionary with a table->engine mapping.
This is suitable for use of sessionmaker(binds=db.get_binds(app)).
"""
app = self.get_app(app)
binds = [None] + list(app.config.get('SQLALCHEMY_BINDS') or ())
retval = {}
for bin... | def get_binds(self, app=None):
"""Returns a dictionary with a table->engine mapping.
This is suitable for use of sessionmaker(binds=db.get_binds(app)).
"""
app = self.get_app(app)
binds = [None] + list(app.config.get('SQLALCHEMY_BINDS') or ())
retval = {}
for bin... | [
"Returns",
"a",
"dictionary",
"with",
"a",
"table",
"-",
">",
"engine",
"mapping",
"."
] | pallets/flask-sqlalchemy | python | https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/flask_sqlalchemy/__init__.py#L999-L1011 | [
"def",
"get_binds",
"(",
"self",
",",
"app",
"=",
"None",
")",
":",
"app",
"=",
"self",
".",
"get_app",
"(",
"app",
")",
"binds",
"=",
"[",
"None",
"]",
"+",
"list",
"(",
"app",
".",
"config",
".",
"get",
"(",
"'SQLALCHEMY_BINDS'",
")",
"or",
"("... | 3d3261f4fc6d28f5bf407cf7d523e36a09a8c144 |
train | SQLAlchemy.reflect | Reflects tables from the database.
.. versionchanged:: 0.12
Parameters were added | flask_sqlalchemy/__init__.py | def reflect(self, bind='__all__', app=None):
"""Reflects tables from the database.
.. versionchanged:: 0.12
Parameters were added
"""
self._execute_for_all_tables(app, bind, 'reflect', skip_tables=True) | def reflect(self, bind='__all__', app=None):
"""Reflects tables from the database.
.. versionchanged:: 0.12
Parameters were added
"""
self._execute_for_all_tables(app, bind, 'reflect', skip_tables=True) | [
"Reflects",
"tables",
"from",
"the",
"database",
"."
] | pallets/flask-sqlalchemy | python | https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/flask_sqlalchemy/__init__.py#L1047-L1053 | [
"def",
"reflect",
"(",
"self",
",",
"bind",
"=",
"'__all__'",
",",
"app",
"=",
"None",
")",
":",
"self",
".",
"_execute_for_all_tables",
"(",
"app",
",",
"bind",
",",
"'reflect'",
",",
"skip_tables",
"=",
"True",
")"
] | 3d3261f4fc6d28f5bf407cf7d523e36a09a8c144 |
train | create_app | Create and configure an instance of the Flask application. | examples/flaskr/flaskr/__init__.py | def create_app(test_config=None):
"""Create and configure an instance of the Flask application."""
app = Flask(__name__, instance_relative_config=True)
# some deploy systems set the database url in the environ
db_url = os.environ.get("DATABASE_URL")
if db_url is None:
# default to a sqlite... | def create_app(test_config=None):
"""Create and configure an instance of the Flask application."""
app = Flask(__name__, instance_relative_config=True)
# some deploy systems set the database url in the environ
db_url = os.environ.get("DATABASE_URL")
if db_url is None:
# default to a sqlite... | [
"Create",
"and",
"configure",
"an",
"instance",
"of",
"the",
"Flask",
"application",
"."
] | pallets/flask-sqlalchemy | python | https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/examples/flaskr/flaskr/__init__.py#L13-L53 | [
"def",
"create_app",
"(",
"test_config",
"=",
"None",
")",
":",
"app",
"=",
"Flask",
"(",
"__name__",
",",
"instance_relative_config",
"=",
"True",
")",
"# some deploy systems set the database url in the environ",
"db_url",
"=",
"os",
".",
"environ",
".",
"get",
"... | 3d3261f4fc6d28f5bf407cf7d523e36a09a8c144 |
train | negative_sharpe | Calculate the negative Sharpe ratio of a portfolio
:param weights: asset weights of the portfolio
:type weights: np.ndarray
:param expected_returns: expected return of each asset
:type expected_returns: pd.Series
:param cov_matrix: the covariance matrix of asset returns
:type cov_matrix: pd.Dat... | pypfopt/objective_functions.py | def negative_sharpe(
weights, expected_returns, cov_matrix, gamma=0, risk_free_rate=0.02
):
"""
Calculate the negative Sharpe ratio of a portfolio
:param weights: asset weights of the portfolio
:type weights: np.ndarray
:param expected_returns: expected return of each asset
:type expected_r... | def negative_sharpe(
weights, expected_returns, cov_matrix, gamma=0, risk_free_rate=0.02
):
"""
Calculate the negative Sharpe ratio of a portfolio
:param weights: asset weights of the portfolio
:type weights: np.ndarray
:param expected_returns: expected return of each asset
:type expected_r... | [
"Calculate",
"the",
"negative",
"Sharpe",
"ratio",
"of",
"a",
"portfolio"
] | robertmartin8/PyPortfolioOpt | python | https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/objective_functions.py#L38-L61 | [
"def",
"negative_sharpe",
"(",
"weights",
",",
"expected_returns",
",",
"cov_matrix",
",",
"gamma",
"=",
"0",
",",
"risk_free_rate",
"=",
"0.02",
")",
":",
"mu",
"=",
"weights",
".",
"dot",
"(",
"expected_returns",
")",
"sigma",
"=",
"np",
".",
"sqrt",
"... | dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc |
train | volatility | Calculate the volatility of a portfolio. This is actually a misnomer because
the function returns variance, which is technically the correct objective
function when minimising volatility.
:param weights: asset weights of the portfolio
:type weights: np.ndarray
:param cov_matrix: the covariance matr... | pypfopt/objective_functions.py | def volatility(weights, cov_matrix, gamma=0):
"""
Calculate the volatility of a portfolio. This is actually a misnomer because
the function returns variance, which is technically the correct objective
function when minimising volatility.
:param weights: asset weights of the portfolio
:type weig... | def volatility(weights, cov_matrix, gamma=0):
"""
Calculate the volatility of a portfolio. This is actually a misnomer because
the function returns variance, which is technically the correct objective
function when minimising volatility.
:param weights: asset weights of the portfolio
:type weig... | [
"Calculate",
"the",
"volatility",
"of",
"a",
"portfolio",
".",
"This",
"is",
"actually",
"a",
"misnomer",
"because",
"the",
"function",
"returns",
"variance",
"which",
"is",
"technically",
"the",
"correct",
"objective",
"function",
"when",
"minimising",
"volatilit... | robertmartin8/PyPortfolioOpt | python | https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/objective_functions.py#L64-L82 | [
"def",
"volatility",
"(",
"weights",
",",
"cov_matrix",
",",
"gamma",
"=",
"0",
")",
":",
"L2_reg",
"=",
"gamma",
"*",
"(",
"weights",
"**",
"2",
")",
".",
"sum",
"(",
")",
"portfolio_volatility",
"=",
"np",
".",
"dot",
"(",
"weights",
".",
"T",
",... | dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc |
train | negative_cvar | Calculate the negative CVaR. Though we want the "min CVaR portfolio", we
actually need to maximise the expected return of the worst q% cases, thus
we need this value to be negative.
:param weights: asset weights of the portfolio
:type weights: np.ndarray
:param returns: asset returns
:type retu... | pypfopt/objective_functions.py | def negative_cvar(weights, returns, s=10000, beta=0.95, random_state=None):
"""
Calculate the negative CVaR. Though we want the "min CVaR portfolio", we
actually need to maximise the expected return of the worst q% cases, thus
we need this value to be negative.
:param weights: asset weights of the ... | def negative_cvar(weights, returns, s=10000, beta=0.95, random_state=None):
"""
Calculate the negative CVaR. Though we want the "min CVaR portfolio", we
actually need to maximise the expected return of the worst q% cases, thus
we need this value to be negative.
:param weights: asset weights of the ... | [
"Calculate",
"the",
"negative",
"CVaR",
".",
"Though",
"we",
"want",
"the",
"min",
"CVaR",
"portfolio",
"we",
"actually",
"need",
"to",
"maximise",
"the",
"expected",
"return",
"of",
"the",
"worst",
"q%",
"cases",
"thus",
"we",
"need",
"this",
"value",
"to... | robertmartin8/PyPortfolioOpt | python | https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/objective_functions.py#L85-L113 | [
"def",
"negative_cvar",
"(",
"weights",
",",
"returns",
",",
"s",
"=",
"10000",
",",
"beta",
"=",
"0.95",
",",
"random_state",
"=",
"None",
")",
":",
"np",
".",
"random",
".",
"seed",
"(",
"seed",
"=",
"random_state",
")",
"# Calcualte the returns given th... | dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc |
train | mean_historical_return | Calculate annualised mean (daily) historical return from input (daily) asset prices.
:param prices: adjusted closing prices of the asset, each row is a date
and each column is a ticker/id.
:type prices: pd.DataFrame
:param frequency: number of time periods in a year, defaults to 252 (the... | pypfopt/expected_returns.py | def mean_historical_return(prices, frequency=252):
"""
Calculate annualised mean (daily) historical return from input (daily) asset prices.
:param prices: adjusted closing prices of the asset, each row is a date
and each column is a ticker/id.
:type prices: pd.DataFrame
:param fr... | def mean_historical_return(prices, frequency=252):
"""
Calculate annualised mean (daily) historical return from input (daily) asset prices.
:param prices: adjusted closing prices of the asset, each row is a date
and each column is a ticker/id.
:type prices: pd.DataFrame
:param fr... | [
"Calculate",
"annualised",
"mean",
"(",
"daily",
")",
"historical",
"return",
"from",
"input",
"(",
"daily",
")",
"asset",
"prices",
"."
] | robertmartin8/PyPortfolioOpt | python | https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/expected_returns.py#L32-L49 | [
"def",
"mean_historical_return",
"(",
"prices",
",",
"frequency",
"=",
"252",
")",
":",
"if",
"not",
"isinstance",
"(",
"prices",
",",
"pd",
".",
"DataFrame",
")",
":",
"warnings",
".",
"warn",
"(",
"\"prices are not in a dataframe\"",
",",
"RuntimeWarning",
"... | dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc |
train | ema_historical_return | Calculate the exponentially-weighted mean of (daily) historical returns, giving
higher weight to more recent data.
:param prices: adjusted closing prices of the asset, each row is a date
and each column is a ticker/id.
:type prices: pd.DataFrame
:param frequency: number of time perio... | pypfopt/expected_returns.py | def ema_historical_return(prices, frequency=252, span=500):
"""
Calculate the exponentially-weighted mean of (daily) historical returns, giving
higher weight to more recent data.
:param prices: adjusted closing prices of the asset, each row is a date
and each column is a ticker/id.
... | def ema_historical_return(prices, frequency=252, span=500):
"""
Calculate the exponentially-weighted mean of (daily) historical returns, giving
higher weight to more recent data.
:param prices: adjusted closing prices of the asset, each row is a date
and each column is a ticker/id.
... | [
"Calculate",
"the",
"exponentially",
"-",
"weighted",
"mean",
"of",
"(",
"daily",
")",
"historical",
"returns",
"giving",
"higher",
"weight",
"to",
"more",
"recent",
"data",
"."
] | robertmartin8/PyPortfolioOpt | python | https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/expected_returns.py#L52-L72 | [
"def",
"ema_historical_return",
"(",
"prices",
",",
"frequency",
"=",
"252",
",",
"span",
"=",
"500",
")",
":",
"if",
"not",
"isinstance",
"(",
"prices",
",",
"pd",
".",
"DataFrame",
")",
":",
"warnings",
".",
"warn",
"(",
"\"prices are not in a dataframe\""... | dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc |
train | EfficientFrontier.max_sharpe | Maximise the Sharpe Ratio. The result is also referred to as the tangency portfolio,
as it is the tangent to the efficient frontier curve that intercepts the risk-free
rate.
:param risk_free_rate: risk-free rate of borrowing/lending, defaults to 0.02
:type risk_free_rate: float, optiona... | pypfopt/efficient_frontier.py | def max_sharpe(self, risk_free_rate=0.02):
"""
Maximise the Sharpe Ratio. The result is also referred to as the tangency portfolio,
as it is the tangent to the efficient frontier curve that intercepts the risk-free
rate.
:param risk_free_rate: risk-free rate of borrowing/lending... | def max_sharpe(self, risk_free_rate=0.02):
"""
Maximise the Sharpe Ratio. The result is also referred to as the tangency portfolio,
as it is the tangent to the efficient frontier curve that intercepts the risk-free
rate.
:param risk_free_rate: risk-free rate of borrowing/lending... | [
"Maximise",
"the",
"Sharpe",
"Ratio",
".",
"The",
"result",
"is",
"also",
"referred",
"to",
"as",
"the",
"tangency",
"portfolio",
"as",
"it",
"is",
"the",
"tangent",
"to",
"the",
"efficient",
"frontier",
"curve",
"that",
"intercepts",
"the",
"risk",
"-",
"... | robertmartin8/PyPortfolioOpt | python | https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/efficient_frontier.py#L86-L111 | [
"def",
"max_sharpe",
"(",
"self",
",",
"risk_free_rate",
"=",
"0.02",
")",
":",
"if",
"not",
"isinstance",
"(",
"risk_free_rate",
",",
"(",
"int",
",",
"float",
")",
")",
":",
"raise",
"ValueError",
"(",
"\"risk_free_rate should be numeric\"",
")",
"args",
"... | dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc |
train | EfficientFrontier.min_volatility | Minimise volatility.
:return: asset weights for the volatility-minimising portfolio
:rtype: dict | pypfopt/efficient_frontier.py | def min_volatility(self):
"""
Minimise volatility.
:return: asset weights for the volatility-minimising portfolio
:rtype: dict
"""
args = (self.cov_matrix, self.gamma)
result = sco.minimize(
objective_functions.volatility,
x0=self.initial_... | def min_volatility(self):
"""
Minimise volatility.
:return: asset weights for the volatility-minimising portfolio
:rtype: dict
"""
args = (self.cov_matrix, self.gamma)
result = sco.minimize(
objective_functions.volatility,
x0=self.initial_... | [
"Minimise",
"volatility",
"."
] | robertmartin8/PyPortfolioOpt | python | https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/efficient_frontier.py#L113-L130 | [
"def",
"min_volatility",
"(",
"self",
")",
":",
"args",
"=",
"(",
"self",
".",
"cov_matrix",
",",
"self",
".",
"gamma",
")",
"result",
"=",
"sco",
".",
"minimize",
"(",
"objective_functions",
".",
"volatility",
",",
"x0",
"=",
"self",
".",
"initial_guess... | dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc |
train | EfficientFrontier.custom_objective | Optimise some objective function. While an implicit requirement is that the function
can be optimised via a quadratic optimiser, this is not enforced. Thus there is a
decent chance of silent failure.
:param objective_function: function which maps (weight, args) -> cost
:type objective_f... | pypfopt/efficient_frontier.py | def custom_objective(self, objective_function, *args):
"""
Optimise some objective function. While an implicit requirement is that the function
can be optimised via a quadratic optimiser, this is not enforced. Thus there is a
decent chance of silent failure.
:param objective_fun... | def custom_objective(self, objective_function, *args):
"""
Optimise some objective function. While an implicit requirement is that the function
can be optimised via a quadratic optimiser, this is not enforced. Thus there is a
decent chance of silent failure.
:param objective_fun... | [
"Optimise",
"some",
"objective",
"function",
".",
"While",
"an",
"implicit",
"requirement",
"is",
"that",
"the",
"function",
"can",
"be",
"optimised",
"via",
"a",
"quadratic",
"optimiser",
"this",
"is",
"not",
"enforced",
".",
"Thus",
"there",
"is",
"a",
"de... | robertmartin8/PyPortfolioOpt | python | https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/efficient_frontier.py#L132-L152 | [
"def",
"custom_objective",
"(",
"self",
",",
"objective_function",
",",
"*",
"args",
")",
":",
"result",
"=",
"sco",
".",
"minimize",
"(",
"objective_function",
",",
"x0",
"=",
"self",
".",
"initial_guess",
",",
"args",
"=",
"args",
",",
"method",
"=",
"... | dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc |
train | EfficientFrontier.efficient_risk | Calculate the Sharpe-maximising portfolio for a given volatility (i.e max return
for a target risk).
:param target_risk: the desired volatility of the resulting portfolio.
:type target_risk: float
:param risk_free_rate: risk-free rate of borrowing/lending, defaults to 0.02
:type... | pypfopt/efficient_frontier.py | def efficient_risk(self, target_risk, risk_free_rate=0.02, market_neutral=False):
"""
Calculate the Sharpe-maximising portfolio for a given volatility (i.e max return
for a target risk).
:param target_risk: the desired volatility of the resulting portfolio.
:type target_risk: fl... | def efficient_risk(self, target_risk, risk_free_rate=0.02, market_neutral=False):
"""
Calculate the Sharpe-maximising portfolio for a given volatility (i.e max return
for a target risk).
:param target_risk: the desired volatility of the resulting portfolio.
:type target_risk: fl... | [
"Calculate",
"the",
"Sharpe",
"-",
"maximising",
"portfolio",
"for",
"a",
"given",
"volatility",
"(",
"i",
".",
"e",
"max",
"return",
"for",
"a",
"target",
"risk",
")",
"."
] | robertmartin8/PyPortfolioOpt | python | https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/efficient_frontier.py#L154-L207 | [
"def",
"efficient_risk",
"(",
"self",
",",
"target_risk",
",",
"risk_free_rate",
"=",
"0.02",
",",
"market_neutral",
"=",
"False",
")",
":",
"if",
"not",
"isinstance",
"(",
"target_risk",
",",
"float",
")",
"or",
"target_risk",
"<",
"0",
":",
"raise",
"Val... | dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc |
train | EfficientFrontier.efficient_return | Calculate the 'Markowitz portfolio', minimising volatility for a given target return.
:param target_return: the desired return of the resulting portfolio.
:type target_return: float
:param market_neutral: whether the portfolio should be market neutral (weights sum to zero),
... | pypfopt/efficient_frontier.py | def efficient_return(self, target_return, market_neutral=False):
"""
Calculate the 'Markowitz portfolio', minimising volatility for a given target return.
:param target_return: the desired return of the resulting portfolio.
:type target_return: float
:param market_neutral: wheth... | def efficient_return(self, target_return, market_neutral=False):
"""
Calculate the 'Markowitz portfolio', minimising volatility for a given target return.
:param target_return: the desired return of the resulting portfolio.
:type target_return: float
:param market_neutral: wheth... | [
"Calculate",
"the",
"Markowitz",
"portfolio",
"minimising",
"volatility",
"for",
"a",
"given",
"target",
"return",
"."
] | robertmartin8/PyPortfolioOpt | python | https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/efficient_frontier.py#L209-L255 | [
"def",
"efficient_return",
"(",
"self",
",",
"target_return",
",",
"market_neutral",
"=",
"False",
")",
":",
"if",
"not",
"isinstance",
"(",
"target_return",
",",
"float",
")",
"or",
"target_return",
"<",
"0",
":",
"raise",
"ValueError",
"(",
"\"target_return ... | dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.