id
int32
0
252k
repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
51
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
244,700
TheHive-Project/Cortex-Analyzers
analyzers/BackscatterIO/backscatter-io.py
BackscatterAnalyzer.run
def run(self): """Run the process to get observation data from Backscatter.io.""" kwargs = {'query': self.get_data()} if self.data_type == "ip": kwargs.update({'query_type': 'ip'}) elif self.data_type == "network": kwargs.update({'query_type': 'network'}) ...
python
def run(self): kwargs = {'query': self.get_data()} if self.data_type == "ip": kwargs.update({'query_type': 'ip'}) elif self.data_type == "network": kwargs.update({'query_type': 'network'}) elif self.data_type == 'autonomous-system': kwargs.update({'que...
[ "def", "run", "(", "self", ")", ":", "kwargs", "=", "{", "'query'", ":", "self", ".", "get_data", "(", ")", "}", "if", "self", ".", "data_type", "==", "\"ip\"", ":", "kwargs", ".", "update", "(", "{", "'query_type'", ":", "'ip'", "}", ")", "elif", ...
Run the process to get observation data from Backscatter.io.
[ "Run", "the", "process", "to", "get", "observation", "data", "from", "Backscatter", ".", "io", "." ]
8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf
https://github.com/TheHive-Project/Cortex-Analyzers/blob/8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf/analyzers/BackscatterIO/backscatter-io.py#L28-L50
244,701
TheHive-Project/Cortex-Analyzers
analyzers/BackscatterIO/backscatter-io.py
BackscatterAnalyzer.summary
def summary(self, raw): """Use the Backscatter.io summary data to create a view.""" taxonomies = list() level = 'info' namespace = 'Backscatter.io' if self.service == 'observations': summary = raw.get('results', dict()).get('summary', dict()) taxonomies =...
python
def summary(self, raw): taxonomies = list() level = 'info' namespace = 'Backscatter.io' if self.service == 'observations': summary = raw.get('results', dict()).get('summary', dict()) taxonomies = taxonomies + [ self.build_taxonomy(level, namespace...
[ "def", "summary", "(", "self", ",", "raw", ")", ":", "taxonomies", "=", "list", "(", ")", "level", "=", "'info'", "namespace", "=", "'Backscatter.io'", "if", "self", ".", "service", "==", "'observations'", ":", "summary", "=", "raw", ".", "get", "(", "...
Use the Backscatter.io summary data to create a view.
[ "Use", "the", "Backscatter", ".", "io", "summary", "data", "to", "create", "a", "view", "." ]
8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf
https://github.com/TheHive-Project/Cortex-Analyzers/blob/8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf/analyzers/BackscatterIO/backscatter-io.py#L52-L97
244,702
TheHive-Project/Cortex-Analyzers
analyzers/MaxMind/maxminddb/decoder.py
Decoder.decode
def decode(self, offset): """Decode a section of the data section starting at offset Arguments: offset -- the location of the data structure to decode """ new_offset = offset + 1 (ctrl_byte,) = struct.unpack(b'!B', self._buffer[offset:new_offset]) type_num = ctrl...
python
def decode(self, offset): new_offset = offset + 1 (ctrl_byte,) = struct.unpack(b'!B', self._buffer[offset:new_offset]) type_num = ctrl_byte >> 5 # Extended type if not type_num: (type_num, new_offset) = self._read_extended(new_offset) (size, new_offset) = sel...
[ "def", "decode", "(", "self", ",", "offset", ")", ":", "new_offset", "=", "offset", "+", "1", "(", "ctrl_byte", ",", ")", "=", "struct", ".", "unpack", "(", "b'!B'", ",", "self", ".", "_buffer", "[", "offset", ":", "new_offset", "]", ")", "type_num",...
Decode a section of the data section starting at offset Arguments: offset -- the location of the data structure to decode
[ "Decode", "a", "section", "of", "the", "data", "section", "starting", "at", "offset" ]
8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf
https://github.com/TheHive-Project/Cortex-Analyzers/blob/8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf/analyzers/MaxMind/maxminddb/decoder.py#L116-L131
244,703
TheHive-Project/Cortex-Analyzers
analyzers/VMRay/vmrayclient.py
VMRayClient.get_sample
def get_sample(self, samplehash): """ Downloads information about a sample using a given hash. :param samplehash: hash to search for. Has to be either md5, sha1 or sha256 :type samplehash: str :returns: Dictionary of results :rtype: dict """ apiurl = '/re...
python
def get_sample(self, samplehash): apiurl = '/rest/sample/' if len(samplehash) == 32: # MD5 apiurl += 'md5/' elif len(samplehash) == 40: # SHA1 apiurl += 'sha1/' elif len(samplehash) == 64: # SHA256 apiurl += 'sha256/' else: raise...
[ "def", "get_sample", "(", "self", ",", "samplehash", ")", ":", "apiurl", "=", "'/rest/sample/'", "if", "len", "(", "samplehash", ")", "==", "32", ":", "# MD5", "apiurl", "+=", "'md5/'", "elif", "len", "(", "samplehash", ")", "==", "40", ":", "# SHA1", ...
Downloads information about a sample using a given hash. :param samplehash: hash to search for. Has to be either md5, sha1 or sha256 :type samplehash: str :returns: Dictionary of results :rtype: dict
[ "Downloads", "information", "about", "a", "sample", "using", "a", "given", "hash", "." ]
8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf
https://github.com/TheHive-Project/Cortex-Analyzers/blob/8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf/analyzers/VMRay/vmrayclient.py#L69-L93
244,704
TheHive-Project/Cortex-Analyzers
analyzers/VMRay/vmrayclient.py
VMRayClient.submit_sample
def submit_sample(self, filepath, filename, tags=['TheHive']): """ Uploads a new sample to VMRay api. Filename gets sent base64 encoded. :param filepath: path to sample :type filepath: str :param filename: filename of the original file :type filename: str :param ...
python
def submit_sample(self, filepath, filename, tags=['TheHive']): apiurl = '/rest/sample/submit?sample_file' params = {'sample_filename_b64enc': base64.b64encode(filename.encode('utf-8')), 'reanalyze': self.reanalyze} if tags: params['tags'] = ','.join(tags) i...
[ "def", "submit_sample", "(", "self", ",", "filepath", ",", "filename", ",", "tags", "=", "[", "'TheHive'", "]", ")", ":", "apiurl", "=", "'/rest/sample/submit?sample_file'", "params", "=", "{", "'sample_filename_b64enc'", ":", "base64", ".", "b64encode", "(", ...
Uploads a new sample to VMRay api. Filename gets sent base64 encoded. :param filepath: path to sample :type filepath: str :param filename: filename of the original file :type filename: str :param tags: List of tags to apply to the sample :type tags: list(str) :re...
[ "Uploads", "a", "new", "sample", "to", "VMRay", "api", ".", "Filename", "gets", "sent", "base64", "encoded", "." ]
8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf
https://github.com/TheHive-Project/Cortex-Analyzers/blob/8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf/analyzers/VMRay/vmrayclient.py#L95-L124
244,705
TheHive-Project/Cortex-Analyzers
analyzers/FileInfo/submodules/submodule_manalyze.py
ManalyzeSubmodule.build_results
def build_results(self, results): """Properly format the results""" self.add_result_subsection( 'Exploit mitigation techniques', { 'level': results.get('Plugins', {}).get('mitigation', {}).get('level', None), 'summary': results.get('Plugins', {}).g...
python
def build_results(self, results): self.add_result_subsection( 'Exploit mitigation techniques', { 'level': results.get('Plugins', {}).get('mitigation', {}).get('level', None), 'summary': results.get('Plugins', {}).get('mitigation', {}).get('summary', None),...
[ "def", "build_results", "(", "self", ",", "results", ")", ":", "self", ".", "add_result_subsection", "(", "'Exploit mitigation techniques'", ",", "{", "'level'", ":", "results", ".", "get", "(", "'Plugins'", ",", "{", "}", ")", ".", "get", "(", "'mitigation'...
Properly format the results
[ "Properly", "format", "the", "results" ]
8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf
https://github.com/TheHive-Project/Cortex-Analyzers/blob/8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf/analyzers/FileInfo/submodules/submodule_manalyze.py#L65-L107
244,706
TheHive-Project/Cortex-Analyzers
analyzers/MaxMind/ipaddr.py
v4_int_to_packed
def v4_int_to_packed(address): """The binary representation of this address. Args: address: An integer representation of an IPv4 IP address. Returns: The binary representation of this address. Raises: ValueError: If the integer is too large to be an IPv4 IP address. ...
python
def v4_int_to_packed(address): if address > _BaseV4._ALL_ONES: raise ValueError('Address too large for IPv4') return Bytes(struct.pack('!I', address))
[ "def", "v4_int_to_packed", "(", "address", ")", ":", "if", "address", ">", "_BaseV4", ".", "_ALL_ONES", ":", "raise", "ValueError", "(", "'Address too large for IPv4'", ")", "return", "Bytes", "(", "struct", ".", "pack", "(", "'!I'", ",", "address", ")", ")"...
The binary representation of this address. Args: address: An integer representation of an IPv4 IP address. Returns: The binary representation of this address. Raises: ValueError: If the integer is too large to be an IPv4 IP address.
[ "The", "binary", "representation", "of", "this", "address", "." ]
8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf
https://github.com/TheHive-Project/Cortex-Analyzers/blob/8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf/analyzers/MaxMind/ipaddr.py#L122-L137
244,707
TheHive-Project/Cortex-Analyzers
analyzers/MaxMind/ipaddr.py
_get_prefix_length
def _get_prefix_length(number1, number2, bits): """Get the number of leading bits that are same for two numbers. Args: number1: an integer. number2: another integer. bits: the maximum number of bits to compare. Returns: The number of leading bits that are the same for two n...
python
def _get_prefix_length(number1, number2, bits): for i in range(bits): if number1 >> i == number2 >> i: return bits - i return 0
[ "def", "_get_prefix_length", "(", "number1", ",", "number2", ",", "bits", ")", ":", "for", "i", "in", "range", "(", "bits", ")", ":", "if", "number1", ">>", "i", "==", "number2", ">>", "i", ":", "return", "bits", "-", "i", "return", "0" ]
Get the number of leading bits that are same for two numbers. Args: number1: an integer. number2: another integer. bits: the maximum number of bits to compare. Returns: The number of leading bits that are the same for two numbers.
[ "Get", "the", "number", "of", "leading", "bits", "that", "are", "same", "for", "two", "numbers", "." ]
8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf
https://github.com/TheHive-Project/Cortex-Analyzers/blob/8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf/analyzers/MaxMind/ipaddr.py#L170-L185
244,708
TheHive-Project/Cortex-Analyzers
analyzers/MaxMind/ipaddr.py
_BaseNet._prefix_from_ip_int
def _prefix_from_ip_int(self, ip_int): """Return prefix length from a bitwise netmask. Args: ip_int: An integer, the netmask in expanded bitwise format. Returns: An integer, the prefix length. Raises: NetmaskValueError: If the input is not a valid n...
python
def _prefix_from_ip_int(self, ip_int): prefixlen = self._max_prefixlen while prefixlen: if ip_int & 1: break ip_int >>= 1 prefixlen -= 1 if ip_int == (1 << prefixlen) - 1: return prefixlen else: raise NetmaskVal...
[ "def", "_prefix_from_ip_int", "(", "self", ",", "ip_int", ")", ":", "prefixlen", "=", "self", ".", "_max_prefixlen", "while", "prefixlen", ":", "if", "ip_int", "&", "1", ":", "break", "ip_int", ">>=", "1", "prefixlen", "-=", "1", "if", "ip_int", "==", "(...
Return prefix length from a bitwise netmask. Args: ip_int: An integer, the netmask in expanded bitwise format. Returns: An integer, the prefix length. Raises: NetmaskValueError: If the input is not a valid netmask.
[ "Return", "prefix", "length", "from", "a", "bitwise", "netmask", "." ]
8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf
https://github.com/TheHive-Project/Cortex-Analyzers/blob/8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf/analyzers/MaxMind/ipaddr.py#L854-L877
244,709
TheHive-Project/Cortex-Analyzers
analyzers/MaxMind/ipaddr.py
_BaseNet._prefix_from_prefix_string
def _prefix_from_prefix_string(self, prefixlen_str): """Turn a prefix length string into an integer. Args: prefixlen_str: A decimal string containing the prefix length. Returns: The prefix length as an integer. Raises: NetmaskValueError: If the inpu...
python
def _prefix_from_prefix_string(self, prefixlen_str): try: if not _BaseV4._DECIMAL_DIGITS.issuperset(prefixlen_str): raise ValueError prefixlen = int(prefixlen_str) if not (0 <= prefixlen <= self._max_prefixlen): raise ValueError except V...
[ "def", "_prefix_from_prefix_string", "(", "self", ",", "prefixlen_str", ")", ":", "try", ":", "if", "not", "_BaseV4", ".", "_DECIMAL_DIGITS", ".", "issuperset", "(", "prefixlen_str", ")", ":", "raise", "ValueError", "prefixlen", "=", "int", "(", "prefixlen_str",...
Turn a prefix length string into an integer. Args: prefixlen_str: A decimal string containing the prefix length. Returns: The prefix length as an integer. Raises: NetmaskValueError: If the input is malformed or out of range.
[ "Turn", "a", "prefix", "length", "string", "into", "an", "integer", "." ]
8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf
https://github.com/TheHive-Project/Cortex-Analyzers/blob/8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf/analyzers/MaxMind/ipaddr.py#L879-L901
244,710
TheHive-Project/Cortex-Analyzers
analyzers/MaxMind/ipaddr.py
_BaseNet.masked
def masked(self): """Return the network object with the host bits masked out.""" return IPNetwork('%s/%d' % (self.network, self._prefixlen), version=self._version)
python
def masked(self): return IPNetwork('%s/%d' % (self.network, self._prefixlen), version=self._version)
[ "def", "masked", "(", "self", ")", ":", "return", "IPNetwork", "(", "'%s/%d'", "%", "(", "self", ".", "network", ",", "self", ".", "_prefixlen", ")", ",", "version", "=", "self", ".", "_version", ")" ]
Return the network object with the host bits masked out.
[ "Return", "the", "network", "object", "with", "the", "host", "bits", "masked", "out", "." ]
8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf
https://github.com/TheHive-Project/Cortex-Analyzers/blob/8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf/analyzers/MaxMind/ipaddr.py#L999-L1002
244,711
TheHive-Project/Cortex-Analyzers
analyzers/MaxMind/ipaddr.py
_BaseV6._string_from_ip_int
def _string_from_ip_int(self, ip_int=None): """Turns a 128-bit integer into hexadecimal notation. Args: ip_int: An integer, the IP address. Returns: A string, the hexadecimal representation of the address. Raises: ValueError: The address is bigger t...
python
def _string_from_ip_int(self, ip_int=None): if not ip_int and ip_int != 0: ip_int = int(self._ip) if ip_int > self._ALL_ONES: raise ValueError('IPv6 address is too large') hex_str = '%032x' % ip_int hextets = [] for x in range(0, 32, 4): hext...
[ "def", "_string_from_ip_int", "(", "self", ",", "ip_int", "=", "None", ")", ":", "if", "not", "ip_int", "and", "ip_int", "!=", "0", ":", "ip_int", "=", "int", "(", "self", ".", "_ip", ")", "if", "ip_int", ">", "self", ".", "_ALL_ONES", ":", "raise", ...
Turns a 128-bit integer into hexadecimal notation. Args: ip_int: An integer, the IP address. Returns: A string, the hexadecimal representation of the address. Raises: ValueError: The address is bigger than 128 bits of all ones.
[ "Turns", "a", "128", "-", "bit", "integer", "into", "hexadecimal", "notation", "." ]
8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf
https://github.com/TheHive-Project/Cortex-Analyzers/blob/8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf/analyzers/MaxMind/ipaddr.py#L1532-L1557
244,712
TheHive-Project/Cortex-Analyzers
analyzers/Malwares/malwares_api.py
Api.scan_file
def scan_file(self, this_file, this_filename): """ Submit a file to be scanned by Malwares :param this_file: File to be scanned (200MB file size limit) :param this_filename: Filename for scanned file :return: JSON response that contains scan_id and permalink. """ params ...
python
def scan_file(self, this_file, this_filename): params = { 'api_key': self.api_key, 'filename': this_filename } try: files = {'file': (this_file.name, open(this_file.name, 'rb'), 'application/octet-stream')} except TypeError as e: return dic...
[ "def", "scan_file", "(", "self", ",", "this_file", ",", "this_filename", ")", ":", "params", "=", "{", "'api_key'", ":", "self", ".", "api_key", ",", "'filename'", ":", "this_filename", "}", "try", ":", "files", "=", "{", "'file'", ":", "(", "this_file",...
Submit a file to be scanned by Malwares :param this_file: File to be scanned (200MB file size limit) :param this_filename: Filename for scanned file :return: JSON response that contains scan_id and permalink.
[ "Submit", "a", "file", "to", "be", "scanned", "by", "Malwares" ]
8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf
https://github.com/TheHive-Project/Cortex-Analyzers/blob/8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf/analyzers/Malwares/malwares_api.py#L17-L38
244,713
TheHive-Project/Cortex-Analyzers
analyzers/GoogleSafebrowsing/safebrowsing.py
SafebrowsingClient.__prepare_body
def __prepare_body(self, search_value, search_type='url'): """ Prepares the http body for querying safebrowsing api. Maybe the list need to get adjusted. :param search_value: value to search for :type search_value: str :param search_type: 'url' or 'ip' :type search_type:...
python
def __prepare_body(self, search_value, search_type='url'): body = { 'client': { 'clientId': self.client_id, 'clientVersion': self.client_version } } if search_type == 'url': data = { 'threatTypes': [ ...
[ "def", "__prepare_body", "(", "self", ",", "search_value", ",", "search_type", "=", "'url'", ")", ":", "body", "=", "{", "'client'", ":", "{", "'clientId'", ":", "self", ".", "client_id", ",", "'clientVersion'", ":", "self", ".", "client_version", "}", "}"...
Prepares the http body for querying safebrowsing api. Maybe the list need to get adjusted. :param search_value: value to search for :type search_value: str :param search_type: 'url' or 'ip' :type search_type: str :returns: http body as dict :rtype: dict
[ "Prepares", "the", "http", "body", "for", "querying", "safebrowsing", "api", ".", "Maybe", "the", "list", "need", "to", "get", "adjusted", "." ]
8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf
https://github.com/TheHive-Project/Cortex-Analyzers/blob/8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf/analyzers/GoogleSafebrowsing/safebrowsing.py#L26-L63
244,714
TheHive-Project/Cortex-Analyzers
analyzers/Robtex/robtex.py
RobtexAnalyzer.query_rpdns
def query_rpdns(self): """ Queries robtex reverse pdns-api using an ip as parameter :return: Dictionary containing results :rtype: list """ results = requests.get('https://freeapi.robtex.com/pdns/reverse/{}'.format(self.get_data())).text.split('\r\n') jsonresults...
python
def query_rpdns(self): results = requests.get('https://freeapi.robtex.com/pdns/reverse/{}'.format(self.get_data())).text.split('\r\n') jsonresults = [] for idx, r in enumerate(results): if len(r) > 0: jsonresults.append(json.loads(r)) return jsonresults
[ "def", "query_rpdns", "(", "self", ")", ":", "results", "=", "requests", ".", "get", "(", "'https://freeapi.robtex.com/pdns/reverse/{}'", ".", "format", "(", "self", ".", "get_data", "(", ")", ")", ")", ".", "text", ".", "split", "(", "'\\r\\n'", ")", "jso...
Queries robtex reverse pdns-api using an ip as parameter :return: Dictionary containing results :rtype: list
[ "Queries", "robtex", "reverse", "pdns", "-", "api", "using", "an", "ip", "as", "parameter" ]
8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf
https://github.com/TheHive-Project/Cortex-Analyzers/blob/8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf/analyzers/Robtex/robtex.py#L22-L34
244,715
TheHive-Project/Cortex-Analyzers
analyzers/FileInfo/submodules/submodule_rtfobj.py
RTFObjectSubmodule.module_summary
def module_summary(self): """Count the malicious and suspicious sections, check for CVE description""" suspicious = 0 malicious = 0 count = 0 cve = False taxonomies = [] for section in self.results: if section['submodule_section_content']['class'] == ...
python
def module_summary(self): suspicious = 0 malicious = 0 count = 0 cve = False taxonomies = [] for section in self.results: if section['submodule_section_content']['class'] == 'malicious': malicious += 1 elif section['submodule_secti...
[ "def", "module_summary", "(", "self", ")", ":", "suspicious", "=", "0", "malicious", "=", "0", "count", "=", "0", "cve", "=", "False", "taxonomies", "=", "[", "]", "for", "section", "in", "self", ".", "results", ":", "if", "section", "[", "'submodule_s...
Count the malicious and suspicious sections, check for CVE description
[ "Count", "the", "malicious", "and", "suspicious", "sections", "check", "for", "CVE", "description" ]
8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf
https://github.com/TheHive-Project/Cortex-Analyzers/blob/8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf/analyzers/FileInfo/submodules/submodule_rtfobj.py#L20-L50
244,716
TheHive-Project/Cortex-Analyzers
analyzers/TorProject/tor_project.py
TorProjectClient.search_tor_node
def search_tor_node(self, ip): """Lookup an IP address to check if it is a known tor exit node. :param ip: The IP address to lookup :type ip: str :return: Data relative to the tor node. If `ip`is a tor exit node it will contain a `node` key with the hash of the node and...
python
def search_tor_node(self, ip): data = {} tmp = {} present = datetime.utcnow().replace(tzinfo=pytz.utc) for line in self._get_raw_data().splitlines(): params = line.split(' ') if params[0] == 'ExitNode': tmp['node'] = params[1] elif para...
[ "def", "search_tor_node", "(", "self", ",", "ip", ")", ":", "data", "=", "{", "}", "tmp", "=", "{", "}", "present", "=", "datetime", ".", "utcnow", "(", ")", ".", "replace", "(", "tzinfo", "=", "pytz", ".", "utc", ")", "for", "line", "in", "self"...
Lookup an IP address to check if it is a known tor exit node. :param ip: The IP address to lookup :type ip: str :return: Data relative to the tor node. If `ip`is a tor exit node it will contain a `node` key with the hash of the node and a `last_status` key with...
[ "Lookup", "an", "IP", "address", "to", "check", "if", "it", "is", "a", "known", "tor", "exit", "node", "." ]
8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf
https://github.com/TheHive-Project/Cortex-Analyzers/blob/8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf/analyzers/TorProject/tor_project.py#L52-L80
244,717
TheHive-Project/Cortex-Analyzers
analyzers/Censys/censys_analyzer.py
CensysAnalyzer.search_hosts
def search_hosts(self, ip): """ Searches for a host using its ipv4 address :param ip: ipv4 address as string :type ip: str :return: dict """ c = CensysIPv4(api_id=self.__uid, api_secret=self.__api_key) return c.view(ip)
python
def search_hosts(self, ip): c = CensysIPv4(api_id=self.__uid, api_secret=self.__api_key) return c.view(ip)
[ "def", "search_hosts", "(", "self", ",", "ip", ")", ":", "c", "=", "CensysIPv4", "(", "api_id", "=", "self", ".", "__uid", ",", "api_secret", "=", "self", ".", "__api_key", ")", "return", "c", ".", "view", "(", "ip", ")" ]
Searches for a host using its ipv4 address :param ip: ipv4 address as string :type ip: str :return: dict
[ "Searches", "for", "a", "host", "using", "its", "ipv4", "address" ]
8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf
https://github.com/TheHive-Project/Cortex-Analyzers/blob/8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf/analyzers/Censys/censys_analyzer.py#L24-L33
244,718
TheHive-Project/Cortex-Analyzers
analyzers/Censys/censys_analyzer.py
CensysAnalyzer.search_certificate
def search_certificate(self, hash): """ Searches for a specific certificate using its hash :param hash: certificate hash :type hash: str :return: dict """ c = CensysCertificates(api_id=self.__uid, api_secret=self.__api_key) return c.view(hash)
python
def search_certificate(self, hash): c = CensysCertificates(api_id=self.__uid, api_secret=self.__api_key) return c.view(hash)
[ "def", "search_certificate", "(", "self", ",", "hash", ")", ":", "c", "=", "CensysCertificates", "(", "api_id", "=", "self", ".", "__uid", ",", "api_secret", "=", "self", ".", "__api_key", ")", "return", "c", ".", "view", "(", "hash", ")" ]
Searches for a specific certificate using its hash :param hash: certificate hash :type hash: str :return: dict
[ "Searches", "for", "a", "specific", "certificate", "using", "its", "hash" ]
8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf
https://github.com/TheHive-Project/Cortex-Analyzers/blob/8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf/analyzers/Censys/censys_analyzer.py#L35-L44
244,719
TheHive-Project/Cortex-Analyzers
analyzers/StopForumSpam/stopforumspam_client.py
StopforumspamClient.get_data
def get_data(self, datatype, data): """ Look for an IP address or an email address in the spammer database. :param datatype: Which type of data is to be looked up. Allowed values are 'ip' or 'mail'. :param data: The value to be looked up through the API. :type d...
python
def get_data(self, datatype, data): result = {} params = StopforumspamClient._set_payload(datatype, data) response = self.client.get( 'https://api.stopforumspam.org/api', params=params, proxies=self.proxies) response.raise_for_status() report = response.js...
[ "def", "get_data", "(", "self", ",", "datatype", ",", "data", ")", ":", "result", "=", "{", "}", "params", "=", "StopforumspamClient", ".", "_set_payload", "(", "datatype", ",", "data", ")", "response", "=", "self", ".", "client", ".", "get", "(", "'ht...
Look for an IP address or an email address in the spammer database. :param datatype: Which type of data is to be looked up. Allowed values are 'ip' or 'mail'. :param data: The value to be looked up through the API. :type datatype: str :type data: str :re...
[ "Look", "for", "an", "IP", "address", "or", "an", "email", "address", "in", "the", "spammer", "database", "." ]
8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf
https://github.com/TheHive-Project/Cortex-Analyzers/blob/8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf/analyzers/StopForumSpam/stopforumspam_client.py#L47-L70
244,720
sdispater/orator
orator/orm/factory.py
Factory.construct
def construct(cls, faker, path_to_factories=None): """ Create a new factory container. :param faker: A faker generator instance :type faker: faker.Generator :param path_to_factories: The path to factories :type path_to_factories: str :rtype: Factory """...
python
def construct(cls, faker, path_to_factories=None): factory = faker.__class__() if path_to_factories is not None and os.path.isdir(path_to_factories): for filename in os.listdir(path_to_factories): if os.path.isfile(filename): cls._resolve(path_to_factorie...
[ "def", "construct", "(", "cls", ",", "faker", ",", "path_to_factories", "=", "None", ")", ":", "factory", "=", "faker", ".", "__class__", "(", ")", "if", "path_to_factories", "is", "not", "None", "and", "os", ".", "path", ".", "isdir", "(", "path_to_fact...
Create a new factory container. :param faker: A faker generator instance :type faker: faker.Generator :param path_to_factories: The path to factories :type path_to_factories: str :rtype: Factory
[ "Create", "a", "new", "factory", "container", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/factory.py#L25-L44
244,721
sdispater/orator
orator/orm/factory.py
Factory.define
def define(self, klass, name="default"): """ Define a class with a given set of attributes. :param klass: The class :type klass: class :param name: The short name :type name: str """ def decorate(func): @wraps(func) def wrapped(*...
python
def define(self, klass, name="default"): def decorate(func): @wraps(func) def wrapped(*args, **kwargs): return func(*args, **kwargs) self.register(klass, func, name=name) return wrapped return decorate
[ "def", "define", "(", "self", ",", "klass", ",", "name", "=", "\"default\"", ")", ":", "def", "decorate", "(", "func", ")", ":", "@", "wraps", "(", "func", ")", "def", "wrapped", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "return", "fun...
Define a class with a given set of attributes. :param klass: The class :type klass: class :param name: The short name :type name: str
[ "Define", "a", "class", "with", "a", "given", "set", "of", "attributes", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/factory.py#L58-L78
244,722
sdispater/orator
orator/orm/factory.py
Factory.create_as
def create_as(self, klass, name, **attributes): """ Create an instance of the given model and type and persist it to the database. :param klass: The class :type klass: class :param name: The type :type name: str :param attributes: The instance attributes ...
python
def create_as(self, klass, name, **attributes): return self.of(klass, name).create(**attributes)
[ "def", "create_as", "(", "self", ",", "klass", ",", "name", ",", "*", "*", "attributes", ")", ":", "return", "self", ".", "of", "(", "klass", ",", "name", ")", ".", "create", "(", "*", "*", "attributes", ")" ]
Create an instance of the given model and type and persist it to the database. :param klass: The class :type klass: class :param name: The type :type name: str :param attributes: The instance attributes :type attributes: dict :return: mixed
[ "Create", "an", "instance", "of", "the", "given", "model", "and", "type", "and", "persist", "it", "to", "the", "database", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/factory.py#L127-L142
244,723
sdispater/orator
orator/orm/factory.py
Factory.make_as
def make_as(self, klass, name, **attributes): """ Create an instance of the given model and type. :param klass: The class :type klass: class :param name: The type :type name: str :param attributes: The instance attributes :type attributes: dict ...
python
def make_as(self, klass, name, **attributes): return self.of(klass, name).make(**attributes)
[ "def", "make_as", "(", "self", ",", "klass", ",", "name", ",", "*", "*", "attributes", ")", ":", "return", "self", ".", "of", "(", "klass", ",", "name", ")", ".", "make", "(", "*", "*", "attributes", ")" ]
Create an instance of the given model and type. :param klass: The class :type klass: class :param name: The type :type name: str :param attributes: The instance attributes :type attributes: dict :return: mixed
[ "Create", "an", "instance", "of", "the", "given", "model", "and", "type", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/factory.py#L158-L173
244,724
sdispater/orator
orator/orm/factory.py
Factory.of
def of(self, klass, name="default"): """ Create a builder for the given model. :param klass: The class :type klass: class :param name: The type :type name: str :return: orator.orm.factory_builder.FactoryBuilder """ return FactoryBuilder( ...
python
def of(self, klass, name="default"): return FactoryBuilder( klass, name, self._definitions, self._faker, self._resolver )
[ "def", "of", "(", "self", ",", "klass", ",", "name", "=", "\"default\"", ")", ":", "return", "FactoryBuilder", "(", "klass", ",", "name", ",", "self", ".", "_definitions", ",", "self", ".", "_faker", ",", "self", ".", "_resolver", ")" ]
Create a builder for the given model. :param klass: The class :type klass: class :param name: The type :type name: str :return: orator.orm.factory_builder.FactoryBuilder
[ "Create", "a", "builder", "for", "the", "given", "model", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/factory.py#L213-L227
244,725
sdispater/orator
orator/orm/factory.py
Factory.build
def build(self, klass, name="default", amount=None): """ Makes a factory builder with a specified amount. :param klass: The class :type klass: class :param name: The type :type name: str :param amount: The number of models to create :type amount: int ...
python
def build(self, klass, name="default", amount=None): if amount is None: if isinstance(name, int): amount = name name = "default" else: amount = 1 return self.of(klass, name).times(amount)
[ "def", "build", "(", "self", ",", "klass", ",", "name", "=", "\"default\"", ",", "amount", "=", "None", ")", ":", "if", "amount", "is", "None", ":", "if", "isinstance", "(", "name", ",", "int", ")", ":", "amount", "=", "name", "name", "=", "\"defau...
Makes a factory builder with a specified amount. :param klass: The class :type klass: class :param name: The type :type name: str :param amount: The number of models to create :type amount: int :return: mixed
[ "Makes", "a", "factory", "builder", "with", "a", "specified", "amount", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/factory.py#L229-L251
244,726
sdispater/orator
orator/schema/grammars/grammar.py
SchemaGrammar._get_renamed_diff
def _get_renamed_diff(self, blueprint, command, column, schema): """ Get a new column instance with the new column name. :param blueprint: The blueprint :type blueprint: Blueprint :param command: The command :type command: Fluent :param column: The column ...
python
def _get_renamed_diff(self, blueprint, command, column, schema): table_diff = self._get_table_diff(blueprint, schema) return self._set_renamed_columns(table_diff, command, column)
[ "def", "_get_renamed_diff", "(", "self", ",", "blueprint", ",", "command", ",", "column", ",", "schema", ")", ":", "table_diff", "=", "self", ".", "_get_table_diff", "(", "blueprint", ",", "schema", ")", "return", "self", ".", "_set_renamed_columns", "(", "t...
Get a new column instance with the new column name. :param blueprint: The blueprint :type blueprint: Blueprint :param command: The command :type command: Fluent :param column: The column :type column: orator.dbal.Column :param schema: The schema :type ...
[ "Get", "a", "new", "column", "instance", "with", "the", "new", "column", "name", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/grammars/grammar.py#L43-L63
244,727
sdispater/orator
orator/schema/grammars/grammar.py
SchemaGrammar._set_renamed_columns
def _set_renamed_columns(self, table_diff, command, column): """ Set the renamed columns on the table diff. :rtype: orator.dbal.TableDiff """ new_column = Column(command.to, column.get_type(), column.to_dict()) table_diff.renamed_columns = {command.from_: new_column} ...
python
def _set_renamed_columns(self, table_diff, command, column): new_column = Column(command.to, column.get_type(), column.to_dict()) table_diff.renamed_columns = {command.from_: new_column} return table_diff
[ "def", "_set_renamed_columns", "(", "self", ",", "table_diff", ",", "command", ",", "column", ")", ":", "new_column", "=", "Column", "(", "command", ".", "to", ",", "column", ".", "get_type", "(", ")", ",", "column", ".", "to_dict", "(", ")", ")", "tab...
Set the renamed columns on the table diff. :rtype: orator.dbal.TableDiff
[ "Set", "the", "renamed", "columns", "on", "the", "table", "diff", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/grammars/grammar.py#L65-L75
244,728
sdispater/orator
orator/schema/grammars/grammar.py
SchemaGrammar._get_command_by_name
def _get_command_by_name(self, blueprint, name): """ Get the primary key command it it exists. """ commands = self._get_commands_by_name(blueprint, name) if len(commands): return commands[0]
python
def _get_command_by_name(self, blueprint, name): commands = self._get_commands_by_name(blueprint, name) if len(commands): return commands[0]
[ "def", "_get_command_by_name", "(", "self", ",", "blueprint", ",", "name", ")", ":", "commands", "=", "self", ".", "_get_commands_by_name", "(", "blueprint", ",", "name", ")", "if", "len", "(", "commands", ")", ":", "return", "commands", "[", "0", "]" ]
Get the primary key command it it exists.
[ "Get", "the", "primary", "key", "command", "it", "it", "exists", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/grammars/grammar.py#L143-L150
244,729
sdispater/orator
orator/schema/grammars/grammar.py
SchemaGrammar._get_commands_by_name
def _get_commands_by_name(self, blueprint, name): """ Get all of the commands with a given name. """ return list(filter(lambda value: value.name == name, blueprint.get_commands()))
python
def _get_commands_by_name(self, blueprint, name): return list(filter(lambda value: value.name == name, blueprint.get_commands()))
[ "def", "_get_commands_by_name", "(", "self", ",", "blueprint", ",", "name", ")", ":", "return", "list", "(", "filter", "(", "lambda", "value", ":", "value", ".", "name", "==", "name", ",", "blueprint", ".", "get_commands", "(", ")", ")", ")" ]
Get all of the commands with a given name.
[ "Get", "all", "of", "the", "commands", "with", "a", "given", "name", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/grammars/grammar.py#L152-L156
244,730
sdispater/orator
orator/schema/grammars/grammar.py
SchemaGrammar.prefix_list
def prefix_list(self, prefix, values): """ Add a prefix to a list of values. """ return list(map(lambda value: prefix + " " + value, values))
python
def prefix_list(self, prefix, values): return list(map(lambda value: prefix + " " + value, values))
[ "def", "prefix_list", "(", "self", ",", "prefix", ",", "values", ")", ":", "return", "list", "(", "map", "(", "lambda", "value", ":", "prefix", "+", "\" \"", "+", "value", ",", "values", ")", ")" ]
Add a prefix to a list of values.
[ "Add", "a", "prefix", "to", "a", "list", "of", "values", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/grammars/grammar.py#L169-L173
244,731
sdispater/orator
orator/schema/grammars/grammar.py
SchemaGrammar._get_default_value
def _get_default_value(self, value): """ Format a value so that it can be used in "default" clauses. """ if isinstance(value, QueryExpression): return value if isinstance(value, bool): return "'%s'" % int(value) return "'%s'" % value
python
def _get_default_value(self, value): if isinstance(value, QueryExpression): return value if isinstance(value, bool): return "'%s'" % int(value) return "'%s'" % value
[ "def", "_get_default_value", "(", "self", ",", "value", ")", ":", "if", "isinstance", "(", "value", ",", "QueryExpression", ")", ":", "return", "value", "if", "isinstance", "(", "value", ",", "bool", ")", ":", "return", "\"'%s'\"", "%", "int", "(", "valu...
Format a value so that it can be used in "default" clauses.
[ "Format", "a", "value", "so", "that", "it", "can", "be", "used", "in", "default", "clauses", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/grammars/grammar.py#L187-L197
244,732
sdispater/orator
orator/schema/grammars/grammar.py
SchemaGrammar._get_changed_diff
def _get_changed_diff(self, blueprint, schema): """ Get the table diffrence for the given changes. :param blueprint: The blueprint :type blueprint: Blueprint :param schema: The schema :type schema: orator.dbal.SchemaManager :rtype: orator.dbal.TableDiff ...
python
def _get_changed_diff(self, blueprint, schema): table = schema.list_table_details( self.get_table_prefix() + blueprint.get_table() ) return Comparator().diff_table( table, self._get_table_with_column_changes(blueprint, table) )
[ "def", "_get_changed_diff", "(", "self", ",", "blueprint", ",", "schema", ")", ":", "table", "=", "schema", ".", "list_table_details", "(", "self", ".", "get_table_prefix", "(", ")", "+", "blueprint", ".", "get_table", "(", ")", ")", "return", "Comparator", ...
Get the table diffrence for the given changes. :param blueprint: The blueprint :type blueprint: Blueprint :param schema: The schema :type schema: orator.dbal.SchemaManager :rtype: orator.dbal.TableDiff
[ "Get", "the", "table", "diffrence", "for", "the", "given", "changes", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/grammars/grammar.py#L237-L255
244,733
sdispater/orator
orator/schema/grammars/grammar.py
SchemaGrammar._get_table_with_column_changes
def _get_table_with_column_changes(self, blueprint, table): """ Get a copy of the given table after making the column changes. :param blueprint: The blueprint :type blueprint: Blueprint :type table: orator.dbal.table.Table :rtype: orator.dbal.table.Table """ ...
python
def _get_table_with_column_changes(self, blueprint, table): table = table.clone() for fluent in blueprint.get_changed_columns(): column = self._get_column_for_change(table, fluent) for key, value in fluent.get_attributes().items(): option = self._map_fluent_opti...
[ "def", "_get_table_with_column_changes", "(", "self", ",", "blueprint", ",", "table", ")", ":", "table", "=", "table", ".", "clone", "(", ")", "for", "fluent", "in", "blueprint", ".", "get_changed_columns", "(", ")", ":", "column", "=", "self", ".", "_get_...
Get a copy of the given table after making the column changes. :param blueprint: The blueprint :type blueprint: Blueprint :type table: orator.dbal.table.Table :rtype: orator.dbal.table.Table
[ "Get", "a", "copy", "of", "the", "given", "table", "after", "making", "the", "column", "changes", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/grammars/grammar.py#L257-L282
244,734
sdispater/orator
orator/schema/grammars/grammar.py
SchemaGrammar._get_column_for_change
def _get_column_for_change(self, table, fluent): """ Get the column instance for a column change. :type table: orator.dbal.table.Table :rtype: orator.dbal.column.Column """ return table.change_column( fluent.name, self._get_column_change_options(fluent) ...
python
def _get_column_for_change(self, table, fluent): return table.change_column( fluent.name, self._get_column_change_options(fluent) ).get_column(fluent.name)
[ "def", "_get_column_for_change", "(", "self", ",", "table", ",", "fluent", ")", ":", "return", "table", ".", "change_column", "(", "fluent", ".", "name", ",", "self", ".", "_get_column_change_options", "(", "fluent", ")", ")", ".", "get_column", "(", "fluent...
Get the column instance for a column change. :type table: orator.dbal.table.Table :rtype: orator.dbal.column.Column
[ "Get", "the", "column", "instance", "for", "a", "column", "change", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/grammars/grammar.py#L284-L294
244,735
sdispater/orator
orator/orm/relations/pivot.py
Pivot._get_delete_query
def _get_delete_query(self): """ Get the query builder for a delete operation on the pivot. :rtype: orator.orm.Builder """ foreign = self.get_attribute(self.__foreign_key) query = self.new_query().where(self.__foreign_key, foreign) return query.where(self.__oth...
python
def _get_delete_query(self): foreign = self.get_attribute(self.__foreign_key) query = self.new_query().where(self.__foreign_key, foreign) return query.where(self.__other_key, self.get_attribute(self.__other_key))
[ "def", "_get_delete_query", "(", "self", ")", ":", "foreign", "=", "self", ".", "get_attribute", "(", "self", ".", "__foreign_key", ")", "query", "=", "self", ".", "new_query", "(", ")", ".", "where", "(", "self", ".", "__foreign_key", ",", "foreign", ")...
Get the query builder for a delete operation on the pivot. :rtype: orator.orm.Builder
[ "Get", "the", "query", "builder", "for", "a", "delete", "operation", "on", "the", "pivot", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/pivot.py#L63-L73
244,736
sdispater/orator
orator/orm/relations/pivot.py
Pivot.set_pivot_keys
def set_pivot_keys(self, foreign_key, other_key): """ Set the key names for the pivot model instance """ self.__foreign_key = foreign_key self.__other_key = other_key return self
python
def set_pivot_keys(self, foreign_key, other_key): self.__foreign_key = foreign_key self.__other_key = other_key return self
[ "def", "set_pivot_keys", "(", "self", ",", "foreign_key", ",", "other_key", ")", ":", "self", ".", "__foreign_key", "=", "foreign_key", "self", ".", "__other_key", "=", "other_key", "return", "self" ]
Set the key names for the pivot model instance
[ "Set", "the", "key", "names", "for", "the", "pivot", "model", "instance" ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/pivot.py#L89-L96
244,737
sdispater/orator
orator/orm/factory_builder.py
FactoryBuilder.create
def create(self, **attributes): """ Create a collection of models and persist them to the database. :param attributes: The models attributes :type attributes: dict :return: mixed """ results = self.make(**attributes) if self._amount == 1: if...
python
def create(self, **attributes): results = self.make(**attributes) if self._amount == 1: if self._resolver: results.set_connection_resolver(self._resolver) results.save() else: if self._resolver: results.each(lambda r: r.set_co...
[ "def", "create", "(", "self", ",", "*", "*", "attributes", ")", ":", "results", "=", "self", ".", "make", "(", "*", "*", "attributes", ")", "if", "self", ".", "_amount", "==", "1", ":", "if", "self", ".", "_resolver", ":", "results", ".", "set_conn...
Create a collection of models and persist them to the database. :param attributes: The models attributes :type attributes: dict :return: mixed
[ "Create", "a", "collection", "of", "models", "and", "persist", "them", "to", "the", "database", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/factory_builder.py#L41-L64
244,738
sdispater/orator
orator/orm/factory_builder.py
FactoryBuilder.make
def make(self, **attributes): """ Create a collection of models. :param attributes: The models attributes :type attributes: dict :return: mixed """ if self._amount == 1: return self._make_instance(**attributes) else: results = [] ...
python
def make(self, **attributes): if self._amount == 1: return self._make_instance(**attributes) else: results = [] for _ in range(self._amount): results.append(self._make_instance(**attributes)) return Collection(results)
[ "def", "make", "(", "self", ",", "*", "*", "attributes", ")", ":", "if", "self", ".", "_amount", "==", "1", ":", "return", "self", ".", "_make_instance", "(", "*", "*", "attributes", ")", "else", ":", "results", "=", "[", "]", "for", "_", "in", "...
Create a collection of models. :param attributes: The models attributes :type attributes: dict :return: mixed
[ "Create", "a", "collection", "of", "models", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/factory_builder.py#L66-L83
244,739
sdispater/orator
orator/orm/factory_builder.py
FactoryBuilder._make_instance
def _make_instance(self, **attributes): """ Make an instance of the model with the given attributes. :param attributes: The models attributes :type attributes: dict :return: mixed """ definition = self._definitions[self._klass][self._name](self._faker) d...
python
def _make_instance(self, **attributes): definition = self._definitions[self._klass][self._name](self._faker) definition.update(attributes) instance = self._klass() instance.force_fill(**definition) return instance
[ "def", "_make_instance", "(", "self", ",", "*", "*", "attributes", ")", ":", "definition", "=", "self", ".", "_definitions", "[", "self", ".", "_klass", "]", "[", "self", ".", "_name", "]", "(", "self", ".", "_faker", ")", "definition", ".", "update", ...
Make an instance of the model with the given attributes. :param attributes: The models attributes :type attributes: dict :return: mixed
[ "Make", "an", "instance", "of", "the", "model", "with", "the", "given", "attributes", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/factory_builder.py#L85-L100
244,740
sdispater/orator
orator/connections/connection.py
run
def run(wrapped): """ Special decorator encapsulating query method. """ @wraps(wrapped) def _run(self, query, bindings=None, *args, **kwargs): self._reconnect_if_missing_connection() start = time.time() try: result = wrapped(self, query, bindings, *args, **kwarg...
python
def run(wrapped): @wraps(wrapped) def _run(self, query, bindings=None, *args, **kwargs): self._reconnect_if_missing_connection() start = time.time() try: result = wrapped(self, query, bindings, *args, **kwargs) except Exception as e: result = self._try_ag...
[ "def", "run", "(", "wrapped", ")", ":", "@", "wraps", "(", "wrapped", ")", "def", "_run", "(", "self", ",", "query", ",", "bindings", "=", "None", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "self", ".", "_reconnect_if_missing_connection", "...
Special decorator encapsulating query method.
[ "Special", "decorator", "encapsulating", "query", "method", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/connections/connection.py#L21-L43
244,741
sdispater/orator
orator/orm/relations/belongs_to_many.py
BelongsToMany.where_pivot
def where_pivot(self, column, operator=None, value=None, boolean="and"): """ Set a where clause for a pivot table column. :param column: The column of the where clause, can also be a QueryBuilder instance for sub where :type column: str|Builder :param operator: The operator of ...
python
def where_pivot(self, column, operator=None, value=None, boolean="and"): self._pivot_wheres.append([column, operator, value, boolean]) return self._query.where( "%s.%s" % (self._table, column), operator, value, boolean )
[ "def", "where_pivot", "(", "self", ",", "column", ",", "operator", "=", "None", ",", "value", "=", "None", ",", "boolean", "=", "\"and\"", ")", ":", "self", ".", "_pivot_wheres", ".", "append", "(", "[", "column", ",", "operator", ",", "value", ",", ...
Set a where clause for a pivot table column. :param column: The column of the where clause, can also be a QueryBuilder instance for sub where :type column: str|Builder :param operator: The operator of the where clause :type operator: str :param value: The value of the where cl...
[ "Set", "a", "where", "clause", "for", "a", "pivot", "table", "column", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L62-L85
244,742
sdispater/orator
orator/orm/relations/belongs_to_many.py
BelongsToMany.or_where_pivot
def or_where_pivot(self, column, operator=None, value=None): """ Set an or where clause for a pivot table column. :param column: The column of the where clause, can also be a QueryBuilder instance for sub where :type column: str|Builder :param operator: The operator of the wher...
python
def or_where_pivot(self, column, operator=None, value=None): return self.where_pivot(column, operator, value, "or")
[ "def", "or_where_pivot", "(", "self", ",", "column", ",", "operator", "=", "None", ",", "value", "=", "None", ")", ":", "return", "self", ".", "where_pivot", "(", "column", ",", "operator", ",", "value", ",", "\"or\"", ")" ]
Set an or where clause for a pivot table column. :param column: The column of the where clause, can also be a QueryBuilder instance for sub where :type column: str|Builder :param operator: The operator of the where clause :type operator: str :param value: The value of the wher...
[ "Set", "an", "or", "where", "clause", "for", "a", "pivot", "table", "column", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L87-L103
244,743
sdispater/orator
orator/orm/relations/belongs_to_many.py
BelongsToMany.first
def first(self, columns=None): """ Execute the query and get the first result. :type columns: list """ self._query.take(1) results = self.get(columns) if len(results) > 0: return results.first() return
python
def first(self, columns=None): self._query.take(1) results = self.get(columns) if len(results) > 0: return results.first() return
[ "def", "first", "(", "self", ",", "columns", "=", "None", ")", ":", "self", ".", "_query", ".", "take", "(", "1", ")", "results", "=", "self", ".", "get", "(", "columns", ")", "if", "len", "(", "results", ")", ">", "0", ":", "return", "results", ...
Execute the query and get the first result. :type columns: list
[ "Execute", "the", "query", "and", "get", "the", "first", "result", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L105-L118
244,744
sdispater/orator
orator/orm/relations/belongs_to_many.py
BelongsToMany.first_or_fail
def first_or_fail(self, columns=None): """ Execute the query and get the first result or raise an exception. :type columns: list :raises: ModelNotFound """ model = self.first(columns) if model is not None: return model raise ModelNotFound(se...
python
def first_or_fail(self, columns=None): model = self.first(columns) if model is not None: return model raise ModelNotFound(self._parent.__class__)
[ "def", "first_or_fail", "(", "self", ",", "columns", "=", "None", ")", ":", "model", "=", "self", ".", "first", "(", "columns", ")", "if", "model", "is", "not", "None", ":", "return", "model", "raise", "ModelNotFound", "(", "self", ".", "_parent", ".",...
Execute the query and get the first result or raise an exception. :type columns: list :raises: ModelNotFound
[ "Execute", "the", "query", "and", "get", "the", "first", "result", "or", "raise", "an", "exception", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L120-L132
244,745
sdispater/orator
orator/orm/relations/belongs_to_many.py
BelongsToMany._hydrate_pivot_relation
def _hydrate_pivot_relation(self, models): """ Hydrate the pivot table relationship on the models. :type models: list """ for model in models: pivot = self.new_existing_pivot(self._clean_pivot_attributes(model)) model.set_relation("pivot", pivot)
python
def _hydrate_pivot_relation(self, models): for model in models: pivot = self.new_existing_pivot(self._clean_pivot_attributes(model)) model.set_relation("pivot", pivot)
[ "def", "_hydrate_pivot_relation", "(", "self", ",", "models", ")", ":", "for", "model", "in", "models", ":", "pivot", "=", "self", ".", "new_existing_pivot", "(", "self", ".", "_clean_pivot_attributes", "(", "model", ")", ")", "model", ".", "set_relation", "...
Hydrate the pivot table relationship on the models. :type models: list
[ "Hydrate", "the", "pivot", "table", "relationship", "on", "the", "models", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L159-L168
244,746
sdispater/orator
orator/orm/relations/belongs_to_many.py
BelongsToMany.touch
def touch(self): """ Touch all of the related models of the relationship. """ key = self.get_related().get_key_name() columns = self.get_related_fresh_update() ids = self.get_related_ids() if len(ids) > 0: self.get_related().new_query().where_in(key...
python
def touch(self): key = self.get_related().get_key_name() columns = self.get_related_fresh_update() ids = self.get_related_ids() if len(ids) > 0: self.get_related().new_query().where_in(key, ids).update(columns)
[ "def", "touch", "(", "self", ")", ":", "key", "=", "self", ".", "get_related", "(", ")", ".", "get_key_name", "(", ")", "columns", "=", "self", ".", "get_related_fresh_update", "(", ")", "ids", "=", "self", ".", "get_related_ids", "(", ")", "if", "len"...
Touch all of the related models of the relationship.
[ "Touch", "all", "of", "the", "related", "models", "of", "the", "relationship", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L391-L402
244,747
sdispater/orator
orator/orm/relations/belongs_to_many.py
BelongsToMany.get_related_ids
def get_related_ids(self): """ Get all of the IDs for the related models. :rtype: list """ related = self.get_related() full_key = related.get_qualified_key_name() return self.get_query().select(full_key).lists(related.get_key_name())
python
def get_related_ids(self): related = self.get_related() full_key = related.get_qualified_key_name() return self.get_query().select(full_key).lists(related.get_key_name())
[ "def", "get_related_ids", "(", "self", ")", ":", "related", "=", "self", ".", "get_related", "(", ")", "full_key", "=", "related", ".", "get_qualified_key_name", "(", ")", "return", "self", ".", "get_query", "(", ")", ".", "select", "(", "full_key", ")", ...
Get all of the IDs for the related models. :rtype: list
[ "Get", "all", "of", "the", "IDs", "for", "the", "related", "models", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L404-L414
244,748
sdispater/orator
orator/orm/relations/belongs_to_many.py
BelongsToMany.save_many
def save_many(self, models, joinings=None): """ Save a list of new models and attach them to the parent model :type models: list :type joinings: dict :rtype: list """ if joinings is None: joinings = {} for key, model in enumerate(models): ...
python
def save_many(self, models, joinings=None): if joinings is None: joinings = {} for key, model in enumerate(models): self.save(model, joinings.get(key), False) self.touch_if_touching() return models
[ "def", "save_many", "(", "self", ",", "models", ",", "joinings", "=", "None", ")", ":", "if", "joinings", "is", "None", ":", "joinings", "=", "{", "}", "for", "key", ",", "model", "in", "enumerate", "(", "models", ")", ":", "self", ".", "save", "("...
Save a list of new models and attach them to the parent model :type models: list :type joinings: dict :rtype: list
[ "Save", "a", "list", "of", "new", "models", "and", "attach", "them", "to", "the", "parent", "model" ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L435-L452
244,749
sdispater/orator
orator/orm/relations/belongs_to_many.py
BelongsToMany.first_or_create
def first_or_create( self, _attributes=None, _joining=None, _touch=True, **attributes ): """ Get the first related model record matching the attributes or create it. :param attributes: The attributes :type attributes: dict :rtype: Model """ if _attr...
python
def first_or_create( self, _attributes=None, _joining=None, _touch=True, **attributes ): if _attributes is not None: attributes.update(_attributes) instance = self._query.where(attributes).first() if instance is None: instance = self.create(attributes, _joini...
[ "def", "first_or_create", "(", "self", ",", "_attributes", "=", "None", ",", "_joining", "=", "None", ",", "_touch", "=", "True", ",", "*", "*", "attributes", ")", ":", "if", "_attributes", "is", "not", "None", ":", "attributes", ".", "update", "(", "_...
Get the first related model record matching the attributes or create it. :param attributes: The attributes :type attributes: dict :rtype: Model
[ "Get", "the", "first", "related", "model", "record", "matching", "the", "attributes", "or", "create", "it", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L490-L508
244,750
sdispater/orator
orator/orm/relations/belongs_to_many.py
BelongsToMany.sync
def sync(self, ids, detaching=True): """ Sync the intermediate tables with a list of IDs or collection of models """ changes = {"attached": [], "detached": [], "updated": []} if isinstance(ids, Collection): ids = ids.model_keys() current = self._new_pivot_qu...
python
def sync(self, ids, detaching=True): changes = {"attached": [], "detached": [], "updated": []} if isinstance(ids, Collection): ids = ids.model_keys() current = self._new_pivot_query().lists(self._other_key).all() records = self._format_sync_list(ids) detach = [x f...
[ "def", "sync", "(", "self", ",", "ids", ",", "detaching", "=", "True", ")", ":", "changes", "=", "{", "\"attached\"", ":", "[", "]", ",", "\"detached\"", ":", "[", "]", ",", "\"updated\"", ":", "[", "]", "}", "if", "isinstance", "(", "ids", ",", ...
Sync the intermediate tables with a list of IDs or collection of models
[ "Sync", "the", "intermediate", "tables", "with", "a", "list", "of", "IDs", "or", "collection", "of", "models" ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L572-L597
244,751
sdispater/orator
orator/orm/relations/belongs_to_many.py
BelongsToMany._format_sync_list
def _format_sync_list(self, records): """ Format the sync list so that it is keyed by ID. """ results = {} for attributes in records: if not isinstance(attributes, dict): id, attributes = attributes, {} else: id = list(attr...
python
def _format_sync_list(self, records): results = {} for attributes in records: if not isinstance(attributes, dict): id, attributes = attributes, {} else: id = list(attributes.keys())[0] attributes = attributes[id] resul...
[ "def", "_format_sync_list", "(", "self", ",", "records", ")", ":", "results", "=", "{", "}", "for", "attributes", "in", "records", ":", "if", "not", "isinstance", "(", "attributes", ",", "dict", ")", ":", "id", ",", "attributes", "=", "attributes", ",", ...
Format the sync list so that it is keyed by ID.
[ "Format", "the", "sync", "list", "so", "that", "it", "is", "keyed", "by", "ID", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L599-L614
244,752
sdispater/orator
orator/orm/relations/belongs_to_many.py
BelongsToMany.attach
def attach(self, id, attributes=None, touch=True): """ Attach a model to the parent. """ if isinstance(id, orator.orm.Model): id = id.get_key() query = self.new_pivot_statement() if not isinstance(id, list): id = [id] query.insert(self._...
python
def attach(self, id, attributes=None, touch=True): if isinstance(id, orator.orm.Model): id = id.get_key() query = self.new_pivot_statement() if not isinstance(id, list): id = [id] query.insert(self._create_attach_records(id, attributes)) if touch: ...
[ "def", "attach", "(", "self", ",", "id", ",", "attributes", "=", "None", ",", "touch", "=", "True", ")", ":", "if", "isinstance", "(", "id", ",", "orator", ".", "orm", ".", "Model", ")", ":", "id", "=", "id", ".", "get_key", "(", ")", "query", ...
Attach a model to the parent.
[ "Attach", "a", "model", "to", "the", "parent", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L648-L663
244,753
sdispater/orator
orator/orm/relations/belongs_to_many.py
BelongsToMany._create_attach_records
def _create_attach_records(self, ids, attributes): """ Create a list of records to insert into the pivot table. """ records = [] timed = self._has_pivot_column(self.created_at()) or self._has_pivot_column( self.updated_at() ) for key, value in enumer...
python
def _create_attach_records(self, ids, attributes): records = [] timed = self._has_pivot_column(self.created_at()) or self._has_pivot_column( self.updated_at() ) for key, value in enumerate(ids): records.append(self._attacher(key, value, attributes, timed)) ...
[ "def", "_create_attach_records", "(", "self", ",", "ids", ",", "attributes", ")", ":", "records", "=", "[", "]", "timed", "=", "self", ".", "_has_pivot_column", "(", "self", ".", "created_at", "(", ")", ")", "or", "self", ".", "_has_pivot_column", "(", "...
Create a list of records to insert into the pivot table.
[ "Create", "a", "list", "of", "records", "to", "insert", "into", "the", "pivot", "table", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L665-L678
244,754
sdispater/orator
orator/orm/relations/belongs_to_many.py
BelongsToMany._attacher
def _attacher(self, key, value, attributes, timed): """ Create a full attachment record payload. """ id, extra = self._get_attach_id(key, value, attributes) record = self._create_attach_record(id, timed) if extra: record.update(extra) return record
python
def _attacher(self, key, value, attributes, timed): id, extra = self._get_attach_id(key, value, attributes) record = self._create_attach_record(id, timed) if extra: record.update(extra) return record
[ "def", "_attacher", "(", "self", ",", "key", ",", "value", ",", "attributes", ",", "timed", ")", ":", "id", ",", "extra", "=", "self", ".", "_get_attach_id", "(", "key", ",", "value", ",", "attributes", ")", "record", "=", "self", ".", "_create_attach_...
Create a full attachment record payload.
[ "Create", "a", "full", "attachment", "record", "payload", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L680-L691
244,755
sdispater/orator
orator/orm/relations/belongs_to_many.py
BelongsToMany._get_attach_id
def _get_attach_id(self, key, value, attributes): """ Get the attach record ID and extra attributes. """ if isinstance(value, dict): key = list(value.keys())[0] attributes.update(value[key]) return [key, attributes] return value, attributes
python
def _get_attach_id(self, key, value, attributes): if isinstance(value, dict): key = list(value.keys())[0] attributes.update(value[key]) return [key, attributes] return value, attributes
[ "def", "_get_attach_id", "(", "self", ",", "key", ",", "value", ",", "attributes", ")", ":", "if", "isinstance", "(", "value", ",", "dict", ")", ":", "key", "=", "list", "(", "value", ".", "keys", "(", ")", ")", "[", "0", "]", "attributes", ".", ...
Get the attach record ID and extra attributes.
[ "Get", "the", "attach", "record", "ID", "and", "extra", "attributes", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L693-L703
244,756
sdispater/orator
orator/orm/relations/belongs_to_many.py
BelongsToMany._set_timestamps_on_attach
def _set_timestamps_on_attach(self, record, exists=False): """ Set the creation an update timestamps on an attach record. """ fresh = self._parent.fresh_timestamp() if not exists and self._has_pivot_column(self.created_at()): record[self.created_at()] = fresh ...
python
def _set_timestamps_on_attach(self, record, exists=False): fresh = self._parent.fresh_timestamp() if not exists and self._has_pivot_column(self.created_at()): record[self.created_at()] = fresh if self._has_pivot_column(self.updated_at()): record[self.updated_at()] = fre...
[ "def", "_set_timestamps_on_attach", "(", "self", ",", "record", ",", "exists", "=", "False", ")", ":", "fresh", "=", "self", ".", "_parent", ".", "fresh_timestamp", "(", ")", "if", "not", "exists", "and", "self", ".", "_has_pivot_column", "(", "self", ".",...
Set the creation an update timestamps on an attach record.
[ "Set", "the", "creation", "an", "update", "timestamps", "on", "an", "attach", "record", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L720-L732
244,757
sdispater/orator
orator/orm/relations/belongs_to_many.py
BelongsToMany.detach
def detach(self, ids=None, touch=True): """ Detach models from the relationship. """ if isinstance(ids, orator.orm.model.Model): ids = ids.get_key() if ids is None: ids = [] query = self._new_pivot_query() if not isinstance(ids, list): ...
python
def detach(self, ids=None, touch=True): if isinstance(ids, orator.orm.model.Model): ids = ids.get_key() if ids is None: ids = [] query = self._new_pivot_query() if not isinstance(ids, list): ids = [ids] if len(ids) > 0: query.wh...
[ "def", "detach", "(", "self", ",", "ids", "=", "None", ",", "touch", "=", "True", ")", ":", "if", "isinstance", "(", "ids", ",", "orator", ".", "orm", ".", "model", ".", "Model", ")", ":", "ids", "=", "ids", ".", "get_key", "(", ")", "if", "ids...
Detach models from the relationship.
[ "Detach", "models", "from", "the", "relationship", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L734-L757
244,758
sdispater/orator
orator/orm/relations/belongs_to_many.py
BelongsToMany.touch_if_touching
def touch_if_touching(self): """ Touch if the parent model is being touched. """ if self._touching_parent(): self.get_parent().touch() if self.get_parent().touches(self._relation_name): self.touch()
python
def touch_if_touching(self): if self._touching_parent(): self.get_parent().touch() if self.get_parent().touches(self._relation_name): self.touch()
[ "def", "touch_if_touching", "(", "self", ")", ":", "if", "self", ".", "_touching_parent", "(", ")", ":", "self", ".", "get_parent", "(", ")", ".", "touch", "(", ")", "if", "self", ".", "get_parent", "(", ")", ".", "touches", "(", "self", ".", "_relat...
Touch if the parent model is being touched.
[ "Touch", "if", "the", "parent", "model", "is", "being", "touched", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L759-L767
244,759
sdispater/orator
orator/orm/relations/belongs_to_many.py
BelongsToMany.with_pivot
def with_pivot(self, *columns): """ Set the columns on the pivot table to retrieve. """ columns = list(columns) self._pivot_columns += columns return self
python
def with_pivot(self, *columns): columns = list(columns) self._pivot_columns += columns return self
[ "def", "with_pivot", "(", "self", ",", "*", "columns", ")", ":", "columns", "=", "list", "(", "columns", ")", "self", ".", "_pivot_columns", "+=", "columns", "return", "self" ]
Set the columns on the pivot table to retrieve.
[ "Set", "the", "columns", "on", "the", "pivot", "table", "to", "retrieve", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L819-L827
244,760
sdispater/orator
orator/orm/relations/belongs_to_many.py
BelongsToMany.with_timestamps
def with_timestamps(self, created_at=None, updated_at=None): """ Specify that the pivot table has creation and update columns. """ if not created_at: created_at = self.created_at() if not updated_at: updated_at = self.updated_at() return self.wit...
python
def with_timestamps(self, created_at=None, updated_at=None): if not created_at: created_at = self.created_at() if not updated_at: updated_at = self.updated_at() return self.with_pivot(created_at, updated_at)
[ "def", "with_timestamps", "(", "self", ",", "created_at", "=", "None", ",", "updated_at", "=", "None", ")", ":", "if", "not", "created_at", ":", "created_at", "=", "self", ".", "created_at", "(", ")", "if", "not", "updated_at", ":", "updated_at", "=", "s...
Specify that the pivot table has creation and update columns.
[ "Specify", "that", "the", "pivot", "table", "has", "creation", "and", "update", "columns", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to_many.py#L829-L839
244,761
sdispater/orator
orator/orm/relations/belongs_to.py
BelongsTo._get_eager_model_keys
def _get_eager_model_keys(self, models): """ Gather the keys from a list of related models. :type models: list :rtype: list """ keys = [] for model in models: value = getattr(model, self._foreign_key) if value is not None and value not ...
python
def _get_eager_model_keys(self, models): keys = [] for model in models: value = getattr(model, self._foreign_key) if value is not None and value not in keys: keys.append(value) if not len(keys): return [0] return keys
[ "def", "_get_eager_model_keys", "(", "self", ",", "models", ")", ":", "keys", "=", "[", "]", "for", "model", "in", "models", ":", "value", "=", "getattr", "(", "model", ",", "self", ".", "_foreign_key", ")", "if", "value", "is", "not", "None", "and", ...
Gather the keys from a list of related models. :type models: list :rtype: list
[ "Gather", "the", "keys", "from", "a", "list", "of", "related", "models", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to.py#L87-L106
244,762
sdispater/orator
orator/orm/relations/belongs_to.py
BelongsTo.update
def update(self, _attributes=None, **attributes): """ Update the parent model on the relationship. :param attributes: The update attributes :type attributes: dict :rtype: mixed """ if _attributes is not None: attributes.update(_attributes) i...
python
def update(self, _attributes=None, **attributes): if _attributes is not None: attributes.update(_attributes) instance = self.get_results() return instance.fill(attributes).save()
[ "def", "update", "(", "self", ",", "_attributes", "=", "None", ",", "*", "*", "attributes", ")", ":", "if", "_attributes", "is", "not", "None", ":", "attributes", ".", "update", "(", "_attributes", ")", "instance", "=", "self", ".", "get_results", "(", ...
Update the parent model on the relationship. :param attributes: The update attributes :type attributes: dict :rtype: mixed
[ "Update", "the", "parent", "model", "on", "the", "relationship", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to.py#L177-L191
244,763
sdispater/orator
orator/orm/relations/morph_to.py
MorphTo._build_dictionary
def _build_dictionary(self, models): """ Build a dictionary with the models. :param models: The models :type models: Collection """ for model in models: key = getattr(model, self._morph_type, None) if key: foreign = getattr(model, ...
python
def _build_dictionary(self, models): for model in models: key = getattr(model, self._morph_type, None) if key: foreign = getattr(model, self._foreign_key) if key not in self._dictionary: self._dictionary[key] = {} if fo...
[ "def", "_build_dictionary", "(", "self", ",", "models", ")", ":", "for", "model", "in", "models", ":", "key", "=", "getattr", "(", "model", ",", "self", ".", "_morph_type", ",", "None", ")", "if", "key", ":", "foreign", "=", "getattr", "(", "model", ...
Build a dictionary with the models. :param models: The models :type models: Collection
[ "Build", "a", "dictionary", "with", "the", "models", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/morph_to.py#L49-L66
244,764
sdispater/orator
orator/orm/relations/morph_to.py
MorphTo.get_eager
def get_eager(self): """ Get the relationship for eager loading. :rtype: Collection """ for type in self._dictionary.keys(): self._match_to_morph_parents(type, self._get_results_by_type(type)) return self._models
python
def get_eager(self): for type in self._dictionary.keys(): self._match_to_morph_parents(type, self._get_results_by_type(type)) return self._models
[ "def", "get_eager", "(", "self", ")", ":", "for", "type", "in", "self", ".", "_dictionary", ".", "keys", "(", ")", ":", "self", ".", "_match_to_morph_parents", "(", "type", ",", "self", ".", "_get_results_by_type", "(", "type", ")", ")", "return", "self"...
Get the relationship for eager loading. :rtype: Collection
[ "Get", "the", "relationship", "for", "eager", "loading", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/morph_to.py#L93-L102
244,765
sdispater/orator
orator/orm/relations/morph_to.py
MorphTo._match_to_morph_parents
def _match_to_morph_parents(self, type, results): """ Match the results for a given type to their parent. :param type: The parent type :type type: str :param results: The results to match to their parent :type results: Collection """ for result in result...
python
def _match_to_morph_parents(self, type, results): for result in results: if result.get_key() in self._dictionary.get(type, []): for model in self._dictionary[type][result.get_key()]: model.set_relation( self._relation, Result(result, self, ...
[ "def", "_match_to_morph_parents", "(", "self", ",", "type", ",", "results", ")", ":", "for", "result", "in", "results", ":", "if", "result", ".", "get_key", "(", ")", "in", "self", ".", "_dictionary", ".", "get", "(", "type", ",", "[", "]", ")", ":",...
Match the results for a given type to their parent. :param type: The parent type :type type: str :param results: The results to match to their parent :type results: Collection
[ "Match", "the", "results", "for", "a", "given", "type", "to", "their", "parent", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/morph_to.py#L104-L119
244,766
sdispater/orator
orator/orm/relations/morph_to.py
MorphTo._get_results_by_type
def _get_results_by_type(self, type): """ Get all the relation results for a type. :param type: The type :type type: str :rtype: Collection """ instance = self._create_model_by_type(type) key = instance.get_key_name() query = instance.new_query...
python
def _get_results_by_type(self, type): instance = self._create_model_by_type(type) key = instance.get_key_name() query = instance.new_query() query = self._use_with_trashed(query) return query.where_in(key, self._gather_keys_by_type(type).all()).get()
[ "def", "_get_results_by_type", "(", "self", ",", "type", ")", ":", "instance", "=", "self", ".", "_create_model_by_type", "(", "type", ")", "key", "=", "instance", ".", "get_key_name", "(", ")", "query", "=", "instance", ".", "new_query", "(", ")", "query"...
Get all the relation results for a type. :param type: The type :type type: str :rtype: Collection
[ "Get", "all", "the", "relation", "results", "for", "a", "type", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/morph_to.py#L121-L138
244,767
sdispater/orator
orator/orm/relations/morph_to.py
MorphTo._gather_keys_by_type
def _gather_keys_by_type(self, type): """ Gather all of the foreign keys for a given type. :param type: The type :type type: str :rtype: BaseCollection """ foreign = self._foreign_key keys = ( BaseCollection.make(list(self._dictionary[type]....
python
def _gather_keys_by_type(self, type): foreign = self._foreign_key keys = ( BaseCollection.make(list(self._dictionary[type].values())) .map(lambda models: getattr(models[0], foreign)) .unique() ) return keys
[ "def", "_gather_keys_by_type", "(", "self", ",", "type", ")", ":", "foreign", "=", "self", ".", "_foreign_key", "keys", "=", "(", "BaseCollection", ".", "make", "(", "list", "(", "self", ".", "_dictionary", "[", "type", "]", ".", "values", "(", ")", ")...
Gather all of the foreign keys for a given type. :param type: The type :type type: str :rtype: BaseCollection
[ "Gather", "all", "of", "the", "foreign", "keys", "for", "a", "given", "type", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/morph_to.py#L140-L157
244,768
sdispater/orator
orator/dbal/table.py
Table.set_primary_key
def set_primary_key(self, columns, index_name=False): """ Set the primary key. :type columns: list :type index_name: str or bool :rtype: Table """ self._add_index( self._create_index(columns, index_name or "primary", True, True) ) fo...
python
def set_primary_key(self, columns, index_name=False): self._add_index( self._create_index(columns, index_name or "primary", True, True) ) for column_name in columns: column = self.get_column(column_name) column.set_notnull(True) return self
[ "def", "set_primary_key", "(", "self", ",", "columns", ",", "index_name", "=", "False", ")", ":", "self", ".", "_add_index", "(", "self", ".", "_create_index", "(", "columns", ",", "index_name", "or", "\"primary\"", ",", "True", ",", "True", ")", ")", "f...
Set the primary key. :type columns: list :type index_name: str or bool :rtype: Table
[ "Set", "the", "primary", "key", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L55-L72
244,769
sdispater/orator
orator/dbal/table.py
Table.drop_index
def drop_index(self, name): """ Drops an index from this table. :param name: The index name :type name: str """ name = self._normalize_identifier(name) if not self.has_index(name): raise IndexDoesNotExist(name, self._name) del self._indexes[n...
python
def drop_index(self, name): name = self._normalize_identifier(name) if not self.has_index(name): raise IndexDoesNotExist(name, self._name) del self._indexes[name]
[ "def", "drop_index", "(", "self", ",", "name", ")", ":", "name", "=", "self", ".", "_normalize_identifier", "(", "name", ")", "if", "not", "self", ".", "has_index", "(", "name", ")", ":", "raise", "IndexDoesNotExist", "(", "name", ",", "self", ".", "_n...
Drops an index from this table. :param name: The index name :type name: str
[ "Drops", "an", "index", "from", "this", "table", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L91-L102
244,770
sdispater/orator
orator/dbal/table.py
Table.rename_index
def rename_index(self, old_name, new_name=None): """ Renames an index. :param old_name: The name of the index to rename from. :type old_name: str :param new_name: The name of the index to rename to. :type new_name: str or None :rtype: Table """ ...
python
def rename_index(self, old_name, new_name=None): old_name = self._normalize_identifier(old_name) normalized_new_name = self._normalize_identifier(new_name) if old_name == normalized_new_name: return self if not self.has_index(old_name): raise IndexDoesNotExist(o...
[ "def", "rename_index", "(", "self", ",", "old_name", ",", "new_name", "=", "None", ")", ":", "old_name", "=", "self", ".", "_normalize_identifier", "(", "old_name", ")", "normalized_new_name", "=", "self", ".", "_normalize_identifier", "(", "new_name", ")", "i...
Renames an index. :param old_name: The name of the index to rename from. :type old_name: str :param new_name: The name of the index to rename to. :type new_name: str or None :rtype: Table
[ "Renames", "an", "index", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L114-L150
244,771
sdispater/orator
orator/dbal/table.py
Table.columns_are_indexed
def columns_are_indexed(self, columns): """ Checks if an index begins in the order of the given columns. :type columns: list :rtype: bool """ for index in self._indexes.values(): if index.spans_columns(columns): return True return Fa...
python
def columns_are_indexed(self, columns): for index in self._indexes.values(): if index.spans_columns(columns): return True return False
[ "def", "columns_are_indexed", "(", "self", ",", "columns", ")", ":", "for", "index", "in", "self", ".", "_indexes", ".", "values", "(", ")", ":", "if", "index", ".", "spans_columns", "(", "columns", ")", ":", "return", "True", "return", "False" ]
Checks if an index begins in the order of the given columns. :type columns: list :rtype: bool
[ "Checks", "if", "an", "index", "begins", "in", "the", "order", "of", "the", "given", "columns", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L152-L164
244,772
sdispater/orator
orator/dbal/table.py
Table._create_index
def _create_index( self, columns, name, is_unique, is_primary, flags=None, options=None ): """ Creates an Index instance. :param columns: The index columns :type columns: list :param name: The index name :type name: str :param is_unique: Whether the...
python
def _create_index( self, columns, name, is_unique, is_primary, flags=None, options=None ): if re.match("[^a-zA-Z0-9_]+", self._normalize_identifier(name)): raise IndexNameInvalid(name) for column in columns: if isinstance(column, dict): column = list(...
[ "def", "_create_index", "(", "self", ",", "columns", ",", "name", ",", "is_unique", ",", "is_primary", ",", "flags", "=", "None", ",", "options", "=", "None", ")", ":", "if", "re", ".", "match", "(", "\"[^a-zA-Z0-9_]+\"", ",", "self", ".", "_normalize_id...
Creates an Index instance. :param columns: The index columns :type columns: list :param name: The index name :type name: str :param is_unique: Whether the index is unique or not :type is_unique: bool :param is_primary: Whether the index is primary or not ...
[ "Creates", "an", "Index", "instance", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L166-L202
244,773
sdispater/orator
orator/dbal/table.py
Table.add_column
def add_column(self, name, type_name, options=None): """ Adds a new column. :param name: The column name :type name: str :param type_name: The column type :type type_name: str :param options: The column options :type options: dict :rtype: Colum...
python
def add_column(self, name, type_name, options=None): column = Column(name, type_name, options) self._add_column(column) return column
[ "def", "add_column", "(", "self", ",", "name", ",", "type_name", ",", "options", "=", "None", ")", ":", "column", "=", "Column", "(", "name", ",", "type_name", ",", "options", ")", "self", ".", "_add_column", "(", "column", ")", "return", "column" ]
Adds a new column. :param name: The column name :type name: str :param type_name: The column type :type type_name: str :param options: The column options :type options: dict :rtype: Column
[ "Adds", "a", "new", "column", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L204-L223
244,774
sdispater/orator
orator/dbal/table.py
Table.change_column
def change_column(self, name, options): """ Changes column details. :param name: The column to change. :type name: str :param options: The new options. :type options: str :rtype: Table """ column = self.get_column(name) column.set_option...
python
def change_column(self, name, options): column = self.get_column(name) column.set_options(options) return self
[ "def", "change_column", "(", "self", ",", "name", ",", "options", ")", ":", "column", "=", "self", ".", "get_column", "(", "name", ")", "column", ".", "set_options", "(", "options", ")", "return", "self" ]
Changes column details. :param name: The column to change. :type name: str :param options: The new options. :type options: str :rtype: Table
[ "Changes", "column", "details", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L225-L240
244,775
sdispater/orator
orator/dbal/table.py
Table.drop_column
def drop_column(self, name): """ Drops a Column from the Table :param name: The name of the column :type name: str :rtype: Table """ name = self._normalize_identifier(name) del self._columns[name] return self
python
def drop_column(self, name): name = self._normalize_identifier(name) del self._columns[name] return self
[ "def", "drop_column", "(", "self", ",", "name", ")", ":", "name", "=", "self", ".", "_normalize_identifier", "(", "name", ")", "del", "self", ".", "_columns", "[", "name", "]", "return", "self" ]
Drops a Column from the Table :param name: The name of the column :type name: str :rtype: Table
[ "Drops", "a", "Column", "from", "the", "Table" ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L242-L254
244,776
sdispater/orator
orator/dbal/table.py
Table.add_named_foreign_key_constraint
def add_named_foreign_key_constraint( self, name, foreign_table, local_columns, foreign_columns, options ): """ Adds a foreign key constraint with a given name. :param name: The constraint name :type name: str :param foreign_table: Table instance or table name ...
python
def add_named_foreign_key_constraint( self, name, foreign_table, local_columns, foreign_columns, options ): if isinstance(foreign_table, Table): for column in foreign_columns: if not foreign_table.has_column(column): raise ColumnDoesNotExist(column, fo...
[ "def", "add_named_foreign_key_constraint", "(", "self", ",", "name", ",", "foreign_table", ",", "local_columns", ",", "foreign_columns", ",", "options", ")", ":", "if", "isinstance", "(", "foreign_table", ",", "Table", ")", ":", "for", "column", "in", "foreign_c...
Adds a foreign key constraint with a given name. :param name: The constraint name :type name: str :param foreign_table: Table instance or table name :type foreign_table: Table or str :type local_columns: list :type foreign_columns: list :type options: dict ...
[ "Adds", "a", "foreign", "key", "constraint", "with", "a", "given", "name", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L293-L328
244,777
sdispater/orator
orator/dbal/table.py
Table._add_index
def _add_index(self, index): """ Adds an index to the table. :param index: The index to add :type index: Index :rtype: Table """ index_name = index.get_name() index_name = self._normalize_identifier(index_name) replaced_implicit_indexes = [] ...
python
def _add_index(self, index): index_name = index.get_name() index_name = self._normalize_identifier(index_name) replaced_implicit_indexes = [] for name, implicit_index in self._implicit_indexes.items(): if implicit_index.is_fullfilled_by(index) and name in self._indexes: ...
[ "def", "_add_index", "(", "self", ",", "index", ")", ":", "index_name", "=", "index", ".", "get_name", "(", ")", "index_name", "=", "self", ".", "_normalize_identifier", "(", "index_name", ")", "replaced_implicit_indexes", "=", "[", "]", "for", "name", ",", ...
Adds an index to the table. :param index: The index to add :type index: Index :rtype: Table
[ "Adds", "an", "index", "to", "the", "table", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L343-L378
244,778
sdispater/orator
orator/dbal/table.py
Table.has_foreign_key
def has_foreign_key(self, name): """ Returns whether this table has a foreign key constraint with the given name. :param name: The constraint name :type name: str :rtype: bool """ name = self._normalize_identifier(name) return name in self._fk_constrain...
python
def has_foreign_key(self, name): name = self._normalize_identifier(name) return name in self._fk_constraints
[ "def", "has_foreign_key", "(", "self", ",", "name", ")", ":", "name", "=", "self", ".", "_normalize_identifier", "(", "name", ")", "return", "name", "in", "self", ".", "_fk_constraints" ]
Returns whether this table has a foreign key constraint with the given name. :param name: The constraint name :type name: str :rtype: bool
[ "Returns", "whether", "this", "table", "has", "a", "foreign", "key", "constraint", "with", "the", "given", "name", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L428-L439
244,779
sdispater/orator
orator/dbal/table.py
Table.get_foreign_key
def get_foreign_key(self, name): """ Returns the foreign key constraint with the given name. :param name: The constraint name :type name: str :rtype: ForeignKeyConstraint """ name = self._normalize_identifier(name) if not self.has_foreign_key(name): ...
python
def get_foreign_key(self, name): name = self._normalize_identifier(name) if not self.has_foreign_key(name): raise ForeignKeyDoesNotExist(name, self._name) return self._fk_constraints[name]
[ "def", "get_foreign_key", "(", "self", ",", "name", ")", ":", "name", "=", "self", ".", "_normalize_identifier", "(", "name", ")", "if", "not", "self", ".", "has_foreign_key", "(", "name", ")", ":", "raise", "ForeignKeyDoesNotExist", "(", "name", ",", "sel...
Returns the foreign key constraint with the given name. :param name: The constraint name :type name: str :rtype: ForeignKeyConstraint
[ "Returns", "the", "foreign", "key", "constraint", "with", "the", "given", "name", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L441-L455
244,780
sdispater/orator
orator/dbal/table.py
Table.remove_foreign_key
def remove_foreign_key(self, name): """ Removes the foreign key constraint with the given name. :param name: The constraint name :type name: str """ name = self._normalize_identifier(name) if not self.has_foreign_key(name): raise ForeignKeyDoesNotExi...
python
def remove_foreign_key(self, name): name = self._normalize_identifier(name) if not self.has_foreign_key(name): raise ForeignKeyDoesNotExist(name, self._name) del self._fk_constraints[name]
[ "def", "remove_foreign_key", "(", "self", ",", "name", ")", ":", "name", "=", "self", ".", "_normalize_identifier", "(", "name", ")", "if", "not", "self", ".", "has_foreign_key", "(", "name", ")", ":", "raise", "ForeignKeyDoesNotExist", "(", "name", ",", "...
Removes the foreign key constraint with the given name. :param name: The constraint name :type name: str
[ "Removes", "the", "foreign", "key", "constraint", "with", "the", "given", "name", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L457-L469
244,781
sdispater/orator
orator/dbal/table.py
Table.get_primary_key_columns
def get_primary_key_columns(self): """ Returns the primary key columns. :rtype: list """ if not self.has_primary_key(): raise DBALException('Table "%s" has no primary key.' % self.get_name()) return self.get_primary_key().get_columns()
python
def get_primary_key_columns(self): if not self.has_primary_key(): raise DBALException('Table "%s" has no primary key.' % self.get_name()) return self.get_primary_key().get_columns()
[ "def", "get_primary_key_columns", "(", "self", ")", ":", "if", "not", "self", ".", "has_primary_key", "(", ")", ":", "raise", "DBALException", "(", "'Table \"%s\" has no primary key.'", "%", "self", ".", "get_name", "(", ")", ")", "return", "self", ".", "get_p...
Returns the primary key columns. :rtype: list
[ "Returns", "the", "primary", "key", "columns", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L511-L520
244,782
sdispater/orator
orator/dbal/table.py
Table.has_index
def has_index(self, name): """ Returns whether this table has an Index with the given name. :param name: The index name :type name: str :rtype: bool """ name = self._normalize_identifier(name) return name in self._indexes
python
def has_index(self, name): name = self._normalize_identifier(name) return name in self._indexes
[ "def", "has_index", "(", "self", ",", "name", ")", ":", "name", "=", "self", ".", "_normalize_identifier", "(", "name", ")", "return", "name", "in", "self", ".", "_indexes" ]
Returns whether this table has an Index with the given name. :param name: The index name :type name: str :rtype: bool
[ "Returns", "whether", "this", "table", "has", "an", "Index", "with", "the", "given", "name", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L533-L544
244,783
sdispater/orator
orator/dbal/table.py
Table.get_index
def get_index(self, name): """ Returns the Index with the given name. :param name: The index name :type name: str :rtype: Index """ name = self._normalize_identifier(name) if not self.has_index(name): raise IndexDoesNotExist(name, self._name)...
python
def get_index(self, name): name = self._normalize_identifier(name) if not self.has_index(name): raise IndexDoesNotExist(name, self._name) return self._indexes[name]
[ "def", "get_index", "(", "self", ",", "name", ")", ":", "name", "=", "self", ".", "_normalize_identifier", "(", "name", ")", "if", "not", "self", ".", "has_index", "(", "name", ")", ":", "raise", "IndexDoesNotExist", "(", "name", ",", "self", ".", "_na...
Returns the Index with the given name. :param name: The index name :type name: str :rtype: Index
[ "Returns", "the", "Index", "with", "the", "given", "name", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L546-L559
244,784
sdispater/orator
orator/orm/builder.py
Builder.without_global_scope
def without_global_scope(self, scope): """ Remove a registered global scope. :param scope: The scope to remove :type scope: Scope or str :rtype: Builder """ if isinstance(scope, basestring): del self._scopes[scope] return self k...
python
def without_global_scope(self, scope): if isinstance(scope, basestring): del self._scopes[scope] return self keys = [] for key, value in self._scopes.items(): if scope == value.__class__ or isinstance(scope, value.__class__): keys.append(key)...
[ "def", "without_global_scope", "(", "self", ",", "scope", ")", ":", "if", "isinstance", "(", "scope", ",", "basestring", ")", ":", "del", "self", ".", "_scopes", "[", "scope", "]", "return", "self", "keys", "=", "[", "]", "for", "key", ",", "value", ...
Remove a registered global scope. :param scope: The scope to remove :type scope: Scope or str :rtype: Builder
[ "Remove", "a", "registered", "global", "scope", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L63-L85
244,785
sdispater/orator
orator/orm/builder.py
Builder.find_or_fail
def find_or_fail(self, id, columns=None): """ Find a model by its primary key or raise an exception :param id: The primary key value :type id: mixed :param columns: The columns to retrieve :type columns: list :return: The found model :rtype: orator.Mode...
python
def find_or_fail(self, id, columns=None): result = self.find(id, columns) if isinstance(id, list): if len(result) == len(set(id)): return result elif result: return result raise ModelNotFound(self._model.__class__)
[ "def", "find_or_fail", "(", "self", ",", "id", ",", "columns", "=", "None", ")", ":", "result", "=", "self", ".", "find", "(", "id", ",", "columns", ")", "if", "isinstance", "(", "id", ",", "list", ")", ":", "if", "len", "(", "result", ")", "==",...
Find a model by its primary key or raise an exception :param id: The primary key value :type id: mixed :param columns: The columns to retrieve :type columns: list :return: The found model :rtype: orator.Model :raises: ModelNotFound
[ "Find", "a", "model", "by", "its", "primary", "key", "or", "raise", "an", "exception" ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L143-L166
244,786
sdispater/orator
orator/orm/builder.py
Builder.first_or_fail
def first_or_fail(self, columns=None): """ Execute the query and get the first result or raise an exception :param columns: The columns to get :type columns: list :return: The result :rtype: mixed """ model = self.first(columns) if model is not ...
python
def first_or_fail(self, columns=None): model = self.first(columns) if model is not None: return model raise ModelNotFound(self._model.__class__)
[ "def", "first_or_fail", "(", "self", ",", "columns", "=", "None", ")", ":", "model", "=", "self", ".", "first", "(", "columns", ")", "if", "model", "is", "not", "None", ":", "return", "model", "raise", "ModelNotFound", "(", "self", ".", "_model", ".", ...
Execute the query and get the first result or raise an exception :param columns: The columns to get :type columns: list :return: The result :rtype: mixed
[ "Execute", "the", "query", "and", "get", "the", "first", "result", "or", "raise", "an", "exception" ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L183-L198
244,787
sdispater/orator
orator/orm/builder.py
Builder.pluck
def pluck(self, column): """ Pluck a single column from the database. :param column: THe column to pluck :type column: str :return: The column value :rtype: mixed """ result = self.first([column]) if result: return result[column]
python
def pluck(self, column): result = self.first([column]) if result: return result[column]
[ "def", "pluck", "(", "self", ",", "column", ")", ":", "result", "=", "self", ".", "first", "(", "[", "column", "]", ")", "if", "result", ":", "return", "result", "[", "column", "]" ]
Pluck a single column from the database. :param column: THe column to pluck :type column: str :return: The column value :rtype: mixed
[ "Pluck", "a", "single", "column", "from", "the", "database", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L221-L234
244,788
sdispater/orator
orator/orm/builder.py
Builder._add_updated_at_column
def _add_updated_at_column(self, values): """ Add the "updated_at" column to a dictionary of values. :param values: The values to update :type values: dict :return: The new dictionary of values :rtype: dict """ if not self._model.uses_timestamps(): ...
python
def _add_updated_at_column(self, values): if not self._model.uses_timestamps(): return values column = self._model.get_updated_at_column() if "updated_at" not in values: values.update({column: self._model.fresh_timestamp_string()}) return values
[ "def", "_add_updated_at_column", "(", "self", ",", "values", ")", ":", "if", "not", "self", ".", "_model", ".", "uses_timestamps", "(", ")", ":", "return", "values", "column", "=", "self", ".", "_model", ".", "get_updated_at_column", "(", ")", "if", "\"upd...
Add the "updated_at" column to a dictionary of values. :param values: The values to update :type values: dict :return: The new dictionary of values :rtype: dict
[ "Add", "the", "updated_at", "column", "to", "a", "dictionary", "of", "values", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L401-L419
244,789
sdispater/orator
orator/orm/builder.py
Builder.delete
def delete(self): """ Delete a record from the database. """ if self._on_delete is not None: return self._on_delete(self) return self._query.delete()
python
def delete(self): if self._on_delete is not None: return self._on_delete(self) return self._query.delete()
[ "def", "delete", "(", "self", ")", ":", "if", "self", ".", "_on_delete", "is", "not", "None", ":", "return", "self", ".", "_on_delete", "(", "self", ")", "return", "self", ".", "_query", ".", "delete", "(", ")" ]
Delete a record from the database.
[ "Delete", "a", "record", "from", "the", "database", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L421-L428
244,790
sdispater/orator
orator/orm/builder.py
Builder.get_relation
def get_relation(self, relation): """ Get the relation instance for the given relation name. :rtype: orator.orm.relations.Relation """ from .relations import Relation with Relation.no_constraints(True): rel = getattr(self.get_model(), relation)() ne...
python
def get_relation(self, relation): from .relations import Relation with Relation.no_constraints(True): rel = getattr(self.get_model(), relation)() nested = self._nested_relations(relation) if len(nested) > 0: rel.get_query().with_(nested) return rel
[ "def", "get_relation", "(", "self", ",", "relation", ")", ":", "from", ".", "relations", "import", "Relation", "with", "Relation", ".", "no_constraints", "(", "True", ")", ":", "rel", "=", "getattr", "(", "self", ".", "get_model", "(", ")", ",", "relatio...
Get the relation instance for the given relation name. :rtype: orator.orm.relations.Relation
[ "Get", "the", "relation", "instance", "for", "the", "given", "relation", "name", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L500-L516
244,791
sdispater/orator
orator/orm/builder.py
Builder._nested_relations
def _nested_relations(self, relation): """ Get the deeply nested relations for a given top-level relation. :rtype: dict """ nested = {} for name, constraints in self._eager_load.items(): if self._is_nested(name, relation): nested[name[len(rel...
python
def _nested_relations(self, relation): nested = {} for name, constraints in self._eager_load.items(): if self._is_nested(name, relation): nested[name[len(relation + ".") :]] = constraints return nested
[ "def", "_nested_relations", "(", "self", ",", "relation", ")", ":", "nested", "=", "{", "}", "for", "name", ",", "constraints", "in", "self", ".", "_eager_load", ".", "items", "(", ")", ":", "if", "self", ".", "_is_nested", "(", "name", ",", "relation"...
Get the deeply nested relations for a given top-level relation. :rtype: dict
[ "Get", "the", "deeply", "nested", "relations", "for", "a", "given", "top", "-", "level", "relation", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L518-L530
244,792
sdispater/orator
orator/orm/builder.py
Builder._is_nested
def _is_nested(self, name, relation): """ Determine if the relationship is nested. :type name: str :type relation: str :rtype: bool """ dots = name.find(".") return dots and name.startswith(relation + ".")
python
def _is_nested(self, name, relation): dots = name.find(".") return dots and name.startswith(relation + ".")
[ "def", "_is_nested", "(", "self", ",", "name", ",", "relation", ")", ":", "dots", "=", "name", ".", "find", "(", "\".\"", ")", "return", "dots", "and", "name", ".", "startswith", "(", "relation", "+", "\".\"", ")" ]
Determine if the relationship is nested. :type name: str :type relation: str :rtype: bool
[ "Determine", "if", "the", "relationship", "is", "nested", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L532-L543
244,793
sdispater/orator
orator/orm/builder.py
Builder.where_exists
def where_exists(self, query, boolean="and", negate=False): """ Add an exists clause to the query. :param query: The exists query :type query: Builder or QueryBuilder :type boolean: str :type negate: bool :rtype: Builder """ if isinstance(query...
python
def where_exists(self, query, boolean="and", negate=False): if isinstance(query, Builder): query = query.get_query() self.get_query().where_exists(query, boolean, negate) return self
[ "def", "where_exists", "(", "self", ",", "query", ",", "boolean", "=", "\"and\"", ",", "negate", "=", "False", ")", ":", "if", "isinstance", "(", "query", ",", "Builder", ")", ":", "query", "=", "query", ".", "get_query", "(", ")", "self", ".", "get_...
Add an exists clause to the query. :param query: The exists query :type query: Builder or QueryBuilder :type boolean: str :type negate: bool :rtype: Builder
[ "Add", "an", "exists", "clause", "to", "the", "query", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L589-L607
244,794
sdispater/orator
orator/orm/builder.py
Builder.has
def has(self, relation, operator=">=", count=1, boolean="and", extra=None): """ Add a relationship count condition to the query. :param relation: The relation to count :type relation: str :param operator: The operator :type operator: str :param count: The count...
python
def has(self, relation, operator=">=", count=1, boolean="and", extra=None): if relation.find(".") >= 0: return self._has_nested(relation, operator, count, boolean, extra) relation = self._get_has_relation_query(relation) query = relation.get_relation_count_query( relati...
[ "def", "has", "(", "self", ",", "relation", ",", "operator", "=", "\">=\"", ",", "count", "=", "1", ",", "boolean", "=", "\"and\"", ",", "extra", "=", "None", ")", ":", "if", "relation", ".", "find", "(", "\".\"", ")", ">=", "0", ":", "return", "...
Add a relationship count condition to the query. :param relation: The relation to count :type relation: str :param operator: The operator :type operator: str :param count: The count :type count: int :param boolean: The boolean value :type boolean: str ...
[ "Add", "a", "relationship", "count", "condition", "to", "the", "query", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L646-L683
244,795
sdispater/orator
orator/orm/builder.py
Builder._add_has_where
def _add_has_where(self, has_query, relation, operator, count, boolean): """ Add the "has" condition where clause to the query. :param has_query: The has query :type has_query: Builder :param relation: The relation to count :type relation: orator.orm.relations.Relation ...
python
def _add_has_where(self, has_query, relation, operator, count, boolean): self._merge_model_defined_relation_wheres_to_has_query(has_query, relation) if isinstance(count, basestring) and count.isdigit(): count = QueryExpression(count) return self.where( QueryExpression("...
[ "def", "_add_has_where", "(", "self", ",", "has_query", ",", "relation", ",", "operator", ",", "count", ",", "boolean", ")", ":", "self", ".", "_merge_model_defined_relation_wheres_to_has_query", "(", "has_query", ",", "relation", ")", "if", "isinstance", "(", "...
Add the "has" condition where clause to the query. :param has_query: The has query :type has_query: Builder :param relation: The relation to count :type relation: orator.orm.relations.Relation :param operator: The operator :type operator: str :param count: The...
[ "Add", "the", "has", "condition", "where", "clause", "to", "the", "query", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L804-L832
244,796
sdispater/orator
orator/orm/builder.py
Builder._merge_model_defined_relation_wheres_to_has_query
def _merge_model_defined_relation_wheres_to_has_query(self, has_query, relation): """ Merge the "wheres" from a relation query to a has query. :param has_query: The has query :type has_query: Builder :param relation: The relation to count :type relation: orator.orm.rela...
python
def _merge_model_defined_relation_wheres_to_has_query(self, has_query, relation): relation_query = relation.get_base_query() has_query.merge_wheres(relation_query.wheres, relation_query.get_bindings()) self._query.add_binding(has_query.get_query().get_bindings(), "where")
[ "def", "_merge_model_defined_relation_wheres_to_has_query", "(", "self", ",", "has_query", ",", "relation", ")", ":", "relation_query", "=", "relation", ".", "get_base_query", "(", ")", "has_query", ".", "merge_wheres", "(", "relation_query", ".", "wheres", ",", "re...
Merge the "wheres" from a relation query to a has query. :param has_query: The has query :type has_query: Builder :param relation: The relation to count :type relation: orator.orm.relations.Relation
[ "Merge", "the", "wheres", "from", "a", "relation", "query", "to", "a", "has", "query", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L834-L848
244,797
sdispater/orator
orator/orm/builder.py
Builder.apply_scopes
def apply_scopes(self): """ Get the underlying query builder instance with applied global scopes. :type: Builder """ if not self._scopes: return self builder = copy.copy(self) query = builder.get_query() # We will keep track of how many whe...
python
def apply_scopes(self): if not self._scopes: return self builder = copy.copy(self) query = builder.get_query() # We will keep track of how many wheres are on the query before running the # scope so that we can properly group the added scope constraints in the ...
[ "def", "apply_scopes", "(", "self", ")", ":", "if", "not", "self", ".", "_scopes", ":", "return", "self", "builder", "=", "copy", ".", "copy", "(", "self", ")", "query", "=", "builder", ".", "get_query", "(", ")", "# We will keep track of how many wheres are...
Get the underlying query builder instance with applied global scopes. :type: Builder
[ "Get", "the", "underlying", "query", "builder", "instance", "with", "applied", "global", "scopes", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L953-L984
244,798
sdispater/orator
orator/orm/builder.py
Builder._apply_scope
def _apply_scope(self, scope, builder): """ Apply a single scope on the given builder instance. :param scope: The scope to apply :type scope: callable or Scope :param builder: The builder to apply the scope to :type builder: Builder """ if callable(scope...
python
def _apply_scope(self, scope, builder): if callable(scope): scope(builder) elif isinstance(scope, Scope): scope.apply(builder, self.get_model())
[ "def", "_apply_scope", "(", "self", ",", "scope", ",", "builder", ")", ":", "if", "callable", "(", "scope", ")", ":", "scope", "(", "builder", ")", "elif", "isinstance", "(", "scope", ",", "Scope", ")", ":", "scope", ".", "apply", "(", "builder", ","...
Apply a single scope on the given builder instance. :param scope: The scope to apply :type scope: callable or Scope :param builder: The builder to apply the scope to :type builder: Builder
[ "Apply", "a", "single", "scope", "on", "the", "given", "builder", "instance", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L986-L999
244,799
sdispater/orator
orator/orm/builder.py
Builder._nest_wheres_for_scope
def _nest_wheres_for_scope(self, query, where_counts): """ Nest where conditions of the builder and each global scope. :type query: QueryBuilder :type where_counts: list """ # Here, we totally remove all of the where clauses since we are going to # rebuild them a...
python
def _nest_wheres_for_scope(self, query, where_counts): # Here, we totally remove all of the where clauses since we are going to # rebuild them as nested queries by slicing the groups of wheres into # their own sections. This is to prevent any confusing logic order. wheres = query.wheres ...
[ "def", "_nest_wheres_for_scope", "(", "self", ",", "query", ",", "where_counts", ")", ":", "# Here, we totally remove all of the where clauses since we are going to", "# rebuild them as nested queries by slicing the groups of wheres into", "# their own sections. This is to prevent any confus...
Nest where conditions of the builder and each global scope. :type query: QueryBuilder :type where_counts: list
[ "Nest", "where", "conditions", "of", "the", "builder", "and", "each", "global", "scope", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L1012-L1038