repo
stringlengths
7
55
path
stringlengths
4
223
func_name
stringlengths
1
134
original_string
stringlengths
75
104k
language
stringclasses
1 value
code
stringlengths
75
104k
code_tokens
listlengths
19
28.4k
docstring
stringlengths
1
46.9k
docstring_tokens
listlengths
1
1.97k
sha
stringlengths
40
40
url
stringlengths
87
315
partition
stringclasses
3 values
summary
stringlengths
4
350
getsentry/rb
rb/clients.py
CommandBuffer.enqueue_command
def enqueue_command(self, command_name, args, options): """Enqueue a new command into this pipeline.""" assert_open(self) promise = Promise() self.commands.append((command_name, args, options, promise)) return promise
python
def enqueue_command(self, command_name, args, options): """Enqueue a new command into this pipeline.""" assert_open(self) promise = Promise() self.commands.append((command_name, args, options, promise)) return promise
[ "def", "enqueue_command", "(", "self", ",", "command_name", ",", "args", ",", "options", ")", ":", "assert_open", "(", "self", ")", "promise", "=", "Promise", "(", ")", "self", ".", "commands", ".", "append", "(", "(", "command_name", ",", "args", ",", ...
Enqueue a new command into this pipeline.
[ "Enqueue", "a", "new", "command", "into", "this", "pipeline", "." ]
569d1d13311f6c04bae537fc17e75da430e4ec45
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/clients.py#L129-L134
train
Enqueue a new command into this pipeline.
getsentry/rb
rb/clients.py
CommandBuffer.send_buffer
def send_buffer(self): """Utility function that sends the buffer into the provided socket. The buffer itself will slowly clear out and is modified in place. """ buf = self._send_buf sock = self.connection._sock try: timeout = sock.gettimeout() sock...
python
def send_buffer(self): """Utility function that sends the buffer into the provided socket. The buffer itself will slowly clear out and is modified in place. """ buf = self._send_buf sock = self.connection._sock try: timeout = sock.gettimeout() sock...
[ "def", "send_buffer", "(", "self", ")", ":", "buf", "=", "self", ".", "_send_buf", "sock", "=", "self", ".", "connection", ".", "_sock", "try", ":", "timeout", "=", "sock", ".", "gettimeout", "(", ")", "sock", ".", "setblocking", "(", "False", ")", "...
Utility function that sends the buffer into the provided socket. The buffer itself will slowly clear out and is modified in place.
[ "Utility", "function", "that", "sends", "the", "buffer", "into", "the", "provided", "socket", ".", "The", "buffer", "itself", "will", "slowly", "clear", "out", "and", "is", "modified", "in", "place", "." ]
569d1d13311f6c04bae537fc17e75da430e4ec45
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/clients.py#L143-L179
train
Utility function that sends the buffer into the provided socket.
getsentry/rb
rb/clients.py
CommandBuffer.send_pending_requests
def send_pending_requests(self): """Sends all pending requests into the connection. The default is to only send pending data that fits into the socket without blocking. This returns `True` if all data was sent or `False` if pending data is left over. """ assert_open(self...
python
def send_pending_requests(self): """Sends all pending requests into the connection. The default is to only send pending data that fits into the socket without blocking. This returns `True` if all data was sent or `False` if pending data is left over. """ assert_open(self...
[ "def", "send_pending_requests", "(", "self", ")", ":", "assert_open", "(", "self", ")", "unsent_commands", "=", "self", ".", "commands", "if", "unsent_commands", ":", "self", ".", "commands", "=", "[", "]", "if", "self", ".", "auto_batch", ":", "unsent_comma...
Sends all pending requests into the connection. The default is to only send pending data that fits into the socket without blocking. This returns `True` if all data was sent or `False` if pending data is left over.
[ "Sends", "all", "pending", "requests", "into", "the", "connection", ".", "The", "default", "is", "to", "only", "send", "pending", "data", "that", "fits", "into", "the", "socket", "without", "blocking", ".", "This", "returns", "True", "if", "all", "data", "...
569d1d13311f6c04bae537fc17e75da430e4ec45
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/clients.py#L181-L208
train
Sends all pending requests into the socket.
getsentry/rb
rb/clients.py
CommandBuffer.wait_for_responses
def wait_for_responses(self, client): """Waits for all responses to come back and resolves the eventual results. """ assert_open(self) if self.has_pending_requests: raise RuntimeError('Cannot wait for responses if there are ' 'pending r...
python
def wait_for_responses(self, client): """Waits for all responses to come back and resolves the eventual results. """ assert_open(self) if self.has_pending_requests: raise RuntimeError('Cannot wait for responses if there are ' 'pending r...
[ "def", "wait_for_responses", "(", "self", ",", "client", ")", ":", "assert_open", "(", "self", ")", "if", "self", ".", "has_pending_requests", ":", "raise", "RuntimeError", "(", "'Cannot wait for responses if there are '", "'pending requests outstanding. You need '", "'t...
Waits for all responses to come back and resolves the eventual results.
[ "Waits", "for", "all", "responses", "to", "come", "back", "and", "resolves", "the", "eventual", "results", "." ]
569d1d13311f6c04bae537fc17e75da430e4ec45
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/clients.py#L210-L227
train
Waits for all responses to come back and resolves the eventual results.
getsentry/rb
rb/clients.py
MappingClient._get_command_buffer
def _get_command_buffer(self, host_id, command_name): """Returns the command buffer for the given command and arguments.""" buf = self._cb_poll.get(host_id) if buf is not None: return buf if self._max_concurrency is not None: while len(self._cb_poll) >= self._max...
python
def _get_command_buffer(self, host_id, command_name): """Returns the command buffer for the given command and arguments.""" buf = self._cb_poll.get(host_id) if buf is not None: return buf if self._max_concurrency is not None: while len(self._cb_poll) >= self._max...
[ "def", "_get_command_buffer", "(", "self", ",", "host_id", ",", "command_name", ")", ":", "buf", "=", "self", ".", "_cb_poll", ".", "get", "(", "host_id", ")", "if", "buf", "is", "not", "None", ":", "return", "buf", "if", "self", ".", "_max_concurrency",...
Returns the command buffer for the given command and arguments.
[ "Returns", "the", "command", "buffer", "for", "the", "given", "command", "and", "arguments", "." ]
569d1d13311f6c04bae537fc17e75da430e4ec45
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/clients.py#L338-L353
train
Returns the command buffer for the given command and arguments.
getsentry/rb
rb/clients.py
MappingClient._release_command_buffer
def _release_command_buffer(self, command_buffer): """This is called by the command buffer when it closes.""" if command_buffer.closed: return self._cb_poll.unregister(command_buffer.host_id) self.connection_pool.release(command_buffer.connection) command_buffer.conn...
python
def _release_command_buffer(self, command_buffer): """This is called by the command buffer when it closes.""" if command_buffer.closed: return self._cb_poll.unregister(command_buffer.host_id) self.connection_pool.release(command_buffer.connection) command_buffer.conn...
[ "def", "_release_command_buffer", "(", "self", ",", "command_buffer", ")", ":", "if", "command_buffer", ".", "closed", ":", "return", "self", ".", "_cb_poll", ".", "unregister", "(", "command_buffer", ".", "host_id", ")", "self", ".", "connection_pool", ".", "...
This is called by the command buffer when it closes.
[ "This", "is", "called", "by", "the", "command", "buffer", "when", "it", "closes", "." ]
569d1d13311f6c04bae537fc17e75da430e4ec45
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/clients.py#L355-L362
train
This is called by the command buffer when it closes.
getsentry/rb
rb/clients.py
MappingClient.join
def join(self, timeout=None): """Waits for all outstanding responses to come back or the timeout to be hit. """ remaining = timeout while self._cb_poll and (remaining is None or remaining > 0): now = time.time() rv = self._cb_poll.poll(remaining) ...
python
def join(self, timeout=None): """Waits for all outstanding responses to come back or the timeout to be hit. """ remaining = timeout while self._cb_poll and (remaining is None or remaining > 0): now = time.time() rv = self._cb_poll.poll(remaining) ...
[ "def", "join", "(", "self", ",", "timeout", "=", "None", ")", ":", "remaining", "=", "timeout", "while", "self", ".", "_cb_poll", "and", "(", "remaining", "is", "None", "or", "remaining", ">", "0", ")", ":", "now", "=", "time", ".", "time", "(", ")...
Waits for all outstanding responses to come back or the timeout to be hit.
[ "Waits", "for", "all", "outstanding", "responses", "to", "come", "back", "or", "the", "timeout", "to", "be", "hit", "." ]
569d1d13311f6c04bae537fc17e75da430e4ec45
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/clients.py#L384-L418
train
Wait for all outstanding responses to come back or the timeout to be hit.
getsentry/rb
rb/clients.py
FanoutClient.target
def target(self, hosts): """Temporarily retarget the client for one call. This is useful when having to deal with a subset of hosts for one call. """ if self.__is_retargeted: raise TypeError('Cannot use target more than once.') rv = FanoutClient(hosts, connection_poo...
python
def target(self, hosts): """Temporarily retarget the client for one call. This is useful when having to deal with a subset of hosts for one call. """ if self.__is_retargeted: raise TypeError('Cannot use target more than once.') rv = FanoutClient(hosts, connection_poo...
[ "def", "target", "(", "self", ",", "hosts", ")", ":", "if", "self", ".", "__is_retargeted", ":", "raise", "TypeError", "(", "'Cannot use target more than once.'", ")", "rv", "=", "FanoutClient", "(", "hosts", ",", "connection_pool", "=", "self", ".", "connecti...
Temporarily retarget the client for one call. This is useful when having to deal with a subset of hosts for one call.
[ "Temporarily", "retarget", "the", "client", "for", "one", "call", ".", "This", "is", "useful", "when", "having", "to", "deal", "with", "a", "subset", "of", "hosts", "for", "one", "call", "." ]
569d1d13311f6c04bae537fc17e75da430e4ec45
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/clients.py#L444-L454
train
Temporarily retarget the client for one call.
getsentry/rb
rb/clients.py
FanoutClient.target_key
def target_key(self, key): """Temporarily retarget the client for one call to route specifically to the one host that the given key routes to. In that case the result on the promise is just the one host's value instead of a dictionary. .. versionadded:: 1.3 """ ...
python
def target_key(self, key): """Temporarily retarget the client for one call to route specifically to the one host that the given key routes to. In that case the result on the promise is just the one host's value instead of a dictionary. .. versionadded:: 1.3 """ ...
[ "def", "target_key", "(", "self", ",", "key", ")", ":", "router", "=", "self", ".", "connection_pool", ".", "cluster", ".", "get_router", "(", ")", "host_id", "=", "router", ".", "get_host_for_key", "(", "key", ")", "rv", "=", "self", ".", "target", "(...
Temporarily retarget the client for one call to route specifically to the one host that the given key routes to. In that case the result on the promise is just the one host's value instead of a dictionary. .. versionadded:: 1.3
[ "Temporarily", "retarget", "the", "client", "for", "one", "call", "to", "route", "specifically", "to", "the", "one", "host", "that", "the", "given", "key", "routes", "to", ".", "In", "that", "case", "the", "result", "on", "the", "promise", "is", "just", ...
569d1d13311f6c04bae537fc17e75da430e4ec45
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/clients.py#L456-L468
train
Temporarily retarget the client for one call to route specifically to the one host that the given key routes to.
getsentry/rb
rb/clients.py
RoutingClient.get_mapping_client
def get_mapping_client(self, max_concurrency=64, auto_batch=None): """Returns a thread unsafe mapping client. This client works similar to a redis pipeline and returns eventual result objects. It needs to be joined on to work properly. Instead of using this directly you shold use the :...
python
def get_mapping_client(self, max_concurrency=64, auto_batch=None): """Returns a thread unsafe mapping client. This client works similar to a redis pipeline and returns eventual result objects. It needs to be joined on to work properly. Instead of using this directly you shold use the :...
[ "def", "get_mapping_client", "(", "self", ",", "max_concurrency", "=", "64", ",", "auto_batch", "=", "None", ")", ":", "if", "auto_batch", "is", "None", ":", "auto_batch", "=", "self", ".", "auto_batch", "return", "MappingClient", "(", "connection_pool", "=", ...
Returns a thread unsafe mapping client. This client works similar to a redis pipeline and returns eventual result objects. It needs to be joined on to work properly. Instead of using this directly you shold use the :meth:`map` context manager which automatically joins. Returns...
[ "Returns", "a", "thread", "unsafe", "mapping", "client", ".", "This", "client", "works", "similar", "to", "a", "redis", "pipeline", "and", "returns", "eventual", "result", "objects", ".", "It", "needs", "to", "be", "joined", "on", "to", "work", "properly", ...
569d1d13311f6c04bae537fc17e75da430e4ec45
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/clients.py#L522-L535
train
Returns a thread unsafe mapping client.
getsentry/rb
rb/clients.py
RoutingClient.get_fanout_client
def get_fanout_client(self, hosts, max_concurrency=64, auto_batch=None): """Returns a thread unsafe fanout client. Returns an instance of :class:`FanoutClient`. """ if auto_batch is None: auto_batch = self.auto_batch return FanoutClient(host...
python
def get_fanout_client(self, hosts, max_concurrency=64, auto_batch=None): """Returns a thread unsafe fanout client. Returns an instance of :class:`FanoutClient`. """ if auto_batch is None: auto_batch = self.auto_batch return FanoutClient(host...
[ "def", "get_fanout_client", "(", "self", ",", "hosts", ",", "max_concurrency", "=", "64", ",", "auto_batch", "=", "None", ")", ":", "if", "auto_batch", "is", "None", ":", "auto_batch", "=", "self", ".", "auto_batch", "return", "FanoutClient", "(", "hosts", ...
Returns a thread unsafe fanout client. Returns an instance of :class:`FanoutClient`.
[ "Returns", "a", "thread", "unsafe", "fanout", "client", "." ]
569d1d13311f6c04bae537fc17e75da430e4ec45
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/clients.py#L537-L547
train
Returns an instance of thread unsafe fanout client.
getsentry/rb
rb/clients.py
RoutingClient.map
def map(self, timeout=None, max_concurrency=64, auto_batch=None): """Returns a context manager for a map operation. This runs multiple queries in parallel and then joins in the end to collect all results. In the context manager the client available is a :class:`MappingClient`. ...
python
def map(self, timeout=None, max_concurrency=64, auto_batch=None): """Returns a context manager for a map operation. This runs multiple queries in parallel and then joins in the end to collect all results. In the context manager the client available is a :class:`MappingClient`. ...
[ "def", "map", "(", "self", ",", "timeout", "=", "None", ",", "max_concurrency", "=", "64", ",", "auto_batch", "=", "None", ")", ":", "return", "MapManager", "(", "self", ".", "get_mapping_client", "(", "max_concurrency", ",", "auto_batch", ")", ",", "timeo...
Returns a context manager for a map operation. This runs multiple queries in parallel and then joins in the end to collect all results. In the context manager the client available is a :class:`MappingClient`. Example usage:: results = {} with cluster.map() as ...
[ "Returns", "a", "context", "manager", "for", "a", "map", "operation", ".", "This", "runs", "multiple", "queries", "in", "parallel", "and", "then", "joins", "in", "the", "end", "to", "collect", "all", "results", "." ]
569d1d13311f6c04bae537fc17e75da430e4ec45
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/clients.py#L549-L565
train
Returns a context manager that runs a map operation.
getsentry/rb
rb/clients.py
RoutingClient.fanout
def fanout(self, hosts=None, timeout=None, max_concurrency=64, auto_batch=None): """Returns a context manager for a map operation that fans out to manually specified hosts instead of using the routing system. This can for instance be used to empty the database on all hosts. The ...
python
def fanout(self, hosts=None, timeout=None, max_concurrency=64, auto_batch=None): """Returns a context manager for a map operation that fans out to manually specified hosts instead of using the routing system. This can for instance be used to empty the database on all hosts. The ...
[ "def", "fanout", "(", "self", ",", "hosts", "=", "None", ",", "timeout", "=", "None", ",", "max_concurrency", "=", "64", ",", "auto_batch", "=", "None", ")", ":", "return", "MapManager", "(", "self", ".", "get_fanout_client", "(", "hosts", ",", "max_conc...
Returns a context manager for a map operation that fans out to manually specified hosts instead of using the routing system. This can for instance be used to empty the database on all hosts. The context manager returns a :class:`FanoutClient`. Example usage:: with cluster.fanout(...
[ "Returns", "a", "context", "manager", "for", "a", "map", "operation", "that", "fans", "out", "to", "manually", "specified", "hosts", "instead", "of", "using", "the", "routing", "system", ".", "This", "can", "for", "instance", "be", "used", "to", "empty", "...
569d1d13311f6c04bae537fc17e75da430e4ec45
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/clients.py#L567-L591
train
Returns a context manager that fans out to the specified hosts.
getsentry/rb
rb/promise.py
Promise.resolved
def resolved(value): """Creates a promise object resolved with a certain value.""" p = Promise() p._state = 'resolved' p.value = value return p
python
def resolved(value): """Creates a promise object resolved with a certain value.""" p = Promise() p._state = 'resolved' p.value = value return p
[ "def", "resolved", "(", "value", ")", ":", "p", "=", "Promise", "(", ")", "p", ".", "_state", "=", "'resolved'", "p", ".", "value", "=", "value", "return", "p" ]
Creates a promise object resolved with a certain value.
[ "Creates", "a", "promise", "object", "resolved", "with", "a", "certain", "value", "." ]
569d1d13311f6c04bae537fc17e75da430e4ec45
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/promise.py#L22-L27
train
Creates a promise object resolved with a certain value.
getsentry/rb
rb/promise.py
Promise.rejected
def rejected(reason): """Creates a promise object rejected with a certain value.""" p = Promise() p._state = 'rejected' p.reason = reason return p
python
def rejected(reason): """Creates a promise object rejected with a certain value.""" p = Promise() p._state = 'rejected' p.reason = reason return p
[ "def", "rejected", "(", "reason", ")", ":", "p", "=", "Promise", "(", ")", "p", ".", "_state", "=", "'rejected'", "p", ".", "reason", "=", "reason", "return", "p" ]
Creates a promise object rejected with a certain value.
[ "Creates", "a", "promise", "object", "rejected", "with", "a", "certain", "value", "." ]
569d1d13311f6c04bae537fc17e75da430e4ec45
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/promise.py#L30-L35
train
Creates a promise object rejected with a certain value.
getsentry/rb
rb/promise.py
Promise.resolve
def resolve(self, value): """Resolves the promise with the given value.""" if self is value: raise TypeError('Cannot resolve promise with itself.') if isinstance(value, Promise): value.done(self.resolve, self.reject) return if self._state != 'pending...
python
def resolve(self, value): """Resolves the promise with the given value.""" if self is value: raise TypeError('Cannot resolve promise with itself.') if isinstance(value, Promise): value.done(self.resolve, self.reject) return if self._state != 'pending...
[ "def", "resolve", "(", "self", ",", "value", ")", ":", "if", "self", "is", "value", ":", "raise", "TypeError", "(", "'Cannot resolve promise with itself.'", ")", "if", "isinstance", "(", "value", ",", "Promise", ")", ":", "value", ".", "done", "(", "self",...
Resolves the promise with the given value.
[ "Resolves", "the", "promise", "with", "the", "given", "value", "." ]
569d1d13311f6c04bae537fc17e75da430e4ec45
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/promise.py#L46-L63
train
Resolves the promise with the given value.
getsentry/rb
rb/promise.py
Promise.reject
def reject(self, reason): """Rejects the promise with the given reason.""" if self._state != 'pending': raise RuntimeError('Promise is no longer pending.') self.reason = reason self._state = 'rejected' errbacks = self._errbacks self._errbacks = None f...
python
def reject(self, reason): """Rejects the promise with the given reason.""" if self._state != 'pending': raise RuntimeError('Promise is no longer pending.') self.reason = reason self._state = 'rejected' errbacks = self._errbacks self._errbacks = None f...
[ "def", "reject", "(", "self", ",", "reason", ")", ":", "if", "self", ".", "_state", "!=", "'pending'", ":", "raise", "RuntimeError", "(", "'Promise is no longer pending.'", ")", "self", ".", "reason", "=", "reason", "self", ".", "_state", "=", "'rejected'", ...
Rejects the promise with the given reason.
[ "Rejects", "the", "promise", "with", "the", "given", "reason", "." ]
569d1d13311f6c04bae537fc17e75da430e4ec45
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/promise.py#L65-L75
train
Rejects the promise with the given reason.
getsentry/rb
rb/promise.py
Promise.done
def done(self, on_success=None, on_failure=None): """Attaches some callbacks to the promise and returns the promise.""" if on_success is not None: if self._state == 'pending': self._callbacks.append(on_success) elif self._state == 'resolved': on_su...
python
def done(self, on_success=None, on_failure=None): """Attaches some callbacks to the promise and returns the promise.""" if on_success is not None: if self._state == 'pending': self._callbacks.append(on_success) elif self._state == 'resolved': on_su...
[ "def", "done", "(", "self", ",", "on_success", "=", "None", ",", "on_failure", "=", "None", ")", ":", "if", "on_success", "is", "not", "None", ":", "if", "self", ".", "_state", "==", "'pending'", ":", "self", ".", "_callbacks", ".", "append", "(", "o...
Attaches some callbacks to the promise and returns the promise.
[ "Attaches", "some", "callbacks", "to", "the", "promise", "and", "returns", "the", "promise", "." ]
569d1d13311f6c04bae537fc17e75da430e4ec45
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/promise.py#L92-L104
train
Attaches some callbacks to the promise and returns the promise.
getsentry/rb
rb/promise.py
Promise.then
def then(self, success=None, failure=None): """A utility method to add success and/or failure callback to the promise which will also return another promise in the process. """ rv = Promise() def on_success(v): try: rv.resolve(success(v)) ...
python
def then(self, success=None, failure=None): """A utility method to add success and/or failure callback to the promise which will also return another promise in the process. """ rv = Promise() def on_success(v): try: rv.resolve(success(v)) ...
[ "def", "then", "(", "self", ",", "success", "=", "None", ",", "failure", "=", "None", ")", ":", "rv", "=", "Promise", "(", ")", "def", "on_success", "(", "v", ")", ":", "try", ":", "rv", ".", "resolve", "(", "success", "(", "v", ")", ")", "exce...
A utility method to add success and/or failure callback to the promise which will also return another promise in the process.
[ "A", "utility", "method", "to", "add", "success", "and", "/", "or", "failure", "callback", "to", "the", "promise", "which", "will", "also", "return", "another", "promise", "in", "the", "process", "." ]
569d1d13311f6c04bae537fc17e75da430e4ec45
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/promise.py#L106-L125
train
A utility method to add success and failure callbacks to the promise which will also return another promise in the process.
getsentry/rb
rb/router.py
BaseRouter.get_key
def get_key(self, command, args): """Returns the key a command operates on.""" spec = COMMANDS.get(command.upper()) if spec is None: raise UnroutableCommand('The command "%r" is unknown to the ' 'router and cannot be handled as a ' ...
python
def get_key(self, command, args): """Returns the key a command operates on.""" spec = COMMANDS.get(command.upper()) if spec is None: raise UnroutableCommand('The command "%r" is unknown to the ' 'router and cannot be handled as a ' ...
[ "def", "get_key", "(", "self", ",", "command", ",", "args", ")", ":", "spec", "=", "COMMANDS", ".", "get", "(", "command", ".", "upper", "(", ")", ")", "if", "spec", "is", "None", ":", "raise", "UnroutableCommand", "(", "'The command \"%r\" is unknown to t...
Returns the key a command operates on.
[ "Returns", "the", "key", "a", "command", "operates", "on", "." ]
569d1d13311f6c04bae537fc17e75da430e4ec45
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/router.py#L60-L85
train
Returns the key a command operates on.
getsentry/rb
rb/router.py
BaseRouter.get_host_for_command
def get_host_for_command(self, command, args): """Returns the host this command should be executed against.""" return self.get_host_for_key(self.get_key(command, args))
python
def get_host_for_command(self, command, args): """Returns the host this command should be executed against.""" return self.get_host_for_key(self.get_key(command, args))
[ "def", "get_host_for_command", "(", "self", ",", "command", ",", "args", ")", ":", "return", "self", ".", "get_host_for_key", "(", "self", ".", "get_key", "(", "command", ",", "args", ")", ")" ]
Returns the host this command should be executed against.
[ "Returns", "the", "host", "this", "command", "should", "be", "executed", "against", "." ]
569d1d13311f6c04bae537fc17e75da430e4ec45
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/router.py#L87-L89
train
Returns the host this command should be executed against.
getsentry/rb
rb/ketama.py
Ketama._rebuild_circle
def _rebuild_circle(self): """Updates the hash ring.""" self._hashring = {} self._sorted_keys = [] total_weight = 0 for node in self._nodes: total_weight += self._weights.get(node, 1) for node in self._nodes: weight = self._weights.get(node, 1) ...
python
def _rebuild_circle(self): """Updates the hash ring.""" self._hashring = {} self._sorted_keys = [] total_weight = 0 for node in self._nodes: total_weight += self._weights.get(node, 1) for node in self._nodes: weight = self._weights.get(node, 1) ...
[ "def", "_rebuild_circle", "(", "self", ")", ":", "self", ".", "_hashring", "=", "{", "}", "self", ".", "_sorted_keys", "=", "[", "]", "total_weight", "=", "0", "for", "node", "in", "self", ".", "_nodes", ":", "total_weight", "+=", "self", ".", "_weight...
Updates the hash ring.
[ "Updates", "the", "hash", "ring", "." ]
569d1d13311f6c04bae537fc17e75da430e4ec45
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/ketama.py#L21-L43
train
Updates the hash ring with the new ones.
getsentry/rb
rb/ketama.py
Ketama._get_node_pos
def _get_node_pos(self, key): """Return node position(integer) for a given key or None.""" if not self._hashring: return k = md5_bytes(key) key = (k[3] << 24) | (k[2] << 16) | (k[1] << 8) | k[0] nodes = self._sorted_keys pos = bisect(nodes, key) if ...
python
def _get_node_pos(self, key): """Return node position(integer) for a given key or None.""" if not self._hashring: return k = md5_bytes(key) key = (k[3] << 24) | (k[2] << 16) | (k[1] << 8) | k[0] nodes = self._sorted_keys pos = bisect(nodes, key) if ...
[ "def", "_get_node_pos", "(", "self", ",", "key", ")", ":", "if", "not", "self", ".", "_hashring", ":", "return", "k", "=", "md5_bytes", "(", "key", ")", "key", "=", "(", "k", "[", "3", "]", "<<", "24", ")", "|", "(", "k", "[", "2", "]", "<<",...
Return node position(integer) for a given key or None.
[ "Return", "node", "position", "(", "integer", ")", "for", "a", "given", "key", "or", "None", "." ]
569d1d13311f6c04bae537fc17e75da430e4ec45
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/ketama.py#L45-L58
train
Return the node position for a given key or None.
getsentry/rb
rb/ketama.py
Ketama.remove_node
def remove_node(self, node): """Removes node from circle and rebuild it.""" try: self._nodes.remove(node) del self._weights[node] except (KeyError, ValueError): pass self._rebuild_circle()
python
def remove_node(self, node): """Removes node from circle and rebuild it.""" try: self._nodes.remove(node) del self._weights[node] except (KeyError, ValueError): pass self._rebuild_circle()
[ "def", "remove_node", "(", "self", ",", "node", ")", ":", "try", ":", "self", ".", "_nodes", ".", "remove", "(", "node", ")", "del", "self", ".", "_weights", "[", "node", "]", "except", "(", "KeyError", ",", "ValueError", ")", ":", "pass", "self", ...
Removes node from circle and rebuild it.
[ "Removes", "node", "from", "circle", "and", "rebuild", "it", "." ]
569d1d13311f6c04bae537fc17e75da430e4ec45
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/ketama.py#L60-L67
train
Removes node from circle and rebuild it.
getsentry/rb
rb/ketama.py
Ketama.add_node
def add_node(self, node, weight=1): """Adds node to circle and rebuild it.""" self._nodes.add(node) self._weights[node] = weight self._rebuild_circle()
python
def add_node(self, node, weight=1): """Adds node to circle and rebuild it.""" self._nodes.add(node) self._weights[node] = weight self._rebuild_circle()
[ "def", "add_node", "(", "self", ",", "node", ",", "weight", "=", "1", ")", ":", "self", ".", "_nodes", ".", "add", "(", "node", ")", "self", ".", "_weights", "[", "node", "]", "=", "weight", "self", ".", "_rebuild_circle", "(", ")" ]
Adds node to circle and rebuild it.
[ "Adds", "node", "to", "circle", "and", "rebuild", "it", "." ]
569d1d13311f6c04bae537fc17e75da430e4ec45
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/ketama.py#L69-L73
train
Adds a node to the circle and rebuilds it.
getsentry/rb
rb/ketama.py
Ketama.get_node
def get_node(self, key): """Return node for a given key. Else return None.""" pos = self._get_node_pos(key) if pos is None: return None return self._hashring[self._sorted_keys[pos]]
python
def get_node(self, key): """Return node for a given key. Else return None.""" pos = self._get_node_pos(key) if pos is None: return None return self._hashring[self._sorted_keys[pos]]
[ "def", "get_node", "(", "self", ",", "key", ")", ":", "pos", "=", "self", ".", "_get_node_pos", "(", "key", ")", "if", "pos", "is", "None", ":", "return", "None", "return", "self", ".", "_hashring", "[", "self", ".", "_sorted_keys", "[", "pos", "]", ...
Return node for a given key. Else return None.
[ "Return", "node", "for", "a", "given", "key", ".", "Else", "return", "None", "." ]
569d1d13311f6c04bae537fc17e75da430e4ec45
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/ketama.py#L75-L80
train
Return node for a given key. If no node exists return None.
hobu/mgrs
mgrs/core.py
check_error
def check_error(result, func, cargs): "Error checking proper value returns" if result != 0: msg = 'Error in "%s": %s' % (func.__name__, get_errors(result) ) raise RTreeError(msg) return
python
def check_error(result, func, cargs): "Error checking proper value returns" if result != 0: msg = 'Error in "%s": %s' % (func.__name__, get_errors(result) ) raise RTreeError(msg) return
[ "def", "check_error", "(", "result", ",", "func", ",", "cargs", ")", ":", "if", "result", "!=", "0", ":", "msg", "=", "'Error in \"%s\": %s'", "%", "(", "func", ".", "__name__", ",", "get_errors", "(", "result", ")", ")", "raise", "RTreeError", "(", "m...
Error checking proper value returns
[ "Error", "checking", "proper", "value", "returns" ]
759b3aba86779318854c73b8843ea956acb5eb3f
https://github.com/hobu/mgrs/blob/759b3aba86779318854c73b8843ea956acb5eb3f/mgrs/core.py#L77-L82
train
Error checking proper value returns
hobu/mgrs
mgrs/__init__.py
MGRS.ddtodms
def ddtodms(self, dd): """Take in dd string and convert to dms""" negative = dd < 0 dd = abs(dd) minutes,seconds = divmod(dd*3600,60) degrees,minutes = divmod(minutes,60) if negative: if degrees > 0: degrees = -degrees elif minutes ...
python
def ddtodms(self, dd): """Take in dd string and convert to dms""" negative = dd < 0 dd = abs(dd) minutes,seconds = divmod(dd*3600,60) degrees,minutes = divmod(minutes,60) if negative: if degrees > 0: degrees = -degrees elif minutes ...
[ "def", "ddtodms", "(", "self", ",", "dd", ")", ":", "negative", "=", "dd", "<", "0", "dd", "=", "abs", "(", "dd", ")", "minutes", ",", "seconds", "=", "divmod", "(", "dd", "*", "3600", ",", "60", ")", "degrees", ",", "minutes", "=", "divmod", "...
Take in dd string and convert to dms
[ "Take", "in", "dd", "string", "and", "convert", "to", "dms" ]
759b3aba86779318854c73b8843ea956acb5eb3f
https://github.com/hobu/mgrs/blob/759b3aba86779318854c73b8843ea956acb5eb3f/mgrs/__init__.py#L13-L26
train
Take in dd string and convert to dms
hobu/mgrs
mgrs/__init__.py
MGRS.dmstodd
def dmstodd(self, dms): """ convert dms to dd""" size = len(dms) letters = 'WENS' is_annotated = False try: float(dms) except ValueError: for letter in letters: if letter in dms.upper(): is_annotated = True ...
python
def dmstodd(self, dms): """ convert dms to dd""" size = len(dms) letters = 'WENS' is_annotated = False try: float(dms) except ValueError: for letter in letters: if letter in dms.upper(): is_annotated = True ...
[ "def", "dmstodd", "(", "self", ",", "dms", ")", ":", "size", "=", "len", "(", "dms", ")", "letters", "=", "'WENS'", "is_annotated", "=", "False", "try", ":", "float", "(", "dms", ")", "except", "ValueError", ":", "for", "letter", "in", "letters", ":"...
convert dms to dd
[ "convert", "dms", "to", "dd" ]
759b3aba86779318854c73b8843ea956acb5eb3f
https://github.com/hobu/mgrs/blob/759b3aba86779318854c73b8843ea956acb5eb3f/mgrs/__init__.py#L28-L80
train
converts a string to dd
pydot/pydot-ng
pydot_ng/__init__.py
get_fobj
def get_fobj(fname, mode='w+'): """Obtain a proper file object. Parameters ---------- fname : string, file object, file descriptor If a string or file descriptor, then we create a file object. If *fname* is a file object, then we do nothing and ignore the specified *mode* parame...
python
def get_fobj(fname, mode='w+'): """Obtain a proper file object. Parameters ---------- fname : string, file object, file descriptor If a string or file descriptor, then we create a file object. If *fname* is a file object, then we do nothing and ignore the specified *mode* parame...
[ "def", "get_fobj", "(", "fname", ",", "mode", "=", "'w+'", ")", ":", "if", "is_string_like", "(", "fname", ")", ":", "fobj", "=", "open", "(", "fname", ",", "mode", ")", "close", "=", "True", "elif", "hasattr", "(", "fname", ",", "'write'", ")", ":...
Obtain a proper file object. Parameters ---------- fname : string, file object, file descriptor If a string or file descriptor, then we create a file object. If *fname* is a file object, then we do nothing and ignore the specified *mode* parameter. mode : str The mode of...
[ "Obtain", "a", "proper", "file", "object", "." ]
16f39800b6f5dc28d291a4d7763bbac04b9efe72
https://github.com/pydot/pydot-ng/blob/16f39800b6f5dc28d291a4d7763bbac04b9efe72/pydot_ng/__init__.py#L111-L146
train
Obtain a proper file object.
pydot/pydot-ng
pydot_ng/__init__.py
graph_from_dot_file
def graph_from_dot_file(path): """Load graph as defined by a DOT file. The file is assumed to be in DOT format. It will be loaded, parsed and a Dot class will be returned, representing the graph. """ fd = open(path, 'rb') data = fd.read() fd.close() return graph_from_dot_data(data...
python
def graph_from_dot_file(path): """Load graph as defined by a DOT file. The file is assumed to be in DOT format. It will be loaded, parsed and a Dot class will be returned, representing the graph. """ fd = open(path, 'rb') data = fd.read() fd.close() return graph_from_dot_data(data...
[ "def", "graph_from_dot_file", "(", "path", ")", ":", "fd", "=", "open", "(", "path", ",", "'rb'", ")", "data", "=", "fd", ".", "read", "(", ")", "fd", ".", "close", "(", ")", "return", "graph_from_dot_data", "(", "data", ")" ]
Load graph as defined by a DOT file. The file is assumed to be in DOT format. It will be loaded, parsed and a Dot class will be returned, representing the graph.
[ "Load", "graph", "as", "defined", "by", "a", "DOT", "file", "." ]
16f39800b6f5dc28d291a4d7763bbac04b9efe72
https://github.com/pydot/pydot-ng/blob/16f39800b6f5dc28d291a4d7763bbac04b9efe72/pydot_ng/__init__.py#L286-L298
train
Load a graph from a DOT file.
pydot/pydot-ng
pydot_ng/__init__.py
graph_from_edges
def graph_from_edges(edge_list, node_prefix='', directed=False): """Creates a basic graph out of an edge list. The edge list has to be a list of tuples representing the nodes connected by the edge. The values can be anything: bool, int, float, str. If the graph is undirected by default, it is only...
python
def graph_from_edges(edge_list, node_prefix='', directed=False): """Creates a basic graph out of an edge list. The edge list has to be a list of tuples representing the nodes connected by the edge. The values can be anything: bool, int, float, str. If the graph is undirected by default, it is only...
[ "def", "graph_from_edges", "(", "edge_list", ",", "node_prefix", "=", "''", ",", "directed", "=", "False", ")", ":", "if", "edge_list", "is", "None", ":", "edge_list", "=", "[", "]", "graph_type", "=", "\"digraph\"", "if", "directed", "else", "\"graph\"", ...
Creates a basic graph out of an edge list. The edge list has to be a list of tuples representing the nodes connected by the edge. The values can be anything: bool, int, float, str. If the graph is undirected by default, it is only calculated from one of the symmetric halves of the matrix.
[ "Creates", "a", "basic", "graph", "out", "of", "an", "edge", "list", "." ]
16f39800b6f5dc28d291a4d7763bbac04b9efe72
https://github.com/pydot/pydot-ng/blob/16f39800b6f5dc28d291a4d7763bbac04b9efe72/pydot_ng/__init__.py#L301-L325
train
Creates a basic graph out of an edge list.
pydot/pydot-ng
pydot_ng/__init__.py
graph_from_adjacency_matrix
def graph_from_adjacency_matrix(matrix, node_prefix='', directed=False): """Creates a basic graph out of an adjacency matrix. The matrix has to be a list of rows of values representing an adjacency matrix. The values can be anything: bool, int, float, as long as they can evaluate to True or False. ...
python
def graph_from_adjacency_matrix(matrix, node_prefix='', directed=False): """Creates a basic graph out of an adjacency matrix. The matrix has to be a list of rows of values representing an adjacency matrix. The values can be anything: bool, int, float, as long as they can evaluate to True or False. ...
[ "def", "graph_from_adjacency_matrix", "(", "matrix", ",", "node_prefix", "=", "''", ",", "directed", "=", "False", ")", ":", "node_orig", "=", "1", "if", "directed", ":", "graph", "=", "Dot", "(", "graph_type", "=", "'digraph'", ")", "else", ":", "graph", ...
Creates a basic graph out of an adjacency matrix. The matrix has to be a list of rows of values representing an adjacency matrix. The values can be anything: bool, int, float, as long as they can evaluate to True or False.
[ "Creates", "a", "basic", "graph", "out", "of", "an", "adjacency", "matrix", "." ]
16f39800b6f5dc28d291a4d7763bbac04b9efe72
https://github.com/pydot/pydot-ng/blob/16f39800b6f5dc28d291a4d7763bbac04b9efe72/pydot_ng/__init__.py#L328-L362
train
Creates a basic graph out of an adjacency matrix.
pydot/pydot-ng
pydot_ng/__init__.py
graph_from_incidence_matrix
def graph_from_incidence_matrix(matrix, node_prefix='', directed=False): """Creates a basic graph out of an incidence matrix. The matrix has to be a list of rows of values representing an incidence matrix. The values can be anything: bool, int, float, as long as they can evaluate to True or False. ...
python
def graph_from_incidence_matrix(matrix, node_prefix='', directed=False): """Creates a basic graph out of an incidence matrix. The matrix has to be a list of rows of values representing an incidence matrix. The values can be anything: bool, int, float, as long as they can evaluate to True or False. ...
[ "def", "graph_from_incidence_matrix", "(", "matrix", ",", "node_prefix", "=", "''", ",", "directed", "=", "False", ")", ":", "if", "directed", ":", "graph", "=", "Dot", "(", "graph_type", "=", "'digraph'", ")", "else", ":", "graph", "=", "Dot", "(", "gra...
Creates a basic graph out of an incidence matrix. The matrix has to be a list of rows of values representing an incidence matrix. The values can be anything: bool, int, float, as long as they can evaluate to True or False.
[ "Creates", "a", "basic", "graph", "out", "of", "an", "incidence", "matrix", "." ]
16f39800b6f5dc28d291a4d7763bbac04b9efe72
https://github.com/pydot/pydot-ng/blob/16f39800b6f5dc28d291a4d7763bbac04b9efe72/pydot_ng/__init__.py#L365-L399
train
Creates a basic graph out of an incidence matrix.
pydot/pydot-ng
pydot_ng/__init__.py
__find_executables
def __find_executables(path): """Used by find_graphviz path - single directory as a string If any of the executables are found, it will return a dictionary containing the program names as keys and their paths as values. Otherwise returns None """ success = False progs = { "do...
python
def __find_executables(path): """Used by find_graphviz path - single directory as a string If any of the executables are found, it will return a dictionary containing the program names as keys and their paths as values. Otherwise returns None """ success = False progs = { "do...
[ "def", "__find_executables", "(", "path", ")", ":", "success", "=", "False", "progs", "=", "{", "\"dot\"", ":", "\"\"", ",", "\"twopi\"", ":", "\"\"", ",", "\"neato\"", ":", "\"\"", ",", "\"circo\"", ":", "\"\"", ",", "\"fdp\"", ":", "\"\"", ",", "\"sf...
Used by find_graphviz path - single directory as a string If any of the executables are found, it will return a dictionary containing the program names as keys and their paths as values. Otherwise returns None
[ "Used", "by", "find_graphviz" ]
16f39800b6f5dc28d291a4d7763bbac04b9efe72
https://github.com/pydot/pydot-ng/blob/16f39800b6f5dc28d291a4d7763bbac04b9efe72/pydot_ng/__init__.py#L402-L454
train
Used by find_graphviz path - single directory as a string
pydot/pydot-ng
pydot_ng/__init__.py
find_graphviz
def find_graphviz(): """Locate Graphviz's executables in the system. Tries three methods: First: Windows Registry (Windows only) This requires Mark Hammond's pywin32 is installed. Secondly: Search the path It will look for 'dot', 'twopi' and 'neato' in all the directories specified in the...
python
def find_graphviz(): """Locate Graphviz's executables in the system. Tries three methods: First: Windows Registry (Windows only) This requires Mark Hammond's pywin32 is installed. Secondly: Search the path It will look for 'dot', 'twopi' and 'neato' in all the directories specified in the...
[ "def", "find_graphviz", "(", ")", ":", "# Method 1 (Windows only)", "if", "os", ".", "sys", ".", "platform", "==", "'win32'", ":", "HKEY_LOCAL_MACHINE", "=", "0x80000002", "KEY_QUERY_VALUE", "=", "0x0001", "RegOpenKeyEx", "=", "None", "RegQueryValueEx", "=", "None...
Locate Graphviz's executables in the system. Tries three methods: First: Windows Registry (Windows only) This requires Mark Hammond's pywin32 is installed. Secondly: Search the path It will look for 'dot', 'twopi' and 'neato' in all the directories specified in the PATH environment variable. ...
[ "Locate", "Graphviz", "s", "executables", "in", "the", "system", "." ]
16f39800b6f5dc28d291a4d7763bbac04b9efe72
https://github.com/pydot/pydot-ng/blob/16f39800b6f5dc28d291a4d7763bbac04b9efe72/pydot_ng/__init__.py#L459-L599
train
Locate the Graphviz executables in the system.
pydot/pydot-ng
pydot_ng/__init__.py
Graph.get_node_list
def get_node_list(self): """Get the list of Node instances. This method returns the list of Node instances composing the graph. """ node_objs = list() for obj_dict_list in self.obj_dict['nodes'].values(): node_objs.extend([ Node(obj_dict=obj_...
python
def get_node_list(self): """Get the list of Node instances. This method returns the list of Node instances composing the graph. """ node_objs = list() for obj_dict_list in self.obj_dict['nodes'].values(): node_objs.extend([ Node(obj_dict=obj_...
[ "def", "get_node_list", "(", "self", ")", ":", "node_objs", "=", "list", "(", ")", "for", "obj_dict_list", "in", "self", ".", "obj_dict", "[", "'nodes'", "]", ".", "values", "(", ")", ":", "node_objs", ".", "extend", "(", "[", "Node", "(", "obj_dict", ...
Get the list of Node instances. This method returns the list of Node instances composing the graph.
[ "Get", "the", "list", "of", "Node", "instances", "." ]
16f39800b6f5dc28d291a4d7763bbac04b9efe72
https://github.com/pydot/pydot-ng/blob/16f39800b6f5dc28d291a4d7763bbac04b9efe72/pydot_ng/__init__.py#L1250-L1264
train
Get the list of Node instances. This method returns the list of Node instances.
pydot/pydot-ng
pydot_ng/__init__.py
Graph.del_edge
def del_edge(self, src_or_list, dst=None, index=None): """Delete an edge from the graph. Given an edge's (source, destination) node names all matching edges(s) will be deleted if 'index' is not specified or set to None. If there are several matching edges and 'index' is ...
python
def del_edge(self, src_or_list, dst=None, index=None): """Delete an edge from the graph. Given an edge's (source, destination) node names all matching edges(s) will be deleted if 'index' is not specified or set to None. If there are several matching edges and 'index' is ...
[ "def", "del_edge", "(", "self", ",", "src_or_list", ",", "dst", "=", "None", ",", "index", "=", "None", ")", ":", "if", "isinstance", "(", "src_or_list", ",", "(", "list", ",", "tuple", ")", ")", ":", "if", "dst", "is", "not", "None", "and", "isins...
Delete an edge from the graph. Given an edge's (source, destination) node names all matching edges(s) will be deleted if 'index' is not specified or set to None. If there are several matching edges and 'index' is given, only the edge in that position will be deleted. 'i...
[ "Delete", "an", "edge", "from", "the", "graph", "." ]
16f39800b6f5dc28d291a4d7763bbac04b9efe72
https://github.com/pydot/pydot-ng/blob/16f39800b6f5dc28d291a4d7763bbac04b9efe72/pydot_ng/__init__.py#L1287-L1326
train
Delete an edge from the graph.
pydot/pydot-ng
pydot_ng/__init__.py
Graph.get_edge_list
def get_edge_list(self): """Get the list of Edge instances. This method returns the list of Edge instances composing the graph. """ edge_objs = list() for obj_dict_list in self.obj_dict['edges'].values(): edge_objs.extend([ Edge(obj_dict=obj_...
python
def get_edge_list(self): """Get the list of Edge instances. This method returns the list of Edge instances composing the graph. """ edge_objs = list() for obj_dict_list in self.obj_dict['edges'].values(): edge_objs.extend([ Edge(obj_dict=obj_...
[ "def", "get_edge_list", "(", "self", ")", ":", "edge_objs", "=", "list", "(", ")", "for", "obj_dict_list", "in", "self", ".", "obj_dict", "[", "'edges'", "]", ".", "values", "(", ")", ":", "edge_objs", ".", "extend", "(", "[", "Edge", "(", "obj_dict", ...
Get the list of Edge instances. This method returns the list of Edge instances composing the graph.
[ "Get", "the", "list", "of", "Edge", "instances", "." ]
16f39800b6f5dc28d291a4d7763bbac04b9efe72
https://github.com/pydot/pydot-ng/blob/16f39800b6f5dc28d291a4d7763bbac04b9efe72/pydot_ng/__init__.py#L1366-L1380
train
Get the list of Edge instances. This method returns the list of Edge instances.
pydot/pydot-ng
pydot_ng/__init__.py
Graph.to_string
def to_string(self): """Returns a string representation of the graph in dot language. It will return the graph and all its subelements in string from. """ graph = list() if self.obj_dict.get('strict', None) is not None: if self == self.get_parent_graph() and self.o...
python
def to_string(self): """Returns a string representation of the graph in dot language. It will return the graph and all its subelements in string from. """ graph = list() if self.obj_dict.get('strict', None) is not None: if self == self.get_parent_graph() and self.o...
[ "def", "to_string", "(", "self", ")", ":", "graph", "=", "list", "(", ")", "if", "self", ".", "obj_dict", ".", "get", "(", "'strict'", ",", "None", ")", "is", "not", "None", ":", "if", "self", "==", "self", ".", "get_parent_graph", "(", ")", "and",...
Returns a string representation of the graph in dot language. It will return the graph and all its subelements in string from.
[ "Returns", "a", "string", "representation", "of", "the", "graph", "in", "dot", "language", "." ]
16f39800b6f5dc28d291a4d7763bbac04b9efe72
https://github.com/pydot/pydot-ng/blob/16f39800b6f5dc28d291a4d7763bbac04b9efe72/pydot_ng/__init__.py#L1463-L1545
train
Returns a string representation of the object in dot language.
pydot/pydot-ng
pydot_ng/__init__.py
Dot.write
def write(self, path, prog=None, format='raw'): """Write graph to file in selected format. Given a filename 'path' it will open/create and truncate such file and write on it a representation of the graph defined by the dot object and in the format specified by 'format'. 'path' c...
python
def write(self, path, prog=None, format='raw'): """Write graph to file in selected format. Given a filename 'path' it will open/create and truncate such file and write on it a representation of the graph defined by the dot object and in the format specified by 'format'. 'path' c...
[ "def", "write", "(", "self", ",", "path", ",", "prog", "=", "None", ",", "format", "=", "'raw'", ")", ":", "if", "prog", "is", "None", ":", "prog", "=", "self", ".", "prog", "fobj", ",", "close", "=", "get_fobj", "(", "path", ",", "'w+b'", ")", ...
Write graph to file in selected format. Given a filename 'path' it will open/create and truncate such file and write on it a representation of the graph defined by the dot object and in the format specified by 'format'. 'path' can also be an open file-like object, such as a Stri...
[ "Write", "graph", "to", "file", "in", "selected", "format", "." ]
16f39800b6f5dc28d291a4d7763bbac04b9efe72
https://github.com/pydot/pydot-ng/blob/16f39800b6f5dc28d291a4d7763bbac04b9efe72/pydot_ng/__init__.py#L1728-L1784
train
Write the graph to file in specified format.
pawamoy/django-suit-dashboard
src/suit_dashboard/views.py
DashboardView.get_crumbs
def get_crumbs(self): """ Get crumbs for navigation links. Returns: tuple: concatenated list of crumbs using these crumbs and the crumbs of the parent classes through ``__mro__``. """ crumbs = [] for cls in reversed(type(self)....
python
def get_crumbs(self): """ Get crumbs for navigation links. Returns: tuple: concatenated list of crumbs using these crumbs and the crumbs of the parent classes through ``__mro__``. """ crumbs = [] for cls in reversed(type(self)....
[ "def", "get_crumbs", "(", "self", ")", ":", "crumbs", "=", "[", "]", "for", "cls", "in", "reversed", "(", "type", "(", "self", ")", ".", "__mro__", "[", "1", ":", "]", ")", ":", "crumbs", ".", "extend", "(", "getattr", "(", "cls", ",", "'crumbs'"...
Get crumbs for navigation links. Returns: tuple: concatenated list of crumbs using these crumbs and the crumbs of the parent classes through ``__mro__``.
[ "Get", "crumbs", "for", "navigation", "links", "." ]
c008f55f4168f7af62ba31e8b621df214bea1e96
https://github.com/pawamoy/django-suit-dashboard/blob/c008f55f4168f7af62ba31e8b621df214bea1e96/src/suit_dashboard/views.py#L30-L43
train
Get crumbs for navigation links.
pawamoy/django-suit-dashboard
src/suit_dashboard/views.py
DashboardView.get
def get(self, request, *args, **kwargs): """ Django view get function. Add items of extra_context, crumbs and grid to context. Args: request (): Django's request object. *args (): request args. **kwargs (): request kwargs. Returns: ...
python
def get(self, request, *args, **kwargs): """ Django view get function. Add items of extra_context, crumbs and grid to context. Args: request (): Django's request object. *args (): request args. **kwargs (): request kwargs. Returns: ...
[ "def", "get", "(", "self", ",", "request", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "context", "=", "self", ".", "get_context_data", "(", "*", "*", "kwargs", ")", "context", ".", "update", "(", "self", ".", "extra_context", ")", "context"...
Django view get function. Add items of extra_context, crumbs and grid to context. Args: request (): Django's request object. *args (): request args. **kwargs (): request kwargs. Returns: response: render to response with context.
[ "Django", "view", "get", "function", "." ]
c008f55f4168f7af62ba31e8b621df214bea1e96
https://github.com/pawamoy/django-suit-dashboard/blob/c008f55f4168f7af62ba31e8b621df214bea1e96/src/suit_dashboard/views.py#L45-L66
train
This function is called by the get view function. It returns a Django response with the context data.
pawamoy/django-suit-dashboard
src/suit_dashboard/widgets.py
realtime
def realtime(widget, url_name=None, url_regex=None, time_interval=None): """ Return a widget as real-time. Args: widget (Widget): the widget to register and return as real-time. url_name (str): the URL name to call to get updated content. url_regex (regex): the URL regex to be match...
python
def realtime(widget, url_name=None, url_regex=None, time_interval=None): """ Return a widget as real-time. Args: widget (Widget): the widget to register and return as real-time. url_name (str): the URL name to call to get updated content. url_regex (regex): the URL regex to be match...
[ "def", "realtime", "(", "widget", ",", "url_name", "=", "None", ",", "url_regex", "=", "None", ",", "time_interval", "=", "None", ")", ":", "if", "not", "hasattr", "(", "widget", ",", "'get_updated_content'", ")", ":", "raise", "AttributeError", "(", "'Wid...
Return a widget as real-time. Args: widget (Widget): the widget to register and return as real-time. url_name (str): the URL name to call to get updated content. url_regex (regex): the URL regex to be matched. time_interval (int): the interval of refreshment in milliseconds. Re...
[ "Return", "a", "widget", "as", "real", "-", "time", "." ]
c008f55f4168f7af62ba31e8b621df214bea1e96
https://github.com/pawamoy/django-suit-dashboard/blob/c008f55f4168f7af62ba31e8b621df214bea1e96/src/suit_dashboard/widgets.py#L22-L97
train
Return a widget as real - time.
pawamoy/django-suit-dashboard
src/suit_dashboard/urls.py
get_realtime_urls
def get_realtime_urls(admin_view_func=lambda x: x): """ Get the URL for real-time widgets. Args: admin_view_func (callable): an admin_view method from an AdminSite instance. By default: identity. Returns: list: the list of the real-time URLs as django's ``url()``. """ ...
python
def get_realtime_urls(admin_view_func=lambda x: x): """ Get the URL for real-time widgets. Args: admin_view_func (callable): an admin_view method from an AdminSite instance. By default: identity. Returns: list: the list of the real-time URLs as django's ``url()``. """ ...
[ "def", "get_realtime_urls", "(", "admin_view_func", "=", "lambda", "x", ":", "x", ")", ":", "from", ".", "widgets", "import", "REALTIME_WIDGETS", "return", "[", "url", "(", "w", ".", "url_regex", ",", "admin_view_func", "(", "w", ".", "as_view", "(", ")", ...
Get the URL for real-time widgets. Args: admin_view_func (callable): an admin_view method from an AdminSite instance. By default: identity. Returns: list: the list of the real-time URLs as django's ``url()``.
[ "Get", "the", "URL", "for", "real", "-", "time", "widgets", "." ]
c008f55f4168f7af62ba31e8b621df214bea1e96
https://github.com/pawamoy/django-suit-dashboard/blob/c008f55f4168f7af62ba31e8b621df214bea1e96/src/suit_dashboard/urls.py#L10-L23
train
Get the URL for real - time widgets.
honeynet/beeswarm
beeswarm/server/db/database_setup.py
setup_db
def setup_db(connection_string): """ Sets up the database schema and adds defaults. :param connection_string: Database URL. e.g: sqlite:///filename.db This is usually taken from the config file. """ global DB_Session, engine new_database = False if connectio...
python
def setup_db(connection_string): """ Sets up the database schema and adds defaults. :param connection_string: Database URL. e.g: sqlite:///filename.db This is usually taken from the config file. """ global DB_Session, engine new_database = False if connectio...
[ "def", "setup_db", "(", "connection_string", ")", ":", "global", "DB_Session", ",", "engine", "new_database", "=", "False", "if", "connection_string", "==", "'sqlite://'", "or", "not", "database_exists", "(", "connection_string", ")", ":", "new_database", "=", "Tr...
Sets up the database schema and adds defaults. :param connection_string: Database URL. e.g: sqlite:///filename.db This is usually taken from the config file.
[ "Sets", "up", "the", "database", "schema", "and", "adds", "defaults", ".", ":", "param", "connection_string", ":", "Database", "URL", ".", "e", ".", "g", ":", "sqlite", ":", "///", "filename", ".", "db", "This", "is", "usually", "taken", "from", "the", ...
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/server/db/database_setup.py#L37-L85
train
Sets up the database schema and adds defaults.
honeynet/beeswarm
beeswarm/drones/honeypot/capabilities/ssh.py
SshWrapper.start_pty_request
def start_pty_request(self, channel, term, modes): """Start a PTY - intended to run it a (green)thread.""" request = self.dummy_request() request._sock = channel request.modes = modes request.term = term request.username = self.username # This should block until ...
python
def start_pty_request(self, channel, term, modes): """Start a PTY - intended to run it a (green)thread.""" request = self.dummy_request() request._sock = channel request.modes = modes request.term = term request.username = self.username # This should block until ...
[ "def", "start_pty_request", "(", "self", ",", "channel", ",", "term", ",", "modes", ")", ":", "request", "=", "self", ".", "dummy_request", "(", ")", "request", ".", "_sock", "=", "channel", "request", ".", "modes", "=", "modes", "request", ".", "term", ...
Start a PTY - intended to run it a (green)thread.
[ "Start", "a", "PTY", "-", "intended", "to", "run", "it", "a", "(", "green", ")", "thread", "." ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/honeypot/capabilities/ssh.py#L118-L130
train
Start a PTY - intended to run it a ( green ) thread.
honeynet/beeswarm
beeswarm/drones/honeypot/honeypot.py
Honeypot.check_time
def check_time(self): """ Make sure our Honeypot time is consistent, and not too far off from the actual time. """ poll = self.config['timecheck']['poll'] ntp_poll = self.config['timecheck']['ntp_pool'] while True: clnt = ntplib.NTPClient() try: ...
python
def check_time(self): """ Make sure our Honeypot time is consistent, and not too far off from the actual time. """ poll = self.config['timecheck']['poll'] ntp_poll = self.config['timecheck']['ntp_pool'] while True: clnt = ntplib.NTPClient() try: ...
[ "def", "check_time", "(", "self", ")", ":", "poll", "=", "self", ".", "config", "[", "'timecheck'", "]", "[", "'poll'", "]", "ntp_poll", "=", "self", ".", "config", "[", "'timecheck'", "]", "[", "'ntp_pool'", "]", "while", "True", ":", "clnt", "=", "...
Make sure our Honeypot time is consistent, and not too far off from the actual time.
[ "Make", "sure", "our", "Honeypot", "time", "is", "consistent", "and", "not", "too", "far", "off", "from", "the", "actual", "time", "." ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/honeypot/honeypot.py#L111-L129
train
Check if our Honeypot time is consistent and not too far off .
honeynet/beeswarm
beeswarm/drones/honeypot/honeypot.py
Honeypot.start
def start(self): """ Starts services. """ # protocol handlers for c in handlerbase.HandlerBase.__subclasses__(): cap_name = c.__name__.lower() if cap_name in self.config['capabilities']: port = self.config['capabilities'][cap_name]['port'] ...
python
def start(self): """ Starts services. """ # protocol handlers for c in handlerbase.HandlerBase.__subclasses__(): cap_name = c.__name__.lower() if cap_name in self.config['capabilities']: port = self.config['capabilities'][cap_name]['port'] ...
[ "def", "start", "(", "self", ")", ":", "# protocol handlers", "for", "c", "in", "handlerbase", ".", "HandlerBase", ".", "__subclasses__", "(", ")", ":", "cap_name", "=", "c", ".", "__name__", ".", "lower", "(", ")", "if", "cap_name", "in", "self", ".", ...
Starts services.
[ "Starts", "services", "." ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/honeypot/honeypot.py#L131-L167
train
Starts services.
honeynet/beeswarm
beeswarm/drones/honeypot/honeypot.py
Honeypot.stop
def stop(self): """Stops services""" for s in self._servers: s.stop() for g in self._server_greenlets: g.kill() logger.info('All workers stopped.')
python
def stop(self): """Stops services""" for s in self._servers: s.stop() for g in self._server_greenlets: g.kill() logger.info('All workers stopped.')
[ "def", "stop", "(", "self", ")", ":", "for", "s", "in", "self", ".", "_servers", ":", "s", ".", "stop", "(", ")", "for", "g", "in", "self", ".", "_server_greenlets", ":", "g", ".", "kill", "(", ")", "logger", ".", "info", "(", "'All workers stopped...
Stops services
[ "Stops", "services" ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/honeypot/honeypot.py#L169-L178
train
Stops all services and greenlets
honeynet/beeswarm
beeswarm/drones/honeypot/honeypot.py
Honeypot.prepare_environment
def prepare_environment(work_dir): """ Performs a few maintenance tasks before the Honeypot is run. Copies the data directory, and the config file to the cwd. The config file copied here is overwritten if the __init__ method is called with a configuration URL. :param...
python
def prepare_environment(work_dir): """ Performs a few maintenance tasks before the Honeypot is run. Copies the data directory, and the config file to the cwd. The config file copied here is overwritten if the __init__ method is called with a configuration URL. :param...
[ "def", "prepare_environment", "(", "work_dir", ")", ":", "package_directory", "=", "os", ".", "path", ".", "dirname", "(", "os", ".", "path", ".", "abspath", "(", "beeswarm", ".", "__file__", ")", ")", "logger", ".", "info", "(", "'Copying data files to work...
Performs a few maintenance tasks before the Honeypot is run. Copies the data directory, and the config file to the cwd. The config file copied here is overwritten if the __init__ method is called with a configuration URL. :param work_dir: The directory to copy files to.
[ "Performs", "a", "few", "maintenance", "tasks", "before", "the", "Honeypot", "is", "run", ".", "Copies", "the", "data", "directory", "and", "the", "config", "file", "to", "the", "cwd", ".", "The", "config", "file", "copied", "here", "is", "overwritten", "i...
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/honeypot/honeypot.py#L181-L193
train
Prepares the environment for the Honeypot.
honeynet/beeswarm
beeswarm/drones/client/baits/http.py
Http.start
def start(self): """ Launches a new HTTP client session on the server taken from the `self.options` dict. :param my_ip: IP of this Client itself """ username = self.options['username'] password = self.options['password'] server_host = self.options['server'] ...
python
def start(self): """ Launches a new HTTP client session on the server taken from the `self.options` dict. :param my_ip: IP of this Client itself """ username = self.options['username'] password = self.options['password'] server_host = self.options['server'] ...
[ "def", "start", "(", "self", ")", ":", "username", "=", "self", ".", "options", "[", "'username'", "]", "password", "=", "self", ".", "options", "[", "'password'", "]", "server_host", "=", "self", ".", "options", "[", "'server'", "]", "server_port", "=",...
Launches a new HTTP client session on the server taken from the `self.options` dict. :param my_ip: IP of this Client itself
[ "Launches", "a", "new", "HTTP", "client", "session", "on", "the", "server", "taken", "from", "the", "self", ".", "options", "dict", "." ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/client/baits/http.py#L49-L91
train
Launches a new HTTP client session on the server taken from the self. options dict.
honeynet/beeswarm
beeswarm/drones/client/baits/http.py
Http._get_links
def _get_links(self, response): """ Parses the response text and returns all the links in it. :param response: The Response object. """ html_text = response.text.encode('utf-8') doc = document_fromstring(html_text) links = [] for e in doc.cssselect('a...
python
def _get_links(self, response): """ Parses the response text and returns all the links in it. :param response: The Response object. """ html_text = response.text.encode('utf-8') doc = document_fromstring(html_text) links = [] for e in doc.cssselect('a...
[ "def", "_get_links", "(", "self", ",", "response", ")", ":", "html_text", "=", "response", ".", "text", ".", "encode", "(", "'utf-8'", ")", "doc", "=", "document_fromstring", "(", "html_text", ")", "links", "=", "[", "]", "for", "e", "in", "doc", ".", ...
Parses the response text and returns all the links in it. :param response: The Response object.
[ "Parses", "the", "response", "text", "and", "returns", "all", "the", "links", "in", "it", "." ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/client/baits/http.py#L100-L110
train
Parses the response text and returns all the links in it.
honeynet/beeswarm
beeswarm/shared/misc/local_bootstrapper.py
bootstrap
def bootstrap(server_workdir, drone_workdir): """Bootstraps localhost configurations for a Beeswarm server and a honeypot. :param server_workdir: Output directory for the server configuration file. :param drone_workdir: Output directory for the drone configuration file. """ root_logger = logging.ge...
python
def bootstrap(server_workdir, drone_workdir): """Bootstraps localhost configurations for a Beeswarm server and a honeypot. :param server_workdir: Output directory for the server configuration file. :param drone_workdir: Output directory for the drone configuration file. """ root_logger = logging.ge...
[ "def", "bootstrap", "(", "server_workdir", ",", "drone_workdir", ")", ":", "root_logger", "=", "logging", ".", "getLogger", "(", ")", "root_logger", ".", "setLevel", "(", "logging", ".", "DEBUG", ")", "formatter", "=", "logging", ".", "Formatter", "(", "'%(a...
Bootstraps localhost configurations for a Beeswarm server and a honeypot. :param server_workdir: Output directory for the server configuration file. :param drone_workdir: Output directory for the drone configuration file.
[ "Bootstraps", "localhost", "configurations", "for", "a", "Beeswarm", "server", "and", "a", "honeypot", "." ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/shared/misc/local_bootstrapper.py#L39-L120
train
Bootstraps the server and a honeypot.
honeynet/beeswarm
beeswarm/shared/helpers.py
database_exists
def database_exists(url): """Check if a database exists. :param url: A SQLAlchemy engine URL. Performs backend-specific testing to quickly determine if a database exists on the server. :: database_exists('postgres://postgres@localhost/name') #=> False create_database('postgres://post...
python
def database_exists(url): """Check if a database exists. :param url: A SQLAlchemy engine URL. Performs backend-specific testing to quickly determine if a database exists on the server. :: database_exists('postgres://postgres@localhost/name') #=> False create_database('postgres://post...
[ "def", "database_exists", "(", "url", ")", ":", "url", "=", "copy", "(", "make_url", "(", "url", ")", ")", "database", "=", "url", ".", "database", "if", "url", ".", "drivername", ".", "startswith", "(", "'postgresql'", ")", ":", "url", ".", "database"...
Check if a database exists. :param url: A SQLAlchemy engine URL. Performs backend-specific testing to quickly determine if a database exists on the server. :: database_exists('postgres://postgres@localhost/name') #=> False create_database('postgres://postgres@localhost/name') dat...
[ "Check", "if", "a", "database", "exists", "." ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/shared/helpers.py#L246-L297
train
Check if a database exists on the server.
honeynet/beeswarm
beeswarm/server/server.py
Server.message_proxy
def message_proxy(self, work_dir): """ drone_data_inboud is for data comming from drones drone_data_outbound is for commands to the drones, topic must either be a drone ID or all for sending a broadcast message to all drones """ public_keys_dir = os....
python
def message_proxy(self, work_dir): """ drone_data_inboud is for data comming from drones drone_data_outbound is for commands to the drones, topic must either be a drone ID or all for sending a broadcast message to all drones """ public_keys_dir = os....
[ "def", "message_proxy", "(", "self", ",", "work_dir", ")", ":", "public_keys_dir", "=", "os", ".", "path", ".", "join", "(", "work_dir", ",", "'certificates'", ",", "'public_keys'", ")", "secret_keys_dir", "=", "os", ".", "path", ".", "join", "(", "work_di...
drone_data_inboud is for data comming from drones drone_data_outbound is for commands to the drones, topic must either be a drone ID or all for sending a broadcast message to all drones
[ "drone_data_inboud", "is", "for", "data", "comming", "from", "drones", "drone_data_outbound", "is", "for", "commands", "to", "the", "drones", "topic", "must", "either", "be", "a", "drone", "ID", "or", "all", "for", "sending", "a", "broadcast", "message", "to",...
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/server/server.py#L113-L176
train
Create a socket that connects to the drones and connects it to the messages.
honeynet/beeswarm
beeswarm/server/server.py
Server.start
def start(self): """ Starts the BeeSwarm server. """ self.started = True if self.app: web_port = self.config['network']['web_port'] logger.info('Starting server listening on port {0}'.format(web_port)) key_file = os.path.join(self.work_dir,...
python
def start(self): """ Starts the BeeSwarm server. """ self.started = True if self.app: web_port = self.config['network']['web_port'] logger.info('Starting server listening on port {0}'.format(web_port)) key_file = os.path.join(self.work_dir,...
[ "def", "start", "(", "self", ")", ":", "self", ".", "started", "=", "True", "if", "self", ".", "app", ":", "web_port", "=", "self", ".", "config", "[", "'network'", "]", "[", "'web_port'", "]", "logger", ".", "info", "(", "'Starting server listening on p...
Starts the BeeSwarm server.
[ "Starts", "the", "BeeSwarm", "server", "." ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/server/server.py#L178-L194
train
Starts the BeeSwarm server.
honeynet/beeswarm
beeswarm/server/server.py
Server.get_config
def get_config(self, configfile): """ Loads the configuration from the JSON file, and returns it. :param configfile: Path to the configuration file """ with open(configfile) as config_file: config = json.load(config_file) return config
python
def get_config(self, configfile): """ Loads the configuration from the JSON file, and returns it. :param configfile: Path to the configuration file """ with open(configfile) as config_file: config = json.load(config_file) return config
[ "def", "get_config", "(", "self", ",", "configfile", ")", ":", "with", "open", "(", "configfile", ")", "as", "config_file", ":", "config", "=", "json", ".", "load", "(", "config_file", ")", "return", "config" ]
Loads the configuration from the JSON file, and returns it. :param configfile: Path to the configuration file
[ "Loads", "the", "configuration", "from", "the", "JSON", "file", "and", "returns", "it", ".", ":", "param", "configfile", ":", "Path", "to", "the", "configuration", "file" ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/server/server.py#L207-L214
train
Loads the configuration from the JSON file and returns it.
honeynet/beeswarm
beeswarm/drones/client/models/dispatcher.py
BaitDispatcher.time_in_range
def time_in_range(self): """Return true if current time is in the active range""" curr = datetime.datetime.now().time() if self.start_time <= self.end_time: return self.start_time <= curr <= self.end_time else: return self.start_time <= curr or curr <= self.end_ti...
python
def time_in_range(self): """Return true if current time is in the active range""" curr = datetime.datetime.now().time() if self.start_time <= self.end_time: return self.start_time <= curr <= self.end_time else: return self.start_time <= curr or curr <= self.end_ti...
[ "def", "time_in_range", "(", "self", ")", ":", "curr", "=", "datetime", ".", "datetime", ".", "now", "(", ")", ".", "time", "(", ")", "if", "self", ".", "start_time", "<=", "self", ".", "end_time", ":", "return", "self", ".", "start_time", "<=", "cur...
Return true if current time is in the active range
[ "Return", "true", "if", "current", "time", "is", "in", "the", "active", "range" ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/client/models/dispatcher.py#L101-L107
train
Return true if current time is in the active range
honeynet/beeswarm
beeswarm/drones/client/baits/vnc.py
Vnc.start
def start(self): """ Launches a new Telnet client session on the server taken from the `self.options` dict. This session always fails. :param my_ip: IP of this Client itself """ password = self.options['password'] server_host = self.options['server'] ...
python
def start(self): """ Launches a new Telnet client session on the server taken from the `self.options` dict. This session always fails. :param my_ip: IP of this Client itself """ password = self.options['password'] server_host = self.options['server'] ...
[ "def", "start", "(", "self", ")", ":", "password", "=", "self", ".", "options", "[", "'password'", "]", "server_host", "=", "self", ".", "options", "[", "'server'", "]", "server_port", "=", "self", ".", "options", "[", "'port'", "]", "honeypot_id", "=", ...
Launches a new Telnet client session on the server taken from the `self.options` dict. This session always fails. :param my_ip: IP of this Client itself
[ "Launches", "a", "new", "Telnet", "client", "session", "on", "the", "server", "taken", "from", "the", "self", ".", "options", "dict", ".", "This", "session", "always", "fails", "." ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/client/baits/vnc.py#L37-L92
train
Launches a new Telnet client session on the server taken from the self. options dict.
honeynet/beeswarm
beeswarm/drones/client/baits/clientbase.py
ClientBase.create_session
def create_session(self, server_host, server_port, honeypot_id): """ Creates a new session. :param server_host: IP address of the server :param server_port: Server port :return: A new `BaitSession` object. """ protocol = self.__class__.__name__.lower() ...
python
def create_session(self, server_host, server_port, honeypot_id): """ Creates a new session. :param server_host: IP address of the server :param server_port: Server port :return: A new `BaitSession` object. """ protocol = self.__class__.__name__.lower() ...
[ "def", "create_session", "(", "self", ",", "server_host", ",", "server_port", ",", "honeypot_id", ")", ":", "protocol", "=", "self", ".", "__class__", ".", "__name__", ".", "lower", "(", ")", "session", "=", "BaitSession", "(", "protocol", ",", "server_host"...
Creates a new session. :param server_host: IP address of the server :param server_port: Server port :return: A new `BaitSession` object.
[ "Creates", "a", "new", "session", "." ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/client/baits/clientbase.py#L31-L42
train
Creates a new session.
honeynet/beeswarm
beeswarm/drones/client/baits/ftp.py
Ftp.start
def start(self): """ Launches a new FTP client session on the server taken from the `self.options` dict. :param my_ip: IP of this Client itself """ username = self.options['username'] password = self.options['password'] server_host = self.options['server'] ...
python
def start(self): """ Launches a new FTP client session on the server taken from the `self.options` dict. :param my_ip: IP of this Client itself """ username = self.options['username'] password = self.options['password'] server_host = self.options['server'] ...
[ "def", "start", "(", "self", ")", ":", "username", "=", "self", ".", "options", "[", "'username'", "]", "password", "=", "self", ".", "options", "[", "'password'", "]", "server_host", "=", "self", ".", "options", "[", "'server'", "]", "server_port", "=",...
Launches a new FTP client session on the server taken from the `self.options` dict. :param my_ip: IP of this Client itself
[ "Launches", "a", "new", "FTP", "client", "session", "on", "the", "server", "taken", "from", "the", "self", ".", "options", "dict", "." ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/client/baits/ftp.py#L64-L116
train
Launches a new FTP client session on the server taken from the self. options dict.
honeynet/beeswarm
beeswarm/drones/client/baits/ftp.py
Ftp.sense
def sense(self): """ Launches a few "sensing" commands such as 'ls', or 'pwd' and updates the current bait state. """ cmd_name = random.choice(self.senses) command = getattr(self, cmd_name) self.state['last_command'] = cmd_name command()
python
def sense(self): """ Launches a few "sensing" commands such as 'ls', or 'pwd' and updates the current bait state. """ cmd_name = random.choice(self.senses) command = getattr(self, cmd_name) self.state['last_command'] = cmd_name command()
[ "def", "sense", "(", "self", ")", ":", "cmd_name", "=", "random", ".", "choice", "(", "self", ".", "senses", ")", "command", "=", "getattr", "(", "self", ",", "cmd_name", ")", "self", ".", "state", "[", "'last_command'", "]", "=", "cmd_name", "command"...
Launches a few "sensing" commands such as 'ls', or 'pwd' and updates the current bait state.
[ "Launches", "a", "few", "sensing", "commands", "such", "as", "ls", "or", "pwd", "and", "updates", "the", "current", "bait", "state", "." ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/client/baits/ftp.py#L118-L126
train
Launches a few sensing commands such as ls or pwd.
honeynet/beeswarm
beeswarm/drones/client/baits/ftp.py
Ftp.decide
def decide(self): """ Decides the next command to be launched based on the current state. :return: Tuple containing the next command name, and it's parameters. """ next_command_name = random.choice(self.COMMAND_MAP[self.state['last_command']]) param = '' if n...
python
def decide(self): """ Decides the next command to be launched based on the current state. :return: Tuple containing the next command name, and it's parameters. """ next_command_name = random.choice(self.COMMAND_MAP[self.state['last_command']]) param = '' if n...
[ "def", "decide", "(", "self", ")", ":", "next_command_name", "=", "random", ".", "choice", "(", "self", ".", "COMMAND_MAP", "[", "self", ".", "state", "[", "'last_command'", "]", "]", ")", "param", "=", "''", "if", "next_command_name", "==", "'retrieve'", ...
Decides the next command to be launched based on the current state. :return: Tuple containing the next command name, and it's parameters.
[ "Decides", "the", "next", "command", "to", "be", "launched", "based", "on", "the", "current", "state", "." ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/client/baits/ftp.py#L128-L140
train
Decides the next command to be launched based on the current state.
honeynet/beeswarm
beeswarm/drones/client/baits/ftp.py
Ftp.act
def act(self, cmd_name, param): """ Run the command with the parameters. :param cmd_name: The name of command to run :param param: Params for the command """ command = getattr(self, cmd_name) if param: command(param) else: comm...
python
def act(self, cmd_name, param): """ Run the command with the parameters. :param cmd_name: The name of command to run :param param: Params for the command """ command = getattr(self, cmd_name) if param: command(param) else: comm...
[ "def", "act", "(", "self", ",", "cmd_name", ",", "param", ")", ":", "command", "=", "getattr", "(", "self", ",", "cmd_name", ")", "if", "param", ":", "command", "(", "param", ")", "else", ":", "command", "(", ")" ]
Run the command with the parameters. :param cmd_name: The name of command to run :param param: Params for the command
[ "Run", "the", "command", "with", "the", "parameters", "." ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/client/baits/ftp.py#L142-L153
train
Run the command with the parameters.
honeynet/beeswarm
beeswarm/drones/client/baits/ftp.py
Ftp.list
def list(self): """ Run the FTP LIST command, and update the state. """ logger.debug('Sending FTP list command.') self.state['file_list'] = [] self.state['dir_list'] = [] self.client.retrlines('LIST', self._process_list)
python
def list(self): """ Run the FTP LIST command, and update the state. """ logger.debug('Sending FTP list command.') self.state['file_list'] = [] self.state['dir_list'] = [] self.client.retrlines('LIST', self._process_list)
[ "def", "list", "(", "self", ")", ":", "logger", ".", "debug", "(", "'Sending FTP list command.'", ")", "self", ".", "state", "[", "'file_list'", "]", "=", "[", "]", "self", ".", "state", "[", "'dir_list'", "]", "=", "[", "]", "self", ".", "client", "...
Run the FTP LIST command, and update the state.
[ "Run", "the", "FTP", "LIST", "command", "and", "update", "the", "state", "." ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/client/baits/ftp.py#L155-L162
train
Send the LIST command to the server.
honeynet/beeswarm
beeswarm/drones/client/baits/ftp.py
Ftp.retrieve
def retrieve(self, filename): """ Run the FTP RETR command, and download the file :param filename: Name of the file to download """ logger.debug('Sending FTP retr command. Filename: {}'.format(filename)) self.client.retrbinary('RETR {}'.format(filename), self._save_f...
python
def retrieve(self, filename): """ Run the FTP RETR command, and download the file :param filename: Name of the file to download """ logger.debug('Sending FTP retr command. Filename: {}'.format(filename)) self.client.retrbinary('RETR {}'.format(filename), self._save_f...
[ "def", "retrieve", "(", "self", ",", "filename", ")", ":", "logger", ".", "debug", "(", "'Sending FTP retr command. Filename: {}'", ".", "format", "(", "filename", ")", ")", "self", ".", "client", ".", "retrbinary", "(", "'RETR {}'", ".", "format", "(", "fil...
Run the FTP RETR command, and download the file :param filename: Name of the file to download
[ "Run", "the", "FTP", "RETR", "command", "and", "download", "the", "file" ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/client/baits/ftp.py#L164-L171
train
Run the FTP RETR command and download the file
honeynet/beeswarm
beeswarm/drones/client/baits/ftp.py
Ftp.cwd
def cwd(self, newdir): """ Send the FTP CWD command :param newdir: Directory to change to """ logger.debug('Sending FTP cwd command. New Workding Directory: {}'.format(newdir)) self.client.cwd(newdir) self.state['current_dir'] = self.client.pwd()
python
def cwd(self, newdir): """ Send the FTP CWD command :param newdir: Directory to change to """ logger.debug('Sending FTP cwd command. New Workding Directory: {}'.format(newdir)) self.client.cwd(newdir) self.state['current_dir'] = self.client.pwd()
[ "def", "cwd", "(", "self", ",", "newdir", ")", ":", "logger", ".", "debug", "(", "'Sending FTP cwd command. New Workding Directory: {}'", ".", "format", "(", "newdir", ")", ")", "self", ".", "client", ".", "cwd", "(", "newdir", ")", "self", ".", "state", "...
Send the FTP CWD command :param newdir: Directory to change to
[ "Send", "the", "FTP", "CWD", "command" ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/client/baits/ftp.py#L180-L188
train
Send the FTP CWD command to change the current working directory
honeynet/beeswarm
beeswarm/drones/client/baits/ftp.py
Ftp._process_list
def _process_list(self, list_line): # -rw-r--r-- 1 ftp ftp 68 May 09 19:37 testftp.txt """ Processes a line of 'ls -l' output, and updates state accordingly. :param list_line: Line to process """ res = list_line.split(' ', 8) if res[0].startswith('-'): ...
python
def _process_list(self, list_line): # -rw-r--r-- 1 ftp ftp 68 May 09 19:37 testftp.txt """ Processes a line of 'ls -l' output, and updates state accordingly. :param list_line: Line to process """ res = list_line.split(' ', 8) if res[0].startswith('-'): ...
[ "def", "_process_list", "(", "self", ",", "list_line", ")", ":", "# -rw-r--r-- 1 ftp ftp 68\t May 09 19:37 testftp.txt", "res", "=", "list_line", ".", "split", "(", "' '", ",", "8", ")", "if", "res", "[", "0", "]", ".", "startswith", "(", "'-'", ")", ":", ...
Processes a line of 'ls -l' output, and updates state accordingly. :param list_line: Line to process
[ "Processes", "a", "line", "of", "ls", "-", "l", "output", "and", "updates", "state", "accordingly", "." ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/client/baits/ftp.py#L206-L217
train
Processes a line of ls - l output and updates state accordingly.
honeynet/beeswarm
beeswarm/server/webapp/forms.py
validate_time_range
def validate_time_range(form, field): """ Makes sure the form data is in 'hh:mm - hh:mm' format and the start time is less than end time.""" string = field.data try: begin, end = string.split('-') begin = begin.strip() end = end.strip() begin_hours, begin_min = begin.split(...
python
def validate_time_range(form, field): """ Makes sure the form data is in 'hh:mm - hh:mm' format and the start time is less than end time.""" string = field.data try: begin, end = string.split('-') begin = begin.strip() end = end.strip() begin_hours, begin_min = begin.split(...
[ "def", "validate_time_range", "(", "form", ",", "field", ")", ":", "string", "=", "field", ".", "data", "try", ":", "begin", ",", "end", "=", "string", ".", "split", "(", "'-'", ")", "begin", "=", "begin", ".", "strip", "(", ")", "end", "=", "end",...
Makes sure the form data is in 'hh:mm - hh:mm' format and the start time is less than end time.
[ "Makes", "sure", "the", "form", "data", "is", "in", "hh", ":", "mm", "-", "hh", ":", "mm", "format", "and", "the", "start", "time", "is", "less", "than", "end", "time", "." ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/server/webapp/forms.py#L6-L24
train
Make sure the form data is in the correct format and the start time is less than end time.
honeynet/beeswarm
beeswarm/drones/client/client.py
Client.start
def start(self): """ Starts sending client bait to the configured Honeypot. """ logger.info('Starting client.') self.dispatcher_greenlets = [] for _, entry in self.config['baits'].items(): for b in clientbase.ClientBase.__subclasses__(): ...
python
def start(self): """ Starts sending client bait to the configured Honeypot. """ logger.info('Starting client.') self.dispatcher_greenlets = [] for _, entry in self.config['baits'].items(): for b in clientbase.ClientBase.__subclasses__(): ...
[ "def", "start", "(", "self", ")", ":", "logger", ".", "info", "(", "'Starting client.'", ")", "self", ".", "dispatcher_greenlets", "=", "[", "]", "for", "_", ",", "entry", "in", "self", ".", "config", "[", "'baits'", "]", ".", "items", "(", ")", ":",...
Starts sending client bait to the configured Honeypot.
[ "Starts", "sending", "client", "bait", "to", "the", "configured", "Honeypot", "." ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/client/client.py#L58-L78
train
Starts sending bait to the configured Honeypot.
honeynet/beeswarm
beeswarm/drones/client/baits/pop3s.py
Pop3s.start
def start(self): """ Launches a new POP3 client session on the server taken from the `self.options` dict. :param my_ip: IP of this Client itself """ username = self.options['username'] password = self.options['password'] server_host = self.options['server'] ...
python
def start(self): """ Launches a new POP3 client session on the server taken from the `self.options` dict. :param my_ip: IP of this Client itself """ username = self.options['username'] password = self.options['password'] server_host = self.options['server'] ...
[ "def", "start", "(", "self", ")", ":", "username", "=", "self", ".", "options", "[", "'username'", "]", "password", "=", "self", ".", "options", "[", "'password'", "]", "server_host", "=", "self", ".", "options", "[", "'server'", "]", "server_port", "=",...
Launches a new POP3 client session on the server taken from the `self.options` dict. :param my_ip: IP of this Client itself
[ "Launches", "a", "new", "POP3", "client", "session", "on", "the", "server", "taken", "from", "the", "self", ".", "options", "dict", "." ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/client/baits/pop3s.py#L30-L75
train
Launches a new POP3 client session on the server taken from the self. options dict.
honeynet/beeswarm
beeswarm/server/db/database_actor.py
DatabaseActor.get_matching_session
def get_matching_session(self, session, db_session, timediff=5): """ Tries to match a session with it's counterpart. For bait session it will try to match it with honeypot sessions and the other way around. :param session: session object which will be used as base for query. :pa...
python
def get_matching_session(self, session, db_session, timediff=5): """ Tries to match a session with it's counterpart. For bait session it will try to match it with honeypot sessions and the other way around. :param session: session object which will be used as base for query. :pa...
[ "def", "get_matching_session", "(", "self", ",", "session", ",", "db_session", ",", "timediff", "=", "5", ")", ":", "db_session", "=", "db_session", "min_datetime", "=", "session", ".", "timestamp", "-", "timedelta", "(", "seconds", "=", "timediff", ")", "ma...
Tries to match a session with it's counterpart. For bait session it will try to match it with honeypot sessions and the other way around. :param session: session object which will be used as base for query. :param timediff: +/- allowed time difference between a session and a potential matching ...
[ "Tries", "to", "match", "a", "session", "with", "it", "s", "counterpart", ".", "For", "bait", "session", "it", "will", "try", "to", "match", "it", "with", "honeypot", "sessions", "and", "the", "other", "way", "around", "." ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/server/db/database_actor.py#L354-L393
train
Tries to match a session with it s counterpart.
honeynet/beeswarm
beeswarm/server/db/database_actor.py
DatabaseActor._classify_malicious_sessions
def _classify_malicious_sessions(self): """ Will classify all unclassified sessions as malicious activity. :param delay_seconds: no sessions newer than (now - delay_seconds) will be processed. """ min_datetime = datetime.utcnow() - timedelta(seconds=self.delay_seconds) ...
python
def _classify_malicious_sessions(self): """ Will classify all unclassified sessions as malicious activity. :param delay_seconds: no sessions newer than (now - delay_seconds) will be processed. """ min_datetime = datetime.utcnow() - timedelta(seconds=self.delay_seconds) ...
[ "def", "_classify_malicious_sessions", "(", "self", ")", ":", "min_datetime", "=", "datetime", ".", "utcnow", "(", ")", "-", "timedelta", "(", "seconds", "=", "self", ".", "delay_seconds", ")", "db_session", "=", "database_setup", ".", "get_session", "(", ")",...
Will classify all unclassified sessions as malicious activity. :param delay_seconds: no sessions newer than (now - delay_seconds) will be processed.
[ "Will", "classify", "all", "unclassified", "sessions", "as", "malicious", "activity", "." ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/server/db/database_actor.py#L414-L474
train
Classify all unclassified sessions as malicious activity.
honeynet/beeswarm
beeswarm/drones/client/baits/ssh.py
Ssh.start
def start(self): """ Launches a new SSH client session on the server taken from the `self.options` dict. :param my_ip: IP of this Client itself """ username = self.options['username'] password = self.options['password'] server_host = self.options['server'] ...
python
def start(self): """ Launches a new SSH client session on the server taken from the `self.options` dict. :param my_ip: IP of this Client itself """ username = self.options['username'] password = self.options['password'] server_host = self.options['server'] ...
[ "def", "start", "(", "self", ")", ":", "username", "=", "self", ".", "options", "[", "'username'", "]", "password", "=", "self", ".", "options", "[", "'password'", "]", "server_host", "=", "self", ".", "options", "[", "'server'", "]", "server_port", "=",...
Launches a new SSH client session on the server taken from the `self.options` dict. :param my_ip: IP of this Client itself
[ "Launches", "a", "new", "SSH", "client", "session", "on", "the", "server", "taken", "from", "the", "self", ".", "options", "dict", "." ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/client/baits/ssh.py#L51-L90
train
Launches a new SSH client session on the server taken from the self. options dict.
honeynet/beeswarm
beeswarm/drones/client/baits/ssh.py
Ssh.send_command
def send_command(self, cmd): """ Send a command to the remote SSH server. :param cmd: The command to send """ logger.debug('Sending {0} command.'.format(cmd)) self.comm_chan.sendall(cmd + '\n')
python
def send_command(self, cmd): """ Send a command to the remote SSH server. :param cmd: The command to send """ logger.debug('Sending {0} command.'.format(cmd)) self.comm_chan.sendall(cmd + '\n')
[ "def", "send_command", "(", "self", ",", "cmd", ")", ":", "logger", ".", "debug", "(", "'Sending {0} command.'", ".", "format", "(", "cmd", ")", ")", "self", ".", "comm_chan", ".", "sendall", "(", "cmd", "+", "'\\n'", ")" ]
Send a command to the remote SSH server. :param cmd: The command to send
[ "Send", "a", "command", "to", "the", "remote", "SSH", "server", "." ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/client/baits/ssh.py#L92-L99
train
Send a command to the remote SSH server.
honeynet/beeswarm
beeswarm/drones/client/baits/ssh.py
Ssh.get_response
def get_response(self): """ Get the response from the server. *This may not return the full response* :return: Response data """ while not self.comm_chan.recv_ready(): time.sleep(0.5) return self.comm_chan.recv(2048)
python
def get_response(self): """ Get the response from the server. *This may not return the full response* :return: Response data """ while not self.comm_chan.recv_ready(): time.sleep(0.5) return self.comm_chan.recv(2048)
[ "def", "get_response", "(", "self", ")", ":", "while", "not", "self", ".", "comm_chan", ".", "recv_ready", "(", ")", ":", "time", ".", "sleep", "(", "0.5", ")", "return", "self", ".", "comm_chan", ".", "recv", "(", "2048", ")" ]
Get the response from the server. *This may not return the full response* :return: Response data
[ "Get", "the", "response", "from", "the", "server", ".", "*", "This", "may", "not", "return", "the", "full", "response", "*" ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/client/baits/ssh.py#L101-L109
train
Get the response from the server.
honeynet/beeswarm
beeswarm/drones/client/baits/ssh.py
Ssh.connect_login
def connect_login(self): """ Try to login to the Remote SSH Server. :return: Response text on successful login :raise: `AuthenticationFailed` on unsuccessful login """ self.client.connect(self.options['server'], self.options['port'], self.options['username'], ...
python
def connect_login(self): """ Try to login to the Remote SSH Server. :return: Response text on successful login :raise: `AuthenticationFailed` on unsuccessful login """ self.client.connect(self.options['server'], self.options['port'], self.options['username'], ...
[ "def", "connect_login", "(", "self", ")", ":", "self", ".", "client", ".", "connect", "(", "self", ".", "options", "[", "'server'", "]", ",", "self", ".", "options", "[", "'port'", "]", ",", "self", ".", "options", "[", "'username'", "]", ",", "self"...
Try to login to the Remote SSH Server. :return: Response text on successful login :raise: `AuthenticationFailed` on unsuccessful login
[ "Try", "to", "login", "to", "the", "Remote", "SSH", "Server", "." ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/client/baits/ssh.py#L111-L127
train
Connect to the Remote SSH Server and login to the Remote SSH Server.
honeynet/beeswarm
beeswarm/drones/honeypot/helpers/common.py
list2dict
def list2dict(list_of_options): """Transforms a list of 2 element tuples to a dictionary""" d = {} for key, value in list_of_options: d[key] = value return d
python
def list2dict(list_of_options): """Transforms a list of 2 element tuples to a dictionary""" d = {} for key, value in list_of_options: d[key] = value return d
[ "def", "list2dict", "(", "list_of_options", ")", ":", "d", "=", "{", "}", "for", "key", ",", "value", "in", "list_of_options", ":", "d", "[", "key", "]", "=", "value", "return", "d" ]
Transforms a list of 2 element tuples to a dictionary
[ "Transforms", "a", "list", "of", "2", "element", "tuples", "to", "a", "dictionary" ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/honeypot/helpers/common.py#L10-L15
train
Transforms a list of 2 element tuples to a dictionary
honeynet/beeswarm
beeswarm/drones/honeypot/helpers/common.py
path_to_ls
def path_to_ls(fn): """ Converts an absolute path to an entry resembling the output of the ls command on most UNIX systems.""" st = os.stat(fn) full_mode = 'rwxrwxrwx' mode = '' file_time = '' d = '' for i in range(9): # Incrementally builds up the 9 character string, using c...
python
def path_to_ls(fn): """ Converts an absolute path to an entry resembling the output of the ls command on most UNIX systems.""" st = os.stat(fn) full_mode = 'rwxrwxrwx' mode = '' file_time = '' d = '' for i in range(9): # Incrementally builds up the 9 character string, using c...
[ "def", "path_to_ls", "(", "fn", ")", ":", "st", "=", "os", ".", "stat", "(", "fn", ")", "full_mode", "=", "'rwxrwxrwx'", "mode", "=", "''", "file_time", "=", "''", "d", "=", "''", "for", "i", "in", "range", "(", "9", ")", ":", "# Incrementally buil...
Converts an absolute path to an entry resembling the output of the ls command on most UNIX systems.
[ "Converts", "an", "absolute", "path", "to", "an", "entry", "resembling", "the", "output", "of", "the", "ls", "command", "on", "most", "UNIX", "systems", "." ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/honeypot/helpers/common.py#L27-L42
train
Converts an absolute path to an entry resembling the output of the ls command on most UNIX systems.
honeynet/beeswarm
beeswarm/drones/drone.py
Drone.start
def start(self): """ Starts services. """ cert_path = os.path.join(self.work_dir, 'certificates') public_keys_dir = os.path.join(cert_path, 'public_keys') private_keys_dir = os.path.join(cert_path, 'private_keys') client_secret_file = os.path.join(private_keys_dir, "client.key")...
python
def start(self): """ Starts services. """ cert_path = os.path.join(self.work_dir, 'certificates') public_keys_dir = os.path.join(cert_path, 'public_keys') private_keys_dir = os.path.join(cert_path, 'private_keys') client_secret_file = os.path.join(private_keys_dir, "client.key")...
[ "def", "start", "(", "self", ")", ":", "cert_path", "=", "os", ".", "path", ".", "join", "(", "self", ".", "work_dir", ",", "'certificates'", ")", "public_keys_dir", "=", "os", ".", "path", ".", "join", "(", "cert_path", ",", "'public_keys'", ")", "pri...
Starts services.
[ "Starts", "services", "." ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/drone.py#L85-L104
train
Starts services.
honeynet/beeswarm
beeswarm/drones/drone.py
Drone._start_drone
def _start_drone(self): """ Restarts the drone """ with open(self.config_file, 'r') as config_file: self.config = json.load(config_file, object_hook=asciify) mode = None if self.config['general']['mode'] == '' or self.config['general']['mode'] is None: ...
python
def _start_drone(self): """ Restarts the drone """ with open(self.config_file, 'r') as config_file: self.config = json.load(config_file, object_hook=asciify) mode = None if self.config['general']['mode'] == '' or self.config['general']['mode'] is None: ...
[ "def", "_start_drone", "(", "self", ")", ":", "with", "open", "(", "self", ".", "config_file", ",", "'r'", ")", "as", "config_file", ":", "self", ".", "config", "=", "json", ".", "load", "(", "config_file", ",", "object_hook", "=", "asciify", ")", "mod...
Restarts the drone
[ "Restarts", "the", "drone" ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/drone.py#L106-L126
train
Restarts the drone and starts it
honeynet/beeswarm
beeswarm/drones/drone.py
Drone.stop
def stop(self): """Stops services""" logging.debug('Stopping drone, hang on.') if self.drone is not None: self.drone_greenlet.unlink(self.on_exception) self.drone.stop() self.drone_greenlet.kill() self.drone = None # just some time for the ...
python
def stop(self): """Stops services""" logging.debug('Stopping drone, hang on.') if self.drone is not None: self.drone_greenlet.unlink(self.on_exception) self.drone.stop() self.drone_greenlet.kill() self.drone = None # just some time for the ...
[ "def", "stop", "(", "self", ")", ":", "logging", ".", "debug", "(", "'Stopping drone, hang on.'", ")", "if", "self", ".", "drone", "is", "not", "None", ":", "self", ".", "drone_greenlet", ".", "unlink", "(", "self", ".", "on_exception", ")", "self", ".",...
Stops services
[ "Stops", "services" ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/drone.py#L128-L139
train
Stops the drone and kills the drone_greenlet.
honeynet/beeswarm
beeswarm/drones/client/baits/smtp.py
Smtp.start
def start(self): """ Launches a new SMTP client session on the server taken from the `self.options` dict. :param my_ip: IP of this Client itself """ username = self.options['username'] password = self.options['password'] server_host = self.options['server'] ...
python
def start(self): """ Launches a new SMTP client session on the server taken from the `self.options` dict. :param my_ip: IP of this Client itself """ username = self.options['username'] password = self.options['password'] server_host = self.options['server'] ...
[ "def", "start", "(", "self", ")", ":", "username", "=", "self", ".", "options", "[", "'username'", "]", "password", "=", "self", ".", "options", "[", "'password'", "]", "server_host", "=", "self", ".", "options", "[", "'server'", "]", "server_port", "=",...
Launches a new SMTP client session on the server taken from the `self.options` dict. :param my_ip: IP of this Client itself
[ "Launches", "a", "new", "SMTP", "client", "session", "on", "the", "server", "taken", "from", "the", "self", ".", "options", "dict", "." ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/client/baits/smtp.py#L51-L103
train
Launches a new SMTP client session on the server taken from the self. options dict.
honeynet/beeswarm
beeswarm/drones/client/baits/smtp.py
Smtp.get_one_mail
def get_one_mail(self): """ Choose and return a random email from the mail archive. :return: Tuple containing From Address, To Address and the mail body. """ while True: mail_key = random.choice(self.mailbox.keys()) mail = self.mailbox[mail_key] ...
python
def get_one_mail(self): """ Choose and return a random email from the mail archive. :return: Tuple containing From Address, To Address and the mail body. """ while True: mail_key = random.choice(self.mailbox.keys()) mail = self.mailbox[mail_key] ...
[ "def", "get_one_mail", "(", "self", ")", ":", "while", "True", ":", "mail_key", "=", "random", ".", "choice", "(", "self", ".", "mailbox", ".", "keys", "(", ")", ")", "mail", "=", "self", ".", "mailbox", "[", "mail_key", "]", "from_addr", "=", "mail"...
Choose and return a random email from the mail archive. :return: Tuple containing From Address, To Address and the mail body.
[ "Choose", "and", "return", "a", "random", "email", "from", "the", "mail", "archive", "." ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/client/baits/smtp.py#L105-L120
train
Choose and return a random email from the mail archive.
honeynet/beeswarm
beeswarm/drones/client/baits/smtp.py
Smtp.connect
def connect(self): """ Connect to the SMTP server. """ # TODO: local_hostname should be configurable self.client = smtplib.SMTP(self.options['server'], self.options['port'], local_hostname='local.domain', timeout=15)
python
def connect(self): """ Connect to the SMTP server. """ # TODO: local_hostname should be configurable self.client = smtplib.SMTP(self.options['server'], self.options['port'], local_hostname='local.domain', timeout=15)
[ "def", "connect", "(", "self", ")", ":", "# TODO: local_hostname should be configurable", "self", ".", "client", "=", "smtplib", ".", "SMTP", "(", "self", ".", "options", "[", "'server'", "]", ",", "self", ".", "options", "[", "'port'", "]", ",", "local_host...
Connect to the SMTP server.
[ "Connect", "to", "the", "SMTP", "server", "." ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/client/baits/smtp.py#L122-L128
train
Connect to the SMTP server.
honeynet/beeswarm
beeswarm/drones/honeypot/capabilities/shared/shell.py
Commands.handle
def handle(self): "The actual service to which the user has connected." if not self.authentication_ok(): return if self.DOECHO: self.writeline(self.WELCOME) self.session_start() while self.RUNSHELL: read_line = self.readline(prompt=self.PROMPT)...
python
def handle(self): "The actual service to which the user has connected." if not self.authentication_ok(): return if self.DOECHO: self.writeline(self.WELCOME) self.session_start() while self.RUNSHELL: read_line = self.readline(prompt=self.PROMPT)...
[ "def", "handle", "(", "self", ")", ":", "if", "not", "self", ".", "authentication_ok", "(", ")", ":", "return", "if", "self", ".", "DOECHO", ":", "self", ".", "writeline", "(", "self", ".", "WELCOME", ")", "self", ".", "session_start", "(", ")", "whi...
The actual service to which the user has connected.
[ "The", "actual", "service", "to", "which", "the", "user", "has", "connected", "." ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/honeypot/capabilities/shared/shell.py#L244-L273
train
The actual service to which the user has connected.
honeynet/beeswarm
beeswarm/shared/asciify.py
_asciify_list
def _asciify_list(data): """ Ascii-fies list values """ ret = [] for item in data: if isinstance(item, unicode): item = _remove_accents(item) item = item.encode('utf-8') elif isinstance(item, list): item = _asciify_list(item) elif isinstance(item, ...
python
def _asciify_list(data): """ Ascii-fies list values """ ret = [] for item in data: if isinstance(item, unicode): item = _remove_accents(item) item = item.encode('utf-8') elif isinstance(item, list): item = _asciify_list(item) elif isinstance(item, ...
[ "def", "_asciify_list", "(", "data", ")", ":", "ret", "=", "[", "]", "for", "item", "in", "data", ":", "if", "isinstance", "(", "item", ",", "unicode", ")", ":", "item", "=", "_remove_accents", "(", "item", ")", "item", "=", "item", ".", "encode", ...
Ascii-fies list values
[ "Ascii", "-", "fies", "list", "values" ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/shared/asciify.py#L15-L27
train
Convert list items into Ascii - fies list values
honeynet/beeswarm
beeswarm/shared/asciify.py
_asciify_dict
def _asciify_dict(data): """ Ascii-fies dict keys and values """ ret = {} for key, value in data.iteritems(): if isinstance(key, unicode): key = _remove_accents(key) key = key.encode('utf-8') # # note new if if isinstance(value, unicode): value...
python
def _asciify_dict(data): """ Ascii-fies dict keys and values """ ret = {} for key, value in data.iteritems(): if isinstance(key, unicode): key = _remove_accents(key) key = key.encode('utf-8') # # note new if if isinstance(value, unicode): value...
[ "def", "_asciify_dict", "(", "data", ")", ":", "ret", "=", "{", "}", "for", "key", ",", "value", "in", "data", ".", "iteritems", "(", ")", ":", "if", "isinstance", "(", "key", ",", "unicode", ")", ":", "key", "=", "_remove_accents", "(", "key", ")"...
Ascii-fies dict keys and values
[ "Ascii", "-", "fies", "dict", "keys", "and", "values" ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/shared/asciify.py#L30-L46
train
Convert dict keys and values into Ascii - fies dict keys and values
honeynet/beeswarm
beeswarm/drones/client/baits/telnet.py
BaitTelnetClient.write_human
def write_human(self, buffer_): """ Emulates human typing speed """ if self.IAC in buffer_: buffer_ = buffer_.replace(self.IAC, self.IAC + self.IAC) self.msg("send %r", buffer_) for char in buffer_: delta = random.gauss(80, 20) self.sock.sendall(char)...
python
def write_human(self, buffer_): """ Emulates human typing speed """ if self.IAC in buffer_: buffer_ = buffer_.replace(self.IAC, self.IAC + self.IAC) self.msg("send %r", buffer_) for char in buffer_: delta = random.gauss(80, 20) self.sock.sendall(char)...
[ "def", "write_human", "(", "self", ",", "buffer_", ")", ":", "if", "self", ".", "IAC", "in", "buffer_", ":", "buffer_", "=", "buffer_", ".", "replace", "(", "self", ".", "IAC", ",", "self", ".", "IAC", "+", "self", ".", "IAC", ")", "self", ".", "...
Emulates human typing speed
[ "Emulates", "human", "typing", "speed" ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/client/baits/telnet.py#L40-L49
train
Emulates human typing speed
honeynet/beeswarm
beeswarm/drones/client/baits/telnet.py
Telnet.start
def start(self): """ Launches a new Telnet client session on the server taken from the `self.options` dict. :param my_ip: IP of this Client itself """ login = self.options['username'] password = self.options['password'] server_host = self.options['server'] ...
python
def start(self): """ Launches a new Telnet client session on the server taken from the `self.options` dict. :param my_ip: IP of this Client itself """ login = self.options['username'] password = self.options['password'] server_host = self.options['server'] ...
[ "def", "start", "(", "self", ")", ":", "login", "=", "self", ".", "options", "[", "'username'", "]", "password", "=", "self", ".", "options", "[", "'password'", "]", "server_host", "=", "self", ".", "options", "[", "'server'", "]", "server_port", "=", ...
Launches a new Telnet client session on the server taken from the `self.options` dict. :param my_ip: IP of this Client itself
[ "Launches", "a", "new", "Telnet", "client", "session", "on", "the", "server", "taken", "from", "the", "self", ".", "options", "dict", "." ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/client/baits/telnet.py#L75-L122
train
Launches a new Telnet client session on the server taken from the self. options dict.
honeynet/beeswarm
beeswarm/drones/client/baits/telnet.py
Telnet.connect
def connect(self): """ Open a new telnet session on the remote server. """ self.client = BaitTelnetClient(self.options['server'], self.options['port']) self.client.set_option_negotiation_callback(self.process_options)
python
def connect(self): """ Open a new telnet session on the remote server. """ self.client = BaitTelnetClient(self.options['server'], self.options['port']) self.client.set_option_negotiation_callback(self.process_options)
[ "def", "connect", "(", "self", ")", ":", "self", ".", "client", "=", "BaitTelnetClient", "(", "self", ".", "options", "[", "'server'", "]", ",", "self", ".", "options", "[", "'port'", "]", ")", "self", ".", "client", ".", "set_option_negotiation_callback",...
Open a new telnet session on the remote server.
[ "Open", "a", "new", "telnet", "session", "on", "the", "remote", "server", "." ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/client/baits/telnet.py#L124-L129
train
Open a new telnet session on the remote server.
honeynet/beeswarm
beeswarm/drones/client/baits/telnet.py
Telnet.login
def login(self, login, password): """ Login to the remote telnet server. :param login: Username to use for logging in :param password: Password to use for logging in :raise: `InvalidLogin` on failed login """ self.client.read_until('Username: ') self....
python
def login(self, login, password): """ Login to the remote telnet server. :param login: Username to use for logging in :param password: Password to use for logging in :raise: `InvalidLogin` on failed login """ self.client.read_until('Username: ') self....
[ "def", "login", "(", "self", ",", "login", ",", "password", ")", ":", "self", ".", "client", ".", "read_until", "(", "'Username: '", ")", "self", ".", "client", ".", "write", "(", "login", "+", "'\\r\\n'", ")", "self", ".", "client", ".", "read_until",...
Login to the remote telnet server. :param login: Username to use for logging in :param password: Password to use for logging in :raise: `InvalidLogin` on failed login
[ "Login", "to", "the", "remote", "telnet", "server", "." ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/client/baits/telnet.py#L131-L145
train
Log in to the remote telnet server.
honeynet/beeswarm
beeswarm/drones/client/baits/telnet.py
Telnet.logout
def logout(self): """ Logout from the remote server. """ self.client.write('exit\r\n') self.client.read_all() self.client.close()
python
def logout(self): """ Logout from the remote server. """ self.client.write('exit\r\n') self.client.read_all() self.client.close()
[ "def", "logout", "(", "self", ")", ":", "self", ".", "client", ".", "write", "(", "'exit\\r\\n'", ")", "self", ".", "client", ".", "read_all", "(", ")", "self", ".", "client", ".", "close", "(", ")" ]
Logout from the remote server.
[ "Logout", "from", "the", "remote", "server", "." ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/client/baits/telnet.py#L147-L153
train
Logout from the remote server.
honeynet/beeswarm
beeswarm/shared/models/base_session.py
BaseSession.add_auth_attempt
def add_auth_attempt(self, auth_type, successful, **kwargs): """ :param username: :param password: :param auth_type: possible values: plain: plaintext username/password :return: """ entry = {'timestamp': datetime.utcnow(), ...
python
def add_auth_attempt(self, auth_type, successful, **kwargs): """ :param username: :param password: :param auth_type: possible values: plain: plaintext username/password :return: """ entry = {'timestamp': datetime.utcnow(), ...
[ "def", "add_auth_attempt", "(", "self", ",", "auth_type", ",", "successful", ",", "*", "*", "kwargs", ")", ":", "entry", "=", "{", "'timestamp'", ":", "datetime", ".", "utcnow", "(", ")", ",", "'auth'", ":", "auth_type", ",", "'id'", ":", "uuid", ".", ...
:param username: :param password: :param auth_type: possible values: plain: plaintext username/password :return:
[ ":", "param", "username", ":", ":", "param", "password", ":", ":", "param", "auth_type", ":", "possible", "values", ":", "plain", ":", "plaintext", "username", "/", "password", ":", "return", ":" ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/shared/models/base_session.py#L54-L76
train
Adds an auth attempt to the log.
honeynet/beeswarm
beeswarm/drones/client/baits/shared/shell.py
Commands.sense
def sense(self): """ Launch a command in the 'senses' List, and update the current state.""" cmd_name = random.choice(self.senses) param = '' if cmd_name == 'ls': if random.randint(0, 1): param = '-l' elif cmd_name == 'uname': # Choose opt...
python
def sense(self): """ Launch a command in the 'senses' List, and update the current state.""" cmd_name = random.choice(self.senses) param = '' if cmd_name == 'ls': if random.randint(0, 1): param = '-l' elif cmd_name == 'uname': # Choose opt...
[ "def", "sense", "(", "self", ")", ":", "cmd_name", "=", "random", ".", "choice", "(", "self", ".", "senses", ")", "param", "=", "''", "if", "cmd_name", "==", "'ls'", ":", "if", "random", ".", "randint", "(", "0", ",", "1", ")", ":", "param", "=",...
Launch a command in the 'senses' List, and update the current state.
[ "Launch", "a", "command", "in", "the", "senses", "List", "and", "update", "the", "current", "state", "." ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/client/baits/shared/shell.py#L102-L117
train
Launch a command in the sense list and update the current state.
honeynet/beeswarm
beeswarm/drones/client/baits/shared/shell.py
Commands.decide
def decide(self): """ Choose the next command to execute, and its parameters, based on the current state. """ next_command_name = random.choice(self.COMMAND_MAP[self.state['last_command']]) param = '' if next_command_name == 'cd': try: par...
python
def decide(self): """ Choose the next command to execute, and its parameters, based on the current state. """ next_command_name = random.choice(self.COMMAND_MAP[self.state['last_command']]) param = '' if next_command_name == 'cd': try: par...
[ "def", "decide", "(", "self", ")", ":", "next_command_name", "=", "random", ".", "choice", "(", "self", ".", "COMMAND_MAP", "[", "self", ".", "state", "[", "'last_command'", "]", "]", ")", "param", "=", "''", "if", "next_command_name", "==", "'cd'", ":",...
Choose the next command to execute, and its parameters, based on the current state.
[ "Choose", "the", "next", "command", "to", "execute", "and", "its", "parameters", "based", "on", "the", "current", "state", "." ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/client/baits/shared/shell.py#L119-L164
train
Choose the next command to execute and its parameters based on the current state.
honeynet/beeswarm
beeswarm/drones/client/baits/shared/shell.py
Commands.act
def act(self, cmd_name, params=None): """ Run the specified command with its parameters.""" command = getattr(self, cmd_name) if params: command(params) else: command()
python
def act(self, cmd_name, params=None): """ Run the specified command with its parameters.""" command = getattr(self, cmd_name) if params: command(params) else: command()
[ "def", "act", "(", "self", ",", "cmd_name", ",", "params", "=", "None", ")", ":", "command", "=", "getattr", "(", "self", ",", "cmd_name", ")", "if", "params", ":", "command", "(", "params", ")", "else", ":", "command", "(", ")" ]
Run the specified command with its parameters.
[ "Run", "the", "specified", "command", "with", "its", "parameters", "." ]
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/client/baits/shared/shell.py#L166-L173
train
Run the specified command with its parameters.
marselester/json-log-formatter
json_log_formatter/__init__.py
JSONFormatter.json_record
def json_record(self, message, extra, record): """Prepares a JSON payload which will be logged. Override this method to change JSON log format. :param message: Log message, e.g., `logger.info(msg='Sign up')`. :param extra: Dictionary that was passed as `extra` param `logger...
python
def json_record(self, message, extra, record): """Prepares a JSON payload which will be logged. Override this method to change JSON log format. :param message: Log message, e.g., `logger.info(msg='Sign up')`. :param extra: Dictionary that was passed as `extra` param `logger...
[ "def", "json_record", "(", "self", ",", "message", ",", "extra", ",", "record", ")", ":", "extra", "[", "'message'", "]", "=", "message", "if", "'time'", "not", "in", "extra", ":", "extra", "[", "'time'", "]", "=", "datetime", ".", "utcnow", "(", ")"...
Prepares a JSON payload which will be logged. Override this method to change JSON log format. :param message: Log message, e.g., `logger.info(msg='Sign up')`. :param extra: Dictionary that was passed as `extra` param `logger.info('Sign up', extra={'referral_code': '52d6ce'})`. ...
[ "Prepares", "a", "JSON", "payload", "which", "will", "be", "logged", "." ]
2db6d5bf025486b0fb690d85e320d01dba614c0c
https://github.com/marselester/json-log-formatter/blob/2db6d5bf025486b0fb690d85e320d01dba614c0c/json_log_formatter/__init__.py#L94-L113
train
Prepares a JSON payload which will be logged.
marselester/json-log-formatter
json_log_formatter/__init__.py
JSONFormatter.mutate_json_record
def mutate_json_record(self, json_record): """Override it to convert fields of `json_record` to needed types. Default implementation converts `datetime` to string in ISO8601 format. """ for attr_name in json_record: attr = json_record[attr_name] if isinstance(at...
python
def mutate_json_record(self, json_record): """Override it to convert fields of `json_record` to needed types. Default implementation converts `datetime` to string in ISO8601 format. """ for attr_name in json_record: attr = json_record[attr_name] if isinstance(at...
[ "def", "mutate_json_record", "(", "self", ",", "json_record", ")", ":", "for", "attr_name", "in", "json_record", ":", "attr", "=", "json_record", "[", "attr_name", "]", "if", "isinstance", "(", "attr", ",", "datetime", ")", ":", "json_record", "[", "attr_nam...
Override it to convert fields of `json_record` to needed types. Default implementation converts `datetime` to string in ISO8601 format.
[ "Override", "it", "to", "convert", "fields", "of", "json_record", "to", "needed", "types", "." ]
2db6d5bf025486b0fb690d85e320d01dba614c0c
https://github.com/marselester/json-log-formatter/blob/2db6d5bf025486b0fb690d85e320d01dba614c0c/json_log_formatter/__init__.py#L115-L125
train
Override it to convert fields of json_record to needed types.