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
1,300
JarryShaw/PyPCAPKit
src/protocols/internet/ipv6_opts.py
IPv6_Opts._read_opt_mpl
def _read_opt_mpl(self, code, *, desc): """Read IPv6_Opts MPL option. Structure of IPv6_Opts MPL option [RFC 7731]: 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 ...
python
def _read_opt_mpl(self, code, *, desc): _type = self._read_opt_type(code) _size = self._read_unpack(1) if _size < 2: raise ProtocolError(f'{self.alias}: [Optno {code}] invalid format') _type = self._read_opt_type(code) _size = self._read_unpack(1) _smvr = sel...
[ "def", "_read_opt_mpl", "(", "self", ",", "code", ",", "*", ",", "desc", ")", ":", "_type", "=", "self", ".", "_read_opt_type", "(", "code", ")", "_size", "=", "self", ".", "_read_unpack", "(", "1", ")", "if", "_size", "<", "2", ":", "raise", "Prot...
Read IPv6_Opts MPL option. Structure of IPv6_Opts MPL option [RFC 7731]: 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ...
[ "Read", "IPv6_Opts", "MPL", "option", "." ]
c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e
https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/ipv6_opts.py#L797-L869
1,301
JarryShaw/PyPCAPKit
src/protocols/internet/ipv6_route.py
IPv6_Route.read_ipv6_route
def read_ipv6_route(self, length, extension): """Read Routing Header for IPv6. Structure of IPv6-Route header [RFC 8200][RFC 5095]: +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Next Header | Hdr Ext Len | Routing Type | Segments Left | +-+...
python
def read_ipv6_route(self, length, extension): if length is None: length = len(self) _next = self._read_protos(1) _hlen = self._read_unpack(1) _type = self._read_unpack(1) _left = self._read_unpack(1) ipv6_route = dict( next=_next, len...
[ "def", "read_ipv6_route", "(", "self", ",", "length", ",", "extension", ")", ":", "if", "length", "is", "None", ":", "length", "=", "len", "(", "self", ")", "_next", "=", "self", ".", "_read_protos", "(", "1", ")", "_hlen", "=", "self", ".", "_read_u...
Read Routing Header for IPv6. Structure of IPv6-Route header [RFC 8200][RFC 5095]: +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Next Header | Hdr Ext Len | Routing Type | Segments Left | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-...
[ "Read", "Routing", "Header", "for", "IPv6", "." ]
c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e
https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/ipv6_route.py#L102-L151
1,302
JarryShaw/PyPCAPKit
src/protocols/internet/ipv6_route.py
IPv6_Route._read_data_type_none
def _read_data_type_none(self, length): """Read IPv6-Route unknown type data. Structure of IPv6-Route unknown type data [RFC 8200][RFC 5095]: +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Next Header | Hdr Ext Len | Routing Type | Segments Left | ...
python
def _read_data_type_none(self, length): _data = self._read_fileng(length) data = dict( data=_data, ) return data
[ "def", "_read_data_type_none", "(", "self", ",", "length", ")", ":", "_data", "=", "self", ".", "_read_fileng", "(", "length", ")", "data", "=", "dict", "(", "data", "=", "_data", ",", ")", "return", "data" ]
Read IPv6-Route unknown type data. Structure of IPv6-Route unknown type data [RFC 8200][RFC 5095]: +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Next Header | Hdr Ext Len | Routing Type | Segments Left | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-...
[ "Read", "IPv6", "-", "Route", "unknown", "type", "data", "." ]
c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e
https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/ipv6_route.py#L169-L197
1,303
JarryShaw/PyPCAPKit
src/protocols/internet/ipv6_route.py
IPv6_Route._read_data_type_src
def _read_data_type_src(self, length): """Read IPv6-Route Source Route data. Structure of IPv6-Route Source Route data [RFC 5095]: +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Next Header | Hdr Ext Len | Routing Type=0| Segments Left | +-+-...
python
def _read_data_type_src(self, length): _resv = self._read_fileng(4) _addr = list() for _ in range((length - 4) // 16): _addr.append(ipaddress.ip_address(self._read_fileng(16))) data = dict( ip=tuple(_addr), ) return data
[ "def", "_read_data_type_src", "(", "self", ",", "length", ")", ":", "_resv", "=", "self", ".", "_read_fileng", "(", "4", ")", "_addr", "=", "list", "(", ")", "for", "_", "in", "range", "(", "(", "length", "-", "4", ")", "//", "16", ")", ":", "_ad...
Read IPv6-Route Source Route data. Structure of IPv6-Route Source Route data [RFC 5095]: +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Next Header | Hdr Ext Len | Routing Type=0| Segments Left | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-...
[ "Read", "IPv6", "-", "Route", "Source", "Route", "data", "." ]
c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e
https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/ipv6_route.py#L199-L256
1,304
JarryShaw/PyPCAPKit
src/protocols/internet/ipv6_route.py
IPv6_Route._read_data_type_2
def _read_data_type_2(self, length): """Read IPv6-Route Type 2 data. Structure of IPv6-Route Type 2 data [RFC 6275]: +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Next Header | Hdr Ext Len=2 | Routing Type=2|Segments Left=1| +-+-+-+-+-+-+-+-+-...
python
def _read_data_type_2(self, length): if length != 20: raise ProtocolError(f'{self.alias}: [Typeno 2] invalid format') _resv = self._read_fileng(4) _home = self._read_fileng(16) data = dict( ip=ipaddress.ip_address(_home), ) return data
[ "def", "_read_data_type_2", "(", "self", ",", "length", ")", ":", "if", "length", "!=", "20", ":", "raise", "ProtocolError", "(", "f'{self.alias}: [Typeno 2] invalid format'", ")", "_resv", "=", "self", ".", "_read_fileng", "(", "4", ")", "_home", "=", "self",...
Read IPv6-Route Type 2 data. Structure of IPv6-Route Type 2 data [RFC 6275]: +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Next Header | Hdr Ext Len=2 | Routing Type=2|Segments Left=1| +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ...
[ "Read", "IPv6", "-", "Route", "Type", "2", "data", "." ]
c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e
https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/ipv6_route.py#L258-L295
1,305
JarryShaw/PyPCAPKit
src/protocols/internet/ipv6_route.py
IPv6_Route._read_data_type_rpl
def _read_data_type_rpl(self, length): """Read IPv6-Route RPL Source data. Structure of IPv6-Route RPL Source data [RFC 6554]: 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-...
python
def _read_data_type_rpl(self, length): _cmpr = self._read_binary(1) _padr = self._read_binary(1) _resv = self._read_fileng(2) _inti = int(_cmpr[:4], base=2) _inte = int(_cmpr[4:], base=2) _plen = int(_padr[:4], base=2) _ilen = 16 - _inti _elen = 16 - _in...
[ "def", "_read_data_type_rpl", "(", "self", ",", "length", ")", ":", "_cmpr", "=", "self", ".", "_read_binary", "(", "1", ")", "_padr", "=", "self", ".", "_read_binary", "(", "1", ")", "_resv", "=", "self", ".", "_read_fileng", "(", "2", ")", "_inti", ...
Read IPv6-Route RPL Source data. Structure of IPv6-Route RPL Source data [RFC 6554]: 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-...
[ "Read", "IPv6", "-", "Route", "RPL", "Source", "data", "." ]
c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e
https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/ipv6_route.py#L297-L352
1,306
desbma/r128gain
r128gain/opusgain.py
write_oggopus_output_gain
def write_oggopus_output_gain(file, new_output_gain): """ Write output gain Opus header for a file. file must be an object successfully used by parse_oggopus_output_gain. """ opus_header_pos = file.tell() # write Opus header with new gain file.seek(opus_header_pos + OGG_OPUS_ID_HEADER_GAIN_OFFSET) file....
python
def write_oggopus_output_gain(file, new_output_gain): opus_header_pos = file.tell() # write Opus header with new gain file.seek(opus_header_pos + OGG_OPUS_ID_HEADER_GAIN_OFFSET) file.write(OGG_OPUS_ID_HEADER_GAIN.pack(new_output_gain)) # compute page crc file.seek(0) page = file.read(opus_header_pos + O...
[ "def", "write_oggopus_output_gain", "(", "file", ",", "new_output_gain", ")", ":", "opus_header_pos", "=", "file", ".", "tell", "(", ")", "# write Opus header with new gain", "file", ".", "seek", "(", "opus_header_pos", "+", "OGG_OPUS_ID_HEADER_GAIN_OFFSET", ")", "fil...
Write output gain Opus header for a file. file must be an object successfully used by parse_oggopus_output_gain.
[ "Write", "output", "gain", "Opus", "header", "for", "a", "file", "." ]
011ee26fe3705a50925571785d206cba2806089a
https://github.com/desbma/r128gain/blob/011ee26fe3705a50925571785d206cba2806089a/r128gain/opusgain.py#L102-L120
1,307
desbma/r128gain
r128gain/opusgain.py
_compute_ogg_page_crc
def _compute_ogg_page_crc(page): """ Compute CRC of an Ogg page. """ page_zero_crc = page[:OGG_FIRST_PAGE_HEADER_CRC_OFFSET] + \ b"\00" * OGG_FIRST_PAGE_HEADER_CRC.size + \ page[OGG_FIRST_PAGE_HEADER_CRC_OFFSET + OGG_FIRST_PAGE_HEADER_CRC.size:] return ogg_page_crc(page_zero_crc)
python
def _compute_ogg_page_crc(page): page_zero_crc = page[:OGG_FIRST_PAGE_HEADER_CRC_OFFSET] + \ b"\00" * OGG_FIRST_PAGE_HEADER_CRC.size + \ page[OGG_FIRST_PAGE_HEADER_CRC_OFFSET + OGG_FIRST_PAGE_HEADER_CRC.size:] return ogg_page_crc(page_zero_crc)
[ "def", "_compute_ogg_page_crc", "(", "page", ")", ":", "page_zero_crc", "=", "page", "[", ":", "OGG_FIRST_PAGE_HEADER_CRC_OFFSET", "]", "+", "b\"\\00\"", "*", "OGG_FIRST_PAGE_HEADER_CRC", ".", "size", "+", "page", "[", "OGG_FIRST_PAGE_HEADER_CRC_OFFSET", "+", "OGG_FIR...
Compute CRC of an Ogg page.
[ "Compute", "CRC", "of", "an", "Ogg", "page", "." ]
011ee26fe3705a50925571785d206cba2806089a
https://github.com/desbma/r128gain/blob/011ee26fe3705a50925571785d206cba2806089a/r128gain/opusgain.py#L123-L128
1,308
desbma/r128gain
r128gain/__init__.py
format_ffmpeg_filter
def format_ffmpeg_filter(name, params): """ Build a string to call a FFMpeg filter. """ return "%s=%s" % (name, ":".join("%s=%s" % (k, v) for k, v in params.items()))
python
def format_ffmpeg_filter(name, params): return "%s=%s" % (name, ":".join("%s=%s" % (k, v) for k, v in params.items()))
[ "def", "format_ffmpeg_filter", "(", "name", ",", "params", ")", ":", "return", "\"%s=%s\"", "%", "(", "name", ",", "\":\"", ".", "join", "(", "\"%s=%s\"", "%", "(", "k", ",", "v", ")", "for", "k", ",", "v", "in", "params", ".", "items", "(", ")", ...
Build a string to call a FFMpeg filter.
[ "Build", "a", "string", "to", "call", "a", "FFMpeg", "filter", "." ]
011ee26fe3705a50925571785d206cba2806089a
https://github.com/desbma/r128gain/blob/011ee26fe3705a50925571785d206cba2806089a/r128gain/__init__.py#L71-L74
1,309
desbma/r128gain
r128gain/__init__.py
scan
def scan(audio_filepaths, *, album_gain=False, skip_tagged=False, thread_count=None, ffmpeg_path=None, executor=None): """ Analyze files, and return a dictionary of filepath to loudness metadata or filepath to future if executor is not None. """ r128_data = {} with contextlib.ExitStack() as cm: if executor i...
python
def scan(audio_filepaths, *, album_gain=False, skip_tagged=False, thread_count=None, ffmpeg_path=None, executor=None): r128_data = {} with contextlib.ExitStack() as cm: if executor is None: if thread_count is None: try: thread_count = len(os.sched_getaffinity(0)) except Attribut...
[ "def", "scan", "(", "audio_filepaths", ",", "*", ",", "album_gain", "=", "False", ",", "skip_tagged", "=", "False", ",", "thread_count", "=", "None", ",", "ffmpeg_path", "=", "None", ",", "executor", "=", "None", ")", ":", "r128_data", "=", "{", "}", "...
Analyze files, and return a dictionary of filepath to loudness metadata or filepath to future if executor is not None.
[ "Analyze", "files", "and", "return", "a", "dictionary", "of", "filepath", "to", "loudness", "metadata", "or", "filepath", "to", "future", "if", "executor", "is", "not", "None", "." ]
011ee26fe3705a50925571785d206cba2806089a
https://github.com/desbma/r128gain/blob/011ee26fe3705a50925571785d206cba2806089a/r128gain/__init__.py#L158-L236
1,310
desbma/r128gain
r128gain/__init__.py
show_scan_report
def show_scan_report(audio_filepaths, album_dir, r128_data): """ Display loudness scan results. """ # track loudness/peak for audio_filepath in audio_filepaths: try: loudness, peak = r128_data[audio_filepath] except KeyError: loudness, peak = "SKIPPED", "SKIPPED" else: loudness = "%....
python
def show_scan_report(audio_filepaths, album_dir, r128_data): # track loudness/peak for audio_filepath in audio_filepaths: try: loudness, peak = r128_data[audio_filepath] except KeyError: loudness, peak = "SKIPPED", "SKIPPED" else: loudness = "%.1f LUFS" % (loudness) if peak is No...
[ "def", "show_scan_report", "(", "audio_filepaths", ",", "album_dir", ",", "r128_data", ")", ":", "# track loudness/peak", "for", "audio_filepath", "in", "audio_filepaths", ":", "try", ":", "loudness", ",", "peak", "=", "r128_data", "[", "audio_filepath", "]", "exc...
Display loudness scan results.
[ "Display", "loudness", "scan", "results", "." ]
011ee26fe3705a50925571785d206cba2806089a
https://github.com/desbma/r128gain/blob/011ee26fe3705a50925571785d206cba2806089a/r128gain/__init__.py#L394-L422
1,311
clemfromspace/scrapy-cloudflare-middleware
setup.py
get_requirements
def get_requirements(source): """Get the requirements from the given ``source`` Parameters ---------- source: str The filename containing the requirements """ install_reqs = parse_requirements(filename=source, session=PipSession()) return [str(ir.req) for ir in install_reqs]
python
def get_requirements(source): install_reqs = parse_requirements(filename=source, session=PipSession()) return [str(ir.req) for ir in install_reqs]
[ "def", "get_requirements", "(", "source", ")", ":", "install_reqs", "=", "parse_requirements", "(", "filename", "=", "source", ",", "session", "=", "PipSession", "(", ")", ")", "return", "[", "str", "(", "ir", ".", "req", ")", "for", "ir", "in", "install...
Get the requirements from the given ``source`` Parameters ---------- source: str The filename containing the requirements
[ "Get", "the", "requirements", "from", "the", "given", "source" ]
03ccea9164418dabe8180053165b0da0bffa0741
https://github.com/clemfromspace/scrapy-cloudflare-middleware/blob/03ccea9164418dabe8180053165b0da0bffa0741/setup.py#L8-L20
1,312
clemfromspace/scrapy-cloudflare-middleware
scrapy_cloudflare_middleware/middlewares.py
CloudFlareMiddleware.is_cloudflare_challenge
def is_cloudflare_challenge(response): """Test if the given response contains the cloudflare's anti-bot protection""" return ( response.status == 503 and response.headers.get('Server', '').startswith(b'cloudflare') and 'jschl_vc' in response.text and 'jsc...
python
def is_cloudflare_challenge(response): return ( response.status == 503 and response.headers.get('Server', '').startswith(b'cloudflare') and 'jschl_vc' in response.text and 'jschl_answer' in response.text )
[ "def", "is_cloudflare_challenge", "(", "response", ")", ":", "return", "(", "response", ".", "status", "==", "503", "and", "response", ".", "headers", ".", "get", "(", "'Server'", ",", "''", ")", ".", "startswith", "(", "b'cloudflare'", ")", "and", "'jschl...
Test if the given response contains the cloudflare's anti-bot protection
[ "Test", "if", "the", "given", "response", "contains", "the", "cloudflare", "s", "anti", "-", "bot", "protection" ]
03ccea9164418dabe8180053165b0da0bffa0741
https://github.com/clemfromspace/scrapy-cloudflare-middleware/blob/03ccea9164418dabe8180053165b0da0bffa0741/scrapy_cloudflare_middleware/middlewares.py#L12-L20
1,313
clemfromspace/scrapy-cloudflare-middleware
scrapy_cloudflare_middleware/middlewares.py
CloudFlareMiddleware.process_response
def process_response(self, request, response, spider): """Handle the a Scrapy response""" if not self.is_cloudflare_challenge(response): return response logger = logging.getLogger('cloudflaremiddleware') logger.debug( 'Cloudflare protection detected on %s, tryi...
python
def process_response(self, request, response, spider): if not self.is_cloudflare_challenge(response): return response logger = logging.getLogger('cloudflaremiddleware') logger.debug( 'Cloudflare protection detected on %s, trying to bypass...', response.url ...
[ "def", "process_response", "(", "self", ",", "request", ",", "response", ",", "spider", ")", ":", "if", "not", "self", ".", "is_cloudflare_challenge", "(", "response", ")", ":", "return", "response", "logger", "=", "logging", ".", "getLogger", "(", "'cloudfl...
Handle the a Scrapy response
[ "Handle", "the", "a", "Scrapy", "response" ]
03ccea9164418dabe8180053165b0da0bffa0741
https://github.com/clemfromspace/scrapy-cloudflare-middleware/blob/03ccea9164418dabe8180053165b0da0bffa0741/scrapy_cloudflare_middleware/middlewares.py#L22-L48
1,314
Fahreeve/aiovk
aiovk/sessions.py
TokenSession.enter_captcha
async def enter_captcha(self, url: str, sid: str) -> str: """ Override this method for processing captcha. :param url: link to captcha image :param sid: captcha id. I do not know why pass here but may be useful :return captcha value """ raise VkCaptchaNeeded(url,...
python
async def enter_captcha(self, url: str, sid: str) -> str: raise VkCaptchaNeeded(url, sid)
[ "async", "def", "enter_captcha", "(", "self", ",", "url", ":", "str", ",", "sid", ":", "str", ")", "->", "str", ":", "raise", "VkCaptchaNeeded", "(", "url", ",", "sid", ")" ]
Override this method for processing captcha. :param url: link to captcha image :param sid: captcha id. I do not know why pass here but may be useful :return captcha value
[ "Override", "this", "method", "for", "processing", "captcha", "." ]
d454649d647d524c6753ba1d6ee16613355ec106
https://github.com/Fahreeve/aiovk/blob/d454649d647d524c6753ba1d6ee16613355ec106/aiovk/sessions.py#L104-L112
1,315
Fahreeve/aiovk
aiovk/sessions.py
ImplicitSession._process_auth_form
async def _process_auth_form(self, html: str) -> (str, str): """ Parsing data from authorization page and filling the form and submitting the form :param html: html page :return: url and html from redirected page """ # Parse page p = AuthPageParser() p.f...
python
async def _process_auth_form(self, html: str) -> (str, str): # Parse page p = AuthPageParser() p.feed(html) p.close() # Get data from hidden inputs form_data = dict(p.inputs) form_url = p.url form_data['email'] = self.login form_data['pass'] = sel...
[ "async", "def", "_process_auth_form", "(", "self", ",", "html", ":", "str", ")", "->", "(", "str", ",", "str", ")", ":", "# Parse page", "p", "=", "AuthPageParser", "(", ")", "p", ".", "feed", "(", "html", ")", "p", ".", "close", "(", ")", "# Get d...
Parsing data from authorization page and filling the form and submitting the form :param html: html page :return: url and html from redirected page
[ "Parsing", "data", "from", "authorization", "page", "and", "filling", "the", "form", "and", "submitting", "the", "form" ]
d454649d647d524c6753ba1d6ee16613355ec106
https://github.com/Fahreeve/aiovk/blob/d454649d647d524c6753ba1d6ee16613355ec106/aiovk/sessions.py#L191-L220
1,316
Fahreeve/aiovk
aiovk/sessions.py
ImplicitSession._process_2auth_form
async def _process_2auth_form(self, html: str) -> (str, str): """ Parsing two-factor authorization page and filling the code :param html: html page :return: url and html from redirected page """ # Parse page p = TwoFactorCodePageParser() p.feed(html) ...
python
async def _process_2auth_form(self, html: str) -> (str, str): # Parse page p = TwoFactorCodePageParser() p.feed(html) p.close() # Prepare request data form_url = p.url form_data = dict(p.inputs) form_data['remember'] = 0 if p.message: ...
[ "async", "def", "_process_2auth_form", "(", "self", ",", "html", ":", "str", ")", "->", "(", "str", ",", "str", ")", ":", "# Parse page", "p", "=", "TwoFactorCodePageParser", "(", ")", "p", ".", "feed", "(", "html", ")", "p", ".", "close", "(", ")", ...
Parsing two-factor authorization page and filling the code :param html: html page :return: url and html from redirected page
[ "Parsing", "two", "-", "factor", "authorization", "page", "and", "filling", "the", "code" ]
d454649d647d524c6753ba1d6ee16613355ec106
https://github.com/Fahreeve/aiovk/blob/d454649d647d524c6753ba1d6ee16613355ec106/aiovk/sessions.py#L222-L244
1,317
Fahreeve/aiovk
aiovk/sessions.py
ImplicitSession._process_access_form
async def _process_access_form(self, html: str) -> (str, str): """ Parsing page with access rights :param html: html page :return: url and html from redirected page """ # Parse page p = AccessPageParser() p.feed(html) p.close() form_url ...
python
async def _process_access_form(self, html: str) -> (str, str): # Parse page p = AccessPageParser() p.feed(html) p.close() form_url = p.url form_data = dict(p.inputs) # Send request url, html = await self.driver.post_text(form_url, form_data) retu...
[ "async", "def", "_process_access_form", "(", "self", ",", "html", ":", "str", ")", "->", "(", "str", ",", "str", ")", ":", "# Parse page", "p", "=", "AccessPageParser", "(", ")", "p", ".", "feed", "(", "html", ")", "p", ".", "close", "(", ")", "for...
Parsing page with access rights :param html: html page :return: url and html from redirected page
[ "Parsing", "page", "with", "access", "rights" ]
d454649d647d524c6753ba1d6ee16613355ec106
https://github.com/Fahreeve/aiovk/blob/d454649d647d524c6753ba1d6ee16613355ec106/aiovk/sessions.py#L246-L263
1,318
Fahreeve/aiovk
aiovk/longpoll.py
BaseLongPoll.wait
async def wait(self, need_pts=False) -> dict: """Send long poll request :param need_pts: need return the pts field """ if not self.base_url: await self._get_long_poll_server(need_pts) params = { 'ts': self.ts, 'key': self.key, } ...
python
async def wait(self, need_pts=False) -> dict: if not self.base_url: await self._get_long_poll_server(need_pts) params = { 'ts': self.ts, 'key': self.key, } params.update(self.base_params) # invalid mimetype from server code, response =...
[ "async", "def", "wait", "(", "self", ",", "need_pts", "=", "False", ")", "->", "dict", ":", "if", "not", "self", ".", "base_url", ":", "await", "self", ".", "_get_long_poll_server", "(", "need_pts", ")", "params", "=", "{", "'ts'", ":", "self", ".", ...
Send long poll request :param need_pts: need return the pts field
[ "Send", "long", "poll", "request" ]
d454649d647d524c6753ba1d6ee16613355ec106
https://github.com/Fahreeve/aiovk/blob/d454649d647d524c6753ba1d6ee16613355ec106/aiovk/longpoll.py#L48-L89
1,319
ericsuh/dirichlet
dirichlet/dirichlet.py
pdf
def pdf(alphas): '''Returns a Dirichlet PDF function''' alphap = alphas - 1 c = np.exp(gammaln(alphas.sum()) - gammaln(alphas).sum()) def dirichlet(xs): '''N x K array''' return c * (xs**alphap).prod(axis=1) return dirichlet
python
def pdf(alphas): '''Returns a Dirichlet PDF function''' alphap = alphas - 1 c = np.exp(gammaln(alphas.sum()) - gammaln(alphas).sum()) def dirichlet(xs): '''N x K array''' return c * (xs**alphap).prod(axis=1) return dirichlet
[ "def", "pdf", "(", "alphas", ")", ":", "alphap", "=", "alphas", "-", "1", "c", "=", "np", ".", "exp", "(", "gammaln", "(", "alphas", ".", "sum", "(", ")", ")", "-", "gammaln", "(", "alphas", ")", ".", "sum", "(", ")", ")", "def", "dirichlet", ...
Returns a Dirichlet PDF function
[ "Returns", "a", "Dirichlet", "PDF", "function" ]
bf39a6d219348cbb4ed95dc195587a9c55c633b9
https://github.com/ericsuh/dirichlet/blob/bf39a6d219348cbb4ed95dc195587a9c55c633b9/dirichlet/dirichlet.py#L95-L102
1,320
ericsuh/dirichlet
dirichlet/dirichlet.py
meanprecision
def meanprecision(a): '''Mean and precision of Dirichlet distribution. Parameters ---------- a : array Parameters of Dirichlet distribution. Returns ------- mean : array Numbers [0,1] of the means of the Dirichlet distribution. precision : float Precision or con...
python
def meanprecision(a): '''Mean and precision of Dirichlet distribution. Parameters ---------- a : array Parameters of Dirichlet distribution. Returns ------- mean : array Numbers [0,1] of the means of the Dirichlet distribution. precision : float Precision or con...
[ "def", "meanprecision", "(", "a", ")", ":", "s", "=", "a", ".", "sum", "(", ")", "m", "=", "a", "/", "s", "return", "(", "m", ",", "s", ")" ]
Mean and precision of Dirichlet distribution. Parameters ---------- a : array Parameters of Dirichlet distribution. Returns ------- mean : array Numbers [0,1] of the means of the Dirichlet distribution. precision : float Precision or concentration parameter of the D...
[ "Mean", "and", "precision", "of", "Dirichlet", "distribution", "." ]
bf39a6d219348cbb4ed95dc195587a9c55c633b9
https://github.com/ericsuh/dirichlet/blob/bf39a6d219348cbb4ed95dc195587a9c55c633b9/dirichlet/dirichlet.py#L104-L121
1,321
ericsuh/dirichlet
dirichlet/dirichlet.py
_fixedpoint
def _fixedpoint(D, tol=1e-7, maxiter=None): '''Simple fixed point iteration method for MLE of Dirichlet distribution''' N, K = D.shape logp = log(D).mean(axis=0) a0 = _init_a(D) # Start updating if maxiter is None: maxiter = MAXINT for i in xrange(maxiter): a1 = _ipsi(psi(a0...
python
def _fixedpoint(D, tol=1e-7, maxiter=None): '''Simple fixed point iteration method for MLE of Dirichlet distribution''' N, K = D.shape logp = log(D).mean(axis=0) a0 = _init_a(D) # Start updating if maxiter is None: maxiter = MAXINT for i in xrange(maxiter): a1 = _ipsi(psi(a0...
[ "def", "_fixedpoint", "(", "D", ",", "tol", "=", "1e-7", ",", "maxiter", "=", "None", ")", ":", "N", ",", "K", "=", "D", ".", "shape", "logp", "=", "log", "(", "D", ")", ".", "mean", "(", "axis", "=", "0", ")", "a0", "=", "_init_a", "(", "D...
Simple fixed point iteration method for MLE of Dirichlet distribution
[ "Simple", "fixed", "point", "iteration", "method", "for", "MLE", "of", "Dirichlet", "distribution" ]
bf39a6d219348cbb4ed95dc195587a9c55c633b9
https://github.com/ericsuh/dirichlet/blob/bf39a6d219348cbb4ed95dc195587a9c55c633b9/dirichlet/dirichlet.py#L173-L189
1,322
ericsuh/dirichlet
dirichlet/dirichlet.py
_meanprecision
def _meanprecision(D, tol=1e-7, maxiter=None): '''Mean and precision alternating method for MLE of Dirichlet distribution''' N, K = D.shape logp = log(D).mean(axis=0) a0 = _init_a(D) s0 = a0.sum() if s0 < 0: a0 = a0/s0 s0 = 1 elif s0 == 0: a0 = ones(a.shape) / len...
python
def _meanprecision(D, tol=1e-7, maxiter=None): '''Mean and precision alternating method for MLE of Dirichlet distribution''' N, K = D.shape logp = log(D).mean(axis=0) a0 = _init_a(D) s0 = a0.sum() if s0 < 0: a0 = a0/s0 s0 = 1 elif s0 == 0: a0 = ones(a.shape) / len...
[ "def", "_meanprecision", "(", "D", ",", "tol", "=", "1e-7", ",", "maxiter", "=", "None", ")", ":", "N", ",", "K", "=", "D", ".", "shape", "logp", "=", "log", "(", "D", ")", ".", "mean", "(", "axis", "=", "0", ")", "a0", "=", "_init_a", "(", ...
Mean and precision alternating method for MLE of Dirichlet distribution
[ "Mean", "and", "precision", "alternating", "method", "for", "MLE", "of", "Dirichlet", "distribution" ]
bf39a6d219348cbb4ed95dc195587a9c55c633b9
https://github.com/ericsuh/dirichlet/blob/bf39a6d219348cbb4ed95dc195587a9c55c633b9/dirichlet/dirichlet.py#L191-L219
1,323
ericsuh/dirichlet
dirichlet/dirichlet.py
_fit_s
def _fit_s(D, a0, logp, tol=1e-7, maxiter=1000): '''Assuming a fixed mean for Dirichlet distribution, maximize likelihood for preicision a.k.a. s''' N, K = D.shape s1 = a0.sum() m = a0 / s1 mlogp = (m*logp).sum() for i in xrange(maxiter): s0 = s1 g = psi(s1) - (m*psi(s1*m)).s...
python
def _fit_s(D, a0, logp, tol=1e-7, maxiter=1000): '''Assuming a fixed mean for Dirichlet distribution, maximize likelihood for preicision a.k.a. s''' N, K = D.shape s1 = a0.sum() m = a0 / s1 mlogp = (m*logp).sum() for i in xrange(maxiter): s0 = s1 g = psi(s1) - (m*psi(s1*m)).s...
[ "def", "_fit_s", "(", "D", ",", "a0", ",", "logp", ",", "tol", "=", "1e-7", ",", "maxiter", "=", "1000", ")", ":", "N", ",", "K", "=", "D", ".", "shape", "s1", "=", "a0", ".", "sum", "(", ")", "m", "=", "a0", "/", "s1", "mlogp", "=", "(",...
Assuming a fixed mean for Dirichlet distribution, maximize likelihood for preicision a.k.a. s
[ "Assuming", "a", "fixed", "mean", "for", "Dirichlet", "distribution", "maximize", "likelihood", "for", "preicision", "a", ".", "k", ".", "a", ".", "s" ]
bf39a6d219348cbb4ed95dc195587a9c55c633b9
https://github.com/ericsuh/dirichlet/blob/bf39a6d219348cbb4ed95dc195587a9c55c633b9/dirichlet/dirichlet.py#L221-L249
1,324
ericsuh/dirichlet
dirichlet/dirichlet.py
_fit_m
def _fit_m(D, a0, logp, tol=1e-7, maxiter=1000): '''With fixed precision s, maximize mean m''' N,K = D.shape s = a0.sum() for i in xrange(maxiter): m = a0 / s a1 = _ipsi(logp + (m*(psi(a0) - logp)).sum()) a1 = a1/a1.sum() * s if norm(a1 - a0) < tol: return a...
python
def _fit_m(D, a0, logp, tol=1e-7, maxiter=1000): '''With fixed precision s, maximize mean m''' N,K = D.shape s = a0.sum() for i in xrange(maxiter): m = a0 / s a1 = _ipsi(logp + (m*(psi(a0) - logp)).sum()) a1 = a1/a1.sum() * s if norm(a1 - a0) < tol: return a...
[ "def", "_fit_m", "(", "D", ",", "a0", ",", "logp", ",", "tol", "=", "1e-7", ",", "maxiter", "=", "1000", ")", ":", "N", ",", "K", "=", "D", ".", "shape", "s", "=", "a0", ".", "sum", "(", ")", "for", "i", "in", "xrange", "(", "maxiter", ")",...
With fixed precision s, maximize mean m
[ "With", "fixed", "precision", "s", "maximize", "mean", "m" ]
bf39a6d219348cbb4ed95dc195587a9c55c633b9
https://github.com/ericsuh/dirichlet/blob/bf39a6d219348cbb4ed95dc195587a9c55c633b9/dirichlet/dirichlet.py#L251-L266
1,325
ericsuh/dirichlet
dirichlet/dirichlet.py
_piecewise
def _piecewise(x, condlist, funclist, *args, **kw): '''Fixed version of numpy.piecewise for 0-d arrays''' x = asanyarray(x) n2 = len(funclist) if isscalar(condlist) or \ (isinstance(condlist, np.ndarray) and condlist.ndim == 0) or \ (x.ndim > 0 and condlist[0].ndim == 0): ...
python
def _piecewise(x, condlist, funclist, *args, **kw): '''Fixed version of numpy.piecewise for 0-d arrays''' x = asanyarray(x) n2 = len(funclist) if isscalar(condlist) or \ (isinstance(condlist, np.ndarray) and condlist.ndim == 0) or \ (x.ndim > 0 and condlist[0].ndim == 0): ...
[ "def", "_piecewise", "(", "x", ",", "condlist", ",", "funclist", ",", "*", "args", ",", "*", "*", "kw", ")", ":", "x", "=", "asanyarray", "(", "x", ")", "n2", "=", "len", "(", "funclist", ")", "if", "isscalar", "(", "condlist", ")", "or", "(", ...
Fixed version of numpy.piecewise for 0-d arrays
[ "Fixed", "version", "of", "numpy", ".", "piecewise", "for", "0", "-", "d", "arrays" ]
bf39a6d219348cbb4ed95dc195587a9c55c633b9
https://github.com/ericsuh/dirichlet/blob/bf39a6d219348cbb4ed95dc195587a9c55c633b9/dirichlet/dirichlet.py#L268-L316
1,326
ericsuh/dirichlet
dirichlet/dirichlet.py
_init_a
def _init_a(D): '''Initial guess for Dirichlet alpha parameters given data D''' E = D.mean(axis=0) E2 = (D**2).mean(axis=0) return ((E[0] - E2[0])/(E2[0]-E[0]**2)) * E
python
def _init_a(D): '''Initial guess for Dirichlet alpha parameters given data D''' E = D.mean(axis=0) E2 = (D**2).mean(axis=0) return ((E[0] - E2[0])/(E2[0]-E[0]**2)) * E
[ "def", "_init_a", "(", "D", ")", ":", "E", "=", "D", ".", "mean", "(", "axis", "=", "0", ")", "E2", "=", "(", "D", "**", "2", ")", ".", "mean", "(", "axis", "=", "0", ")", "return", "(", "(", "E", "[", "0", "]", "-", "E2", "[", "0", "...
Initial guess for Dirichlet alpha parameters given data D
[ "Initial", "guess", "for", "Dirichlet", "alpha", "parameters", "given", "data", "D" ]
bf39a6d219348cbb4ed95dc195587a9c55c633b9
https://github.com/ericsuh/dirichlet/blob/bf39a6d219348cbb4ed95dc195587a9c55c633b9/dirichlet/dirichlet.py#L318-L322
1,327
ericsuh/dirichlet
dirichlet/simplex.py
scatter
def scatter(points, vertexlabels=None, **kwargs): '''Scatter plot of barycentric 2-simplex points on a 2D triangle. :param points: Points on a 2-simplex. :type points: N x 3 list or ndarray. :param vertexlabels: Labels for corners of plot in the order ``(a, b, c)`` where ``a == (1,0,0)``, ``b =...
python
def scatter(points, vertexlabels=None, **kwargs): '''Scatter plot of barycentric 2-simplex points on a 2D triangle. :param points: Points on a 2-simplex. :type points: N x 3 list or ndarray. :param vertexlabels: Labels for corners of plot in the order ``(a, b, c)`` where ``a == (1,0,0)``, ``b =...
[ "def", "scatter", "(", "points", ",", "vertexlabels", "=", "None", ",", "*", "*", "kwargs", ")", ":", "if", "vertexlabels", "is", "None", ":", "vertexlabels", "=", "(", "'1'", ",", "'2'", ",", "'3'", ")", "projected", "=", "cartesian", "(", "points", ...
Scatter plot of barycentric 2-simplex points on a 2D triangle. :param points: Points on a 2-simplex. :type points: N x 3 list or ndarray. :param vertexlabels: Labels for corners of plot in the order ``(a, b, c)`` where ``a == (1,0,0)``, ``b == (0,1,0)``, ``c == (0,0,1)``. :type vertexla...
[ "Scatter", "plot", "of", "barycentric", "2", "-", "simplex", "points", "on", "a", "2D", "triangle", "." ]
bf39a6d219348cbb4ed95dc195587a9c55c633b9
https://github.com/ericsuh/dirichlet/blob/bf39a6d219348cbb4ed95dc195587a9c55c633b9/dirichlet/simplex.py#L54-L72
1,328
ericsuh/dirichlet
dirichlet/simplex.py
contour
def contour(f, vertexlabels=None, **kwargs): '''Contour line plot on a 2D triangle of a function evaluated at barycentric 2-simplex points. :param f: Function to evaluate on N x 3 ndarray of coordinates :type f: ``ufunc`` :param vertexlabels: Labels for corners of plot in the order ``(a, b,...
python
def contour(f, vertexlabels=None, **kwargs): '''Contour line plot on a 2D triangle of a function evaluated at barycentric 2-simplex points. :param f: Function to evaluate on N x 3 ndarray of coordinates :type f: ``ufunc`` :param vertexlabels: Labels for corners of plot in the order ``(a, b,...
[ "def", "contour", "(", "f", ",", "vertexlabels", "=", "None", ",", "*", "*", "kwargs", ")", ":", "return", "_contour", "(", "f", ",", "vertexlabels", ",", "contourfunc", "=", "plt", ".", "tricontour", ",", "*", "*", "kwargs", ")" ]
Contour line plot on a 2D triangle of a function evaluated at barycentric 2-simplex points. :param f: Function to evaluate on N x 3 ndarray of coordinates :type f: ``ufunc`` :param vertexlabels: Labels for corners of plot in the order ``(a, b, c)`` where ``a == (1,0,0)``, ``b == (0,1,0)``, ...
[ "Contour", "line", "plot", "on", "a", "2D", "triangle", "of", "a", "function", "evaluated", "at", "barycentric", "2", "-", "simplex", "points", "." ]
bf39a6d219348cbb4ed95dc195587a9c55c633b9
https://github.com/ericsuh/dirichlet/blob/bf39a6d219348cbb4ed95dc195587a9c55c633b9/dirichlet/simplex.py#L74-L86
1,329
ericsuh/dirichlet
dirichlet/simplex.py
contourf
def contourf(f, vertexlabels=None, **kwargs): '''Filled contour plot on a 2D triangle of a function evaluated at barycentric 2-simplex points. Function signature is identical to :func:`contour` with the caveat that ``**kwargs`` are passed on to :func:`plt.tricontourf`.''' return _contour(f, vertexl...
python
def contourf(f, vertexlabels=None, **kwargs): '''Filled contour plot on a 2D triangle of a function evaluated at barycentric 2-simplex points. Function signature is identical to :func:`contour` with the caveat that ``**kwargs`` are passed on to :func:`plt.tricontourf`.''' return _contour(f, vertexl...
[ "def", "contourf", "(", "f", ",", "vertexlabels", "=", "None", ",", "*", "*", "kwargs", ")", ":", "return", "_contour", "(", "f", ",", "vertexlabels", ",", "contourfunc", "=", "plt", ".", "tricontourf", ",", "*", "*", "kwargs", ")" ]
Filled contour plot on a 2D triangle of a function evaluated at barycentric 2-simplex points. Function signature is identical to :func:`contour` with the caveat that ``**kwargs`` are passed on to :func:`plt.tricontourf`.
[ "Filled", "contour", "plot", "on", "a", "2D", "triangle", "of", "a", "function", "evaluated", "at", "barycentric", "2", "-", "simplex", "points", "." ]
bf39a6d219348cbb4ed95dc195587a9c55c633b9
https://github.com/ericsuh/dirichlet/blob/bf39a6d219348cbb4ed95dc195587a9c55c633b9/dirichlet/simplex.py#L88-L94
1,330
ericsuh/dirichlet
dirichlet/simplex.py
_contour
def _contour(f, vertexlabels=None, contourfunc=None, **kwargs): '''Workhorse function for the above, where ``contourfunc`` is the contour plotting function to use for actual plotting.''' if contourfunc is None: contourfunc = plt.tricontour if vertexlabels is None: vertexlabels = ('1','2...
python
def _contour(f, vertexlabels=None, contourfunc=None, **kwargs): '''Workhorse function for the above, where ``contourfunc`` is the contour plotting function to use for actual plotting.''' if contourfunc is None: contourfunc = plt.tricontour if vertexlabels is None: vertexlabels = ('1','2...
[ "def", "_contour", "(", "f", ",", "vertexlabels", "=", "None", ",", "contourfunc", "=", "None", ",", "*", "*", "kwargs", ")", ":", "if", "contourfunc", "is", "None", ":", "contourfunc", "=", "plt", ".", "tricontour", "if", "vertexlabels", "is", "None", ...
Workhorse function for the above, where ``contourfunc`` is the contour plotting function to use for actual plotting.
[ "Workhorse", "function", "for", "the", "above", "where", "contourfunc", "is", "the", "contour", "plotting", "function", "to", "use", "for", "actual", "plotting", "." ]
bf39a6d219348cbb4ed95dc195587a9c55c633b9
https://github.com/ericsuh/dirichlet/blob/bf39a6d219348cbb4ed95dc195587a9c55c633b9/dirichlet/simplex.py#L96-L114
1,331
insightindustry/validator-collection
validator_collection/_decorators.py
disable_on_env
def disable_on_env(func): """Disable the ``func`` called if its name is present in ``VALIDATORS_DISABLED``. :param func: The function/validator to be disabled. :type func: callable :returns: If disabled, the ``value`` (first positional argument) passed to ``func``. If enabled, the result of ``fu...
python
def disable_on_env(func): @wraps(func) def func_wrapper(*args, **kwargs): # pylint: disable=C0111, C0103 function_name = func.__name__ VALIDATORS_DISABLED = os.getenv('VALIDATORS_DISABLED', '') disabled_functions = [x.strip() for x in VALIDATORS_DISABLED.split(',')] forc...
[ "def", "disable_on_env", "(", "func", ")", ":", "@", "wraps", "(", "func", ")", "def", "func_wrapper", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "# pylint: disable=C0111, C0103", "function_name", "=", "func", ".", "__name__", "VALIDATORS_DISABLED", ...
Disable the ``func`` called if its name is present in ``VALIDATORS_DISABLED``. :param func: The function/validator to be disabled. :type func: callable :returns: If disabled, the ``value`` (first positional argument) passed to ``func``. If enabled, the result of ``func``.
[ "Disable", "the", "func", "called", "if", "its", "name", "is", "present", "in", "VALIDATORS_DISABLED", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/_decorators.py#L21-L53
1,332
insightindustry/validator-collection
validator_collection/_decorators.py
disable_checker_on_env
def disable_checker_on_env(func): """Disable the ``func`` called if its name is present in ``CHECKERS_DISABLED``. :param func: The function/validator to be disabled. :type func: callable :returns: If disabled, ``True``. If enabled, the result of ``func``. """ @wraps(func) def func_wrapper...
python
def disable_checker_on_env(func): @wraps(func) def func_wrapper(*args, **kwargs): # pylint: disable=C0111, C0103 function_name = func.__name__ CHECKERS_DISABLED = os.getenv('CHECKERS_DISABLED', '') disabled_functions = [x.strip() for x in CHECKERS_DISABLED.split(',')] fo...
[ "def", "disable_checker_on_env", "(", "func", ")", ":", "@", "wraps", "(", "func", ")", "def", "func_wrapper", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "# pylint: disable=C0111, C0103", "function_name", "=", "func", ".", "__name__", "CHECKERS_DISAB...
Disable the ``func`` called if its name is present in ``CHECKERS_DISABLED``. :param func: The function/validator to be disabled. :type func: callable :returns: If disabled, ``True``. If enabled, the result of ``func``.
[ "Disable", "the", "func", "called", "if", "its", "name", "is", "present", "in", "CHECKERS_DISABLED", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/_decorators.py#L56-L79
1,333
insightindustry/validator-collection
validator_collection/validators.py
string
def string(value, allow_empty = False, coerce_value = False, minimum_length = None, maximum_length = None, whitespace_padding = False, **kwargs): """Validate that ``value`` is a valid string. :param value: The value to validate. :type value:...
python
def string(value, allow_empty = False, coerce_value = False, minimum_length = None, maximum_length = None, whitespace_padding = False, **kwargs): if not value and not allow_empty: raise errors.EmptyValueError('value (%s) was empty' % value) ...
[ "def", "string", "(", "value", ",", "allow_empty", "=", "False", ",", "coerce_value", "=", "False", ",", "minimum_length", "=", "None", ",", "maximum_length", "=", "None", ",", "whitespace_padding", "=", "False", ",", "*", "*", "kwargs", ")", ":", "if", ...
Validate that ``value`` is a valid string. :param value: The value to validate. :type value: :class:`str <python:str>` / :obj:`None <python:None>` :param allow_empty: If ``True``, returns :obj:`None <python:None>` if ``value`` is empty. If ``False``, raises a :class:`EmptyValueError <validator...
[ "Validate", "that", "value", "is", "a", "valid", "string", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/validators.py#L172-L245
1,334
insightindustry/validator-collection
validator_collection/validators.py
iterable
def iterable(value, allow_empty = False, forbid_literals = (str, bytes), minimum_length = None, maximum_length = None, **kwargs): """Validate that ``value`` is a valid iterable. :param value: The value to validate. :param allow_empty: If ``T...
python
def iterable(value, allow_empty = False, forbid_literals = (str, bytes), minimum_length = None, maximum_length = None, **kwargs): if not value and not allow_empty: raise errors.EmptyValueError('value (%s) was empty' % value) elif value is ...
[ "def", "iterable", "(", "value", ",", "allow_empty", "=", "False", ",", "forbid_literals", "=", "(", "str", ",", "bytes", ")", ",", "minimum_length", "=", "None", ",", "maximum_length", "=", "None", ",", "*", "*", "kwargs", ")", ":", "if", "not", "valu...
Validate that ``value`` is a valid iterable. :param value: The value to validate. :param allow_empty: If ``True``, returns :obj:`None <python:None>` if ``value`` is empty. If ``False``, raises a :class:`EmptyValueError <validator_collection.errors.EmptyValueError>` if ``value`` is empty. Def...
[ "Validate", "that", "value", "is", "a", "valid", "iterable", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/validators.py#L249-L311
1,335
insightindustry/validator-collection
validator_collection/validators.py
not_empty
def not_empty(value, allow_empty = False, **kwargs): """Validate that ``value`` is not empty. :param value: The value to validate. :param allow_empty: If ``True``, returns :obj:`None <python:None>` if ``value`` is empty. If ``False``, raises a :class:`EmptyValueErro...
python
def not_empty(value, allow_empty = False, **kwargs): if not value and allow_empty: return None elif not value: raise errors.EmptyValueError('value was empty') return value
[ "def", "not_empty", "(", "value", ",", "allow_empty", "=", "False", ",", "*", "*", "kwargs", ")", ":", "if", "not", "value", "and", "allow_empty", ":", "return", "None", "elif", "not", "value", ":", "raise", "errors", ".", "EmptyValueError", "(", "'value...
Validate that ``value`` is not empty. :param value: The value to validate. :param allow_empty: If ``True``, returns :obj:`None <python:None>` if ``value`` is empty. If ``False``, raises a :class:`EmptyValueError <validator_collection.errors.EmptyValueError>` if ``value`` is empty. Defaults t...
[ "Validate", "that", "value", "is", "not", "empty", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/validators.py#L343-L365
1,336
insightindustry/validator-collection
validator_collection/validators.py
variable_name
def variable_name(value, allow_empty = False, **kwargs): """Validate that the value is a valid Python variable name. .. caution:: This function does **NOT** check whether the variable exists. It only checks that the ``value`` would work as a Python variable (or ...
python
def variable_name(value, allow_empty = False, **kwargs): if not value and not allow_empty: raise errors.EmptyValueError('value (%s) was empty' % value) elif not value: return None try: parse('%s = None' % value) except (SyntaxError, ValueError...
[ "def", "variable_name", "(", "value", ",", "allow_empty", "=", "False", ",", "*", "*", "kwargs", ")", ":", "if", "not", "value", "and", "not", "allow_empty", ":", "raise", "errors", ".", "EmptyValueError", "(", "'value (%s) was empty'", "%", "value", ")", ...
Validate that the value is a valid Python variable name. .. caution:: This function does **NOT** check whether the variable exists. It only checks that the ``value`` would work as a Python variable (or class, or function, etc.) name. :param value: The value to validate. :param allow_em...
[ "Validate", "that", "the", "value", "is", "a", "valid", "Python", "variable", "name", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/validators.py#L369-L406
1,337
insightindustry/validator-collection
validator_collection/validators.py
json
def json(value, schema = None, allow_empty = False, json_serializer = None, **kwargs): """Validate that ``value`` conforms to the supplied JSON Schema. .. note:: ``schema`` supports JSON Schema Drafts 3 - 7. Unless the JSON Schema indicates the meta-schema using...
python
def json(value, schema = None, allow_empty = False, json_serializer = None, **kwargs): original_value = value original_schema = schema if not value and not allow_empty: raise errors.EmptyValueError('value (%s) was empty' % value) elif not value: retur...
[ "def", "json", "(", "value", ",", "schema", "=", "None", ",", "allow_empty", "=", "False", ",", "json_serializer", "=", "None", ",", "*", "*", "kwargs", ")", ":", "original_value", "=", "value", "original_schema", "=", "schema", "if", "not", "value", "an...
Validate that ``value`` conforms to the supplied JSON Schema. .. note:: ``schema`` supports JSON Schema Drafts 3 - 7. Unless the JSON Schema indicates the meta-schema using a ``$schema`` property, the schema will be assumed to conform to Draft 7. .. hint:: If either ``value`` or ``sc...
[ "Validate", "that", "value", "conforms", "to", "the", "supplied", "JSON", "Schema", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/validators.py#L474-L568
1,338
insightindustry/validator-collection
validator_collection/validators.py
numeric
def numeric(value, allow_empty = False, minimum = None, maximum = None, **kwargs): """Validate that ``value`` is a numeric value. :param value: The value to validate. :param allow_empty: If ``True``, returns :obj:`None <python:None>` if ``value`` is :o...
python
def numeric(value, allow_empty = False, minimum = None, maximum = None, **kwargs): if maximum is None: maximum = POSITIVE_INFINITY else: maximum = numeric(maximum) if minimum is None: minimum = NEGATIVE_INFINITY else: minimu...
[ "def", "numeric", "(", "value", ",", "allow_empty", "=", "False", ",", "minimum", "=", "None", ",", "maximum", "=", "None", ",", "*", "*", "kwargs", ")", ":", "if", "maximum", "is", "None", ":", "maximum", "=", "POSITIVE_INFINITY", "else", ":", "maximu...
Validate that ``value`` is a numeric value. :param value: The value to validate. :param allow_empty: If ``True``, returns :obj:`None <python:None>` if ``value`` is :obj:`None <python:None>`. If ``False``, raises an :class:`EmptyValueError <validator_collection.errors.EmptyValueError>` if ``v...
[ "Validate", "that", "value", "is", "a", "numeric", "value", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/validators.py#L1225-L1295
1,339
insightindustry/validator-collection
validator_collection/validators.py
_numeric_coercion
def _numeric_coercion(value, coercion_function = None, allow_empty = False, minimum = None, maximum = None): """Validate that ``value`` is numeric and coerce using ``coercion_function``. :param value: The value to validate....
python
def _numeric_coercion(value, coercion_function = None, allow_empty = False, minimum = None, maximum = None): if coercion_function is None: raise errors.CoercionFunctionEmptyError('coercion_function cannot be empty') ...
[ "def", "_numeric_coercion", "(", "value", ",", "coercion_function", "=", "None", ",", "allow_empty", "=", "False", ",", "minimum", "=", "None", ",", "maximum", "=", "None", ")", ":", "if", "coercion_function", "is", "None", ":", "raise", "errors", ".", "Co...
Validate that ``value`` is numeric and coerce using ``coercion_function``. :param value: The value to validate. :param coercion_function: The function to use to coerce ``value`` to the desired type. :type coercion_function: callable :param allow_empty: If ``True``, returns :obj:`None <python:No...
[ "Validate", "that", "value", "is", "numeric", "and", "coerce", "using", "coercion_function", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/validators.py#L1543-L1594
1,340
insightindustry/validator-collection
validator_collection/validators.py
path
def path(value, allow_empty = False, **kwargs): """Validate that ``value`` is a valid path-like object. :param value: The value to validate. :param allow_empty: If ``True``, returns :obj:`None <python:None>` if ``value`` is empty. If ``False``, raises a :class:`EmptyValueErro...
python
def path(value, allow_empty = False, **kwargs): if not value and not allow_empty: raise errors.EmptyValueError('value (%s) was empty' % value) elif not value: return None if hasattr(os, 'PathLike'): if not isinstance(value, (str, bytes, int, os.PathLike)): ...
[ "def", "path", "(", "value", ",", "allow_empty", "=", "False", ",", "*", "*", "kwargs", ")", ":", "if", "not", "value", "and", "not", "allow_empty", ":", "raise", "errors", ".", "EmptyValueError", "(", "'value (%s) was empty'", "%", "value", ")", "elif", ...
Validate that ``value`` is a valid path-like object. :param value: The value to validate. :param allow_empty: If ``True``, returns :obj:`None <python:None>` if ``value`` is empty. If ``False``, raises a :class:`EmptyValueError <validator_collection.errors.EmptyValueError>` if ``value`` is em...
[ "Validate", "that", "value", "is", "a", "valid", "path", "-", "like", "object", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/validators.py#L1666-L1701
1,341
insightindustry/validator-collection
validator_collection/validators.py
path_exists
def path_exists(value, allow_empty = False, **kwargs): """Validate that ``value`` is a path-like object that exists on the local filesystem. :param value: The value to validate. :param allow_empty: If ``True``, returns :obj:`None <python:None>` if ``value`` is emp...
python
def path_exists(value, allow_empty = False, **kwargs): if not value and not allow_empty: raise errors.EmptyValueError('value (%s) was empty' % value) elif not value: return None value = path(value, force_run = True) # pyl...
[ "def", "path_exists", "(", "value", ",", "allow_empty", "=", "False", ",", "*", "*", "kwargs", ")", ":", "if", "not", "value", "and", "not", "allow_empty", ":", "raise", "errors", ".", "EmptyValueError", "(", "'value (%s) was empty'", "%", "value", ")", "e...
Validate that ``value`` is a path-like object that exists on the local filesystem. :param value: The value to validate. :param allow_empty: If ``True``, returns :obj:`None <python:None>` if ``value`` is empty. If ``False``, raises a :class:`EmptyValueError <validator_collection.errors.EmptyVal...
[ "Validate", "that", "value", "is", "a", "path", "-", "like", "object", "that", "exists", "on", "the", "local", "filesystem", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/validators.py#L1705-L1738
1,342
insightindustry/validator-collection
validator_collection/validators.py
file_exists
def file_exists(value, allow_empty = False, **kwargs): """Validate that ``value`` is a valid file that exists on the local filesystem. :param value: The value to validate. :param allow_empty: If ``True``, returns :obj:`None <python:None>` if ``value`` is empty. If ``F...
python
def file_exists(value, allow_empty = False, **kwargs): if not value and not allow_empty: raise errors.EmptyValueError('value (%s) was empty' % value) elif not value: return None value = path_exists(value, force_run = True) # pyl...
[ "def", "file_exists", "(", "value", ",", "allow_empty", "=", "False", ",", "*", "*", "kwargs", ")", ":", "if", "not", "value", "and", "not", "allow_empty", ":", "raise", "errors", ".", "EmptyValueError", "(", "'value (%s) was empty'", "%", "value", ")", "e...
Validate that ``value`` is a valid file that exists on the local filesystem. :param value: The value to validate. :param allow_empty: If ``True``, returns :obj:`None <python:None>` if ``value`` is empty. If ``False``, raises a :class:`EmptyValueError <validator_collection.errors.EmptyValueError>` ...
[ "Validate", "that", "value", "is", "a", "valid", "file", "that", "exists", "on", "the", "local", "filesystem", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/validators.py#L1742-L1775
1,343
insightindustry/validator-collection
validator_collection/validators.py
directory_exists
def directory_exists(value, allow_empty = False, **kwargs): """Validate that ``value`` is a valid directory that exists on the local filesystem. :param value: The value to validate. :param allow_empty: If ``True``, returns :obj:`None <python:None>` if ``...
python
def directory_exists(value, allow_empty = False, **kwargs): if not value and not allow_empty: raise errors.EmptyValueError('value (%s) was empty' % value) elif not value: return None value = path_exists(value, force_run = True) ...
[ "def", "directory_exists", "(", "value", ",", "allow_empty", "=", "False", ",", "*", "*", "kwargs", ")", ":", "if", "not", "value", "and", "not", "allow_empty", ":", "raise", "errors", ".", "EmptyValueError", "(", "'value (%s) was empty'", "%", "value", ")",...
Validate that ``value`` is a valid directory that exists on the local filesystem. :param value: The value to validate. :param allow_empty: If ``True``, returns :obj:`None <python:None>` if ``value`` is empty. If ``False``, raises a :class:`EmptyValueError <validator_collection.errors.EmptyValu...
[ "Validate", "that", "value", "is", "a", "valid", "directory", "that", "exists", "on", "the", "local", "filesystem", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/validators.py#L1779-L1813
1,344
insightindustry/validator-collection
validator_collection/validators.py
readable
def readable(value, allow_empty = False, **kwargs): """Validate that ``value`` is a path to a readable file. .. caution:: **Use of this validator is an anti-pattern and should be used with caution.** Validating the readability of a file *before* attempting to read it ...
python
def readable(value, allow_empty = False, **kwargs): if not value and not allow_empty: raise errors.EmptyValueError('value (%s) was empty' % value) elif not value: return None value = file_exists(value, force_run = True) # pylint: disa...
[ "def", "readable", "(", "value", ",", "allow_empty", "=", "False", ",", "*", "*", "kwargs", ")", ":", "if", "not", "value", "and", "not", "allow_empty", ":", "raise", "errors", ".", "EmptyValueError", "(", "'value (%s) was empty'", "%", "value", ")", "elif...
Validate that ``value`` is a path to a readable file. .. caution:: **Use of this validator is an anti-pattern and should be used with caution.** Validating the readability of a file *before* attempting to read it exposes your code to a bug called `TOCTOU <https://en.wikipedia.org/wiki/Tim...
[ "Validate", "that", "value", "is", "a", "path", "to", "a", "readable", "file", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/validators.py#L1817-L1880
1,345
insightindustry/validator-collection
validator_collection/validators.py
writeable
def writeable(value, allow_empty = False, **kwargs): """Validate that ``value`` is a path to a writeable file. .. caution:: This validator does **NOT** work correctly on a Windows file system. This is due to the vagaries of how Windows manages its file system and the ...
python
def writeable(value, allow_empty = False, **kwargs): if not value and not allow_empty: raise errors.EmptyValueError('value (%s) was empty' % value) elif not value: return None value = path(value, force_run = True) if sys.platform in ['win32', 'cygwin']: ...
[ "def", "writeable", "(", "value", ",", "allow_empty", "=", "False", ",", "*", "*", "kwargs", ")", ":", "if", "not", "value", "and", "not", "allow_empty", ":", "raise", "errors", ".", "EmptyValueError", "(", "'value (%s) was empty'", "%", "value", ")", "eli...
Validate that ``value`` is a path to a writeable file. .. caution:: This validator does **NOT** work correctly on a Windows file system. This is due to the vagaries of how Windows manages its file system and the various ways in which it can manage file permission. If called on a Windows f...
[ "Validate", "that", "value", "is", "a", "path", "to", "a", "writeable", "file", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/validators.py#L1883-L1968
1,346
insightindustry/validator-collection
validator_collection/validators.py
executable
def executable(value, allow_empty = False, **kwargs): """Validate that ``value`` is a path to an executable file. .. caution:: This validator does **NOT** work correctly on a Windows file system. This is due to the vagaries of how Windows manages its file system and t...
python
def executable(value, allow_empty = False, **kwargs): if not value and not allow_empty: raise errors.EmptyValueError('value (%s) was empty' % value) elif not value: return None value = file_exists(value, force_run = True) if sys.platform in ['win32', 'cygw...
[ "def", "executable", "(", "value", ",", "allow_empty", "=", "False", ",", "*", "*", "kwargs", ")", ":", "if", "not", "value", "and", "not", "allow_empty", ":", "raise", "errors", ".", "EmptyValueError", "(", "'value (%s) was empty'", "%", "value", ")", "el...
Validate that ``value`` is a path to an executable file. .. caution:: This validator does **NOT** work correctly on a Windows file system. This is due to the vagaries of how Windows manages its file system and the various ways in which it can manage file permission. If called on a Windows...
[ "Validate", "that", "value", "is", "a", "path", "to", "an", "executable", "file", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/validators.py#L1971-L2049
1,347
insightindustry/validator-collection
validator_collection/validators.py
url
def url(value, allow_empty = False, allow_special_ips = False, **kwargs): """Validate that ``value`` is a valid URL. .. note:: URL validation is...complicated. The methodology that we have adopted here is *generally* compliant with `RFC 1738 <https://tools.ietf.org/ht...
python
def url(value, allow_empty = False, allow_special_ips = False, **kwargs): is_recursive = kwargs.pop('is_recursive', False) if not value and not allow_empty: raise errors.EmptyValueError('value (%s) was empty' % value) elif not value: return None if not isinstanc...
[ "def", "url", "(", "value", ",", "allow_empty", "=", "False", ",", "allow_special_ips", "=", "False", ",", "*", "*", "kwargs", ")", ":", "is_recursive", "=", "kwargs", ".", "pop", "(", "'is_recursive'", ",", "False", ")", "if", "not", "value", "and", "...
Validate that ``value`` is a valid URL. .. note:: URL validation is...complicated. The methodology that we have adopted here is *generally* compliant with `RFC 1738 <https://tools.ietf.org/html/rfc1738>`_, `RFC 6761 <https://tools.ietf.org/html/rfc6761>`_, `RFC 2181 <https://tools.ie...
[ "Validate", "that", "value", "is", "a", "valid", "URL", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/validators.py#L2216-L2306
1,348
insightindustry/validator-collection
validator_collection/validators.py
domain
def domain(value, allow_empty = False, allow_ips = False, **kwargs): """Validate that ``value`` is a valid domain name. .. caution:: This validator does not verify that ``value`` **exists** as a domain. It merely verifies that its contents *might* exist as a domain...
python
def domain(value, allow_empty = False, allow_ips = False, **kwargs): is_recursive = kwargs.pop('is_recursive', False) if not value and not allow_empty: raise errors.EmptyValueError('value (%s) was empty' % value) elif not value: return None if not isins...
[ "def", "domain", "(", "value", ",", "allow_empty", "=", "False", ",", "allow_ips", "=", "False", ",", "*", "*", "kwargs", ")", ":", "is_recursive", "=", "kwargs", ".", "pop", "(", "'is_recursive'", ",", "False", ")", "if", "not", "value", "and", "not",...
Validate that ``value`` is a valid domain name. .. caution:: This validator does not verify that ``value`` **exists** as a domain. It merely verifies that its contents *might* exist as a domain. .. note:: This validator checks to validate that ``value`` resembles a valid domain name....
[ "Validate", "that", "value", "is", "a", "valid", "domain", "name", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/validators.py#L2310-L2418
1,349
insightindustry/validator-collection
validator_collection/validators.py
ip_address
def ip_address(value, allow_empty = False, **kwargs): """Validate that ``value`` is a valid IP address. .. note:: First, the validator will check if the address is a valid IPv6 address. If that doesn't work, the validator will check if the address is a valid IPv...
python
def ip_address(value, allow_empty = False, **kwargs): if not value and not allow_empty: raise errors.EmptyValueError('value (%s) was empty' % value) elif not value: return None if is_py2 and value and isinstance(value, unicode): value = value.encode('ut...
[ "def", "ip_address", "(", "value", ",", "allow_empty", "=", "False", ",", "*", "*", "kwargs", ")", ":", "if", "not", "value", "and", "not", "allow_empty", ":", "raise", "errors", ".", "EmptyValueError", "(", "'value (%s) was empty'", "%", "value", ")", "el...
Validate that ``value`` is a valid IP address. .. note:: First, the validator will check if the address is a valid IPv6 address. If that doesn't work, the validator will check if the address is a valid IPv4 address. If neither works, the validator will raise an error (as always). :pa...
[ "Validate", "that", "value", "is", "a", "valid", "IP", "address", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/validators.py#L2422-L2471
1,350
insightindustry/validator-collection
validator_collection/validators.py
ipv4
def ipv4(value, allow_empty = False): """Validate that ``value`` is a valid IP version 4 address. :param value: The value to validate. :param allow_empty: If ``True``, returns :obj:`None <python:None>` if ``value`` is empty. If ``False``, raises a :class:`EmptyValueError <validator_collection....
python
def ipv4(value, allow_empty = False): if not value and allow_empty is False: raise errors.EmptyValueError('value (%s) was empty' % value) elif not value: return None try: components = value.split('.') except AttributeError: raise errors.InvalidIPAddressError('value (%s) ...
[ "def", "ipv4", "(", "value", ",", "allow_empty", "=", "False", ")", ":", "if", "not", "value", "and", "allow_empty", "is", "False", ":", "raise", "errors", ".", "EmptyValueError", "(", "'value (%s) was empty'", "%", "value", ")", "elif", "not", "value", ":...
Validate that ``value`` is a valid IP version 4 address. :param value: The value to validate. :param allow_empty: If ``True``, returns :obj:`None <python:None>` if ``value`` is empty. If ``False``, raises a :class:`EmptyValueError <validator_collection.errors.EmptyValueError>` if ``value`` i...
[ "Validate", "that", "value", "is", "a", "valid", "IP", "version", "4", "address", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/validators.py#L2475-L2513
1,351
insightindustry/validator-collection
validator_collection/validators.py
ipv6
def ipv6(value, allow_empty = False, **kwargs): """Validate that ``value`` is a valid IP address version 6. :param value: The value to validate. :param allow_empty: If ``True``, returns :obj:`None <python:None>` if ``value`` is empty. If ``False``, raises a :class:`EmptyValue...
python
def ipv6(value, allow_empty = False, **kwargs): if not value and allow_empty is False: raise errors.EmptyValueError('value (%s) was empty' % value) elif not value: return None if not isinstance(value, str): raise errors.InvalidIPAddressError('value (%s) is not a va...
[ "def", "ipv6", "(", "value", ",", "allow_empty", "=", "False", ",", "*", "*", "kwargs", ")", ":", "if", "not", "value", "and", "allow_empty", "is", "False", ":", "raise", "errors", ".", "EmptyValueError", "(", "'value (%s) was empty'", "%", "value", ")", ...
Validate that ``value`` is a valid IP address version 6. :param value: The value to validate. :param allow_empty: If ``True``, returns :obj:`None <python:None>` if ``value`` is empty. If ``False``, raises a :class:`EmptyValueError <validator_collection.errors.EmptyValueError>` if ``value`` i...
[ "Validate", "that", "value", "is", "a", "valid", "IP", "address", "version", "6", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/validators.py#L2517-L2552
1,352
insightindustry/validator-collection
validator_collection/validators.py
mac_address
def mac_address(value, allow_empty = False, **kwargs): """Validate that ``value`` is a valid MAC address. :param value: The value to validate. :type value: :class:`str <python:str>` / :obj:`None <python:None>` :param allow_empty: If ``True``, returns :obj:`None <python:...
python
def mac_address(value, allow_empty = False, **kwargs): if not value and not allow_empty: raise errors.EmptyValueError('value (%s) was empty' % value) elif not value: return None if not isinstance(value, basestring): raise errors.CannotCoerceError('val...
[ "def", "mac_address", "(", "value", ",", "allow_empty", "=", "False", ",", "*", "*", "kwargs", ")", ":", "if", "not", "value", "and", "not", "allow_empty", ":", "raise", "errors", ".", "EmptyValueError", "(", "'value (%s) was empty'", "%", "value", ")", "e...
Validate that ``value`` is a valid MAC address. :param value: The value to validate. :type value: :class:`str <python:str>` / :obj:`None <python:None>` :param allow_empty: If ``True``, returns :obj:`None <python:None>` if ``value`` is empty. If ``False``, raises a :class:`EmptyValueError <vali...
[ "Validate", "that", "value", "is", "a", "valid", "MAC", "address", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/validators.py#L2556-L2600
1,353
insightindustry/validator-collection
validator_collection/checkers.py
is_type
def is_type(obj, type_, **kwargs): """Indicate if ``obj`` is a type in ``type_``. .. hint:: This checker is particularly useful when you want to evaluate whether ``obj`` is of a particular type, but importing that type directly to use in :func:`isinstance() <python:is...
python
def is_type(obj, type_, **kwargs): if not is_iterable(type_): type_ = [type_] return_value = False for check_for_type in type_: if isinstance(check_for_type, type): return_value = isinstance(obj, check_for_type) elif obj.__class__.__name__ == chec...
[ "def", "is_type", "(", "obj", ",", "type_", ",", "*", "*", "kwargs", ")", ":", "if", "not", "is_iterable", "(", "type_", ")", ":", "type_", "=", "[", "type_", "]", "return_value", "=", "False", "for", "check_for_type", "in", "type_", ":", "if", "isin...
Indicate if ``obj`` is a type in ``type_``. .. hint:: This checker is particularly useful when you want to evaluate whether ``obj`` is of a particular type, but importing that type directly to use in :func:`isinstance() <python:isinstance>` would cause a circular import error. To us...
[ "Indicate", "if", "obj", "is", "a", "type", "in", "type_", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/checkers.py#L21-L69
1,354
insightindustry/validator-collection
validator_collection/checkers.py
_check_base_classes
def _check_base_classes(base_classes, check_for_type): """Indicate whether ``check_for_type`` exists in ``base_classes``. """ return_value = False for base in base_classes: if base.__name__ == check_for_type: return_value = True break else: return_valu...
python
def _check_base_classes(base_classes, check_for_type): return_value = False for base in base_classes: if base.__name__ == check_for_type: return_value = True break else: return_value = _check_base_classes(base.__bases__, check_for_type) if return_v...
[ "def", "_check_base_classes", "(", "base_classes", ",", "check_for_type", ")", ":", "return_value", "=", "False", "for", "base", "in", "base_classes", ":", "if", "base", ".", "__name__", "==", "check_for_type", ":", "return_value", "=", "True", "break", "else", ...
Indicate whether ``check_for_type`` exists in ``base_classes``.
[ "Indicate", "whether", "check_for_type", "exists", "in", "base_classes", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/checkers.py#L72-L85
1,355
insightindustry/validator-collection
validator_collection/checkers.py
are_equivalent
def are_equivalent(*args, **kwargs): """Indicate if arguments passed to this function are equivalent. .. hint:: This checker operates recursively on the members contained within iterables and :class:`dict <python:dict>` objects. .. caution:: If you only pass one argument to this checke...
python
def are_equivalent(*args, **kwargs): if len(args) == 1: return True first_item = args[0] for item in args[1:]: if type(item) != type(first_item): # pylint: disable=C0123 return False if isinstance(item, dict): if not are_...
[ "def", "are_equivalent", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "len", "(", "args", ")", "==", "1", ":", "return", "True", "first_item", "=", "args", "[", "0", "]", "for", "item", "in", "args", "[", "1", ":", "]", ":", "if",...
Indicate if arguments passed to this function are equivalent. .. hint:: This checker operates recursively on the members contained within iterables and :class:`dict <python:dict>` objects. .. caution:: If you only pass one argument to this checker - even if it is an iterable - the ch...
[ "Indicate", "if", "arguments", "passed", "to", "this", "function", "are", "equivalent", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/checkers.py#L89-L148
1,356
insightindustry/validator-collection
validator_collection/checkers.py
is_json
def is_json(value, schema = None, json_serializer = None, **kwargs): """Indicate whether ``value`` is a valid JSON object. .. note:: ``schema`` supports JSON Schema Drafts 3 - 7. Unless the JSON Schema indicates the meta-schema using a ``$schema`` property, the ...
python
def is_json(value, schema = None, json_serializer = None, **kwargs): try: value = validators.json(value, schema = schema, json_serializer = json_serializer, **kwargs) excep...
[ "def", "is_json", "(", "value", ",", "schema", "=", "None", ",", "json_serializer", "=", "None", ",", "*", "*", "kwargs", ")", ":", "try", ":", "value", "=", "validators", ".", "json", "(", "value", ",", "schema", "=", "schema", ",", "json_serializer",...
Indicate whether ``value`` is a valid JSON object. .. note:: ``schema`` supports JSON Schema Drafts 3 - 7. Unless the JSON Schema indicates the meta-schema using a ``$schema`` property, the schema will be assumed to conform to Draft 7. :param value: The value to evaluate. :param schema...
[ "Indicate", "whether", "value", "is", "a", "valid", "JSON", "object", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/checkers.py#L340-L375
1,357
insightindustry/validator-collection
validator_collection/checkers.py
is_string
def is_string(value, coerce_value = False, minimum_length = None, maximum_length = None, whitespace_padding = False, **kwargs): """Indicate whether ``value`` is a string. :param value: The value to evaluate. :param coerce_value: If ``Tr...
python
def is_string(value, coerce_value = False, minimum_length = None, maximum_length = None, whitespace_padding = False, **kwargs): if value is None: return False minimum_length = validators.integer(minimum_length, allow_empty = True, **...
[ "def", "is_string", "(", "value", ",", "coerce_value", "=", "False", ",", "minimum_length", "=", "None", ",", "maximum_length", "=", "None", ",", "whitespace_padding", "=", "False", ",", "*", "*", "kwargs", ")", ":", "if", "value", "is", "None", ":", "re...
Indicate whether ``value`` is a string. :param value: The value to evaluate. :param coerce_value: If ``True``, will check whether ``value`` can be coerced to a string if it is not already. Defaults to ``False``. :type coerce_value: :class:`bool <python:bool>` :param minimum_length: If supplied,...
[ "Indicate", "whether", "value", "is", "a", "string", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/checkers.py#L379-L436
1,358
insightindustry/validator-collection
validator_collection/checkers.py
is_iterable
def is_iterable(obj, forbid_literals = (str, bytes), minimum_length = None, maximum_length = None, **kwargs): """Indicate whether ``obj`` is iterable. :param forbid_literals: A collection of literals that will be considered invalid even if t...
python
def is_iterable(obj, forbid_literals = (str, bytes), minimum_length = None, maximum_length = None, **kwargs): if obj is None: return False if obj in forbid_literals: return False try: obj = validators.iterable(obj, ...
[ "def", "is_iterable", "(", "obj", ",", "forbid_literals", "=", "(", "str", ",", "bytes", ")", ",", "minimum_length", "=", "None", ",", "maximum_length", "=", "None", ",", "*", "*", "kwargs", ")", ":", "if", "obj", "is", "None", ":", "return", "False", ...
Indicate whether ``obj`` is iterable. :param forbid_literals: A collection of literals that will be considered invalid even if they are (actually) iterable. Defaults to a :class:`tuple <python:tuple>` containing :class:`str <python:str>` and :class:`bytes <python:bytes>`. :type forbid_literals: ite...
[ "Indicate", "whether", "obj", "is", "iterable", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/checkers.py#L440-L485
1,359
insightindustry/validator-collection
validator_collection/checkers.py
is_not_empty
def is_not_empty(value, **kwargs): """Indicate whether ``value`` is empty. :param value: The value to evaluate. :returns: ``True`` if ``value`` is empty, ``False`` if it is not. :rtype: :class:`bool <python:bool>` :raises SyntaxError: if ``kwargs`` contains duplicate keyword parameters or duplica...
python
def is_not_empty(value, **kwargs): try: value = validators.not_empty(value, **kwargs) except SyntaxError as error: raise error except Exception: return False return True
[ "def", "is_not_empty", "(", "value", ",", "*", "*", "kwargs", ")", ":", "try", ":", "value", "=", "validators", ".", "not_empty", "(", "value", ",", "*", "*", "kwargs", ")", "except", "SyntaxError", "as", "error", ":", "raise", "error", "except", "Exce...
Indicate whether ``value`` is empty. :param value: The value to evaluate. :returns: ``True`` if ``value`` is empty, ``False`` if it is not. :rtype: :class:`bool <python:bool>` :raises SyntaxError: if ``kwargs`` contains duplicate keyword parameters or duplicates keyword parameters passed to the...
[ "Indicate", "whether", "value", "is", "empty", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/checkers.py#L489-L508
1,360
insightindustry/validator-collection
validator_collection/checkers.py
is_variable_name
def is_variable_name(value, **kwargs): """Indicate whether ``value`` is a valid Python variable name. .. caution:: This function does **NOT** check whether the variable exists. It only checks that the ``value`` would work as a Python variable (or class, or function, etc.) name. :param v...
python
def is_variable_name(value, **kwargs): try: validators.variable_name(value, **kwargs) except SyntaxError as error: raise error except Exception: return False return True
[ "def", "is_variable_name", "(", "value", ",", "*", "*", "kwargs", ")", ":", "try", ":", "validators", ".", "variable_name", "(", "value", ",", "*", "*", "kwargs", ")", "except", "SyntaxError", "as", "error", ":", "raise", "error", "except", "Exception", ...
Indicate whether ``value`` is a valid Python variable name. .. caution:: This function does **NOT** check whether the variable exists. It only checks that the ``value`` would work as a Python variable (or class, or function, etc.) name. :param value: The value to evaluate. :returns: ``...
[ "Indicate", "whether", "value", "is", "a", "valid", "Python", "variable", "name", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/checkers.py#L540-L565
1,361
insightindustry/validator-collection
validator_collection/checkers.py
is_numeric
def is_numeric(value, minimum = None, maximum = None, **kwargs): """Indicate whether ``value`` is a numeric value. :param value: The value to evaluate. :param minimum: If supplied, will make sure that ``value`` is greater than or equal to this value. ...
python
def is_numeric(value, minimum = None, maximum = None, **kwargs): try: value = validators.numeric(value, minimum = minimum, maximum = maximum, **kwargs) ex...
[ "def", "is_numeric", "(", "value", ",", "minimum", "=", "None", ",", "maximum", "=", "None", ",", "*", "*", "kwargs", ")", ":", "try", ":", "value", "=", "validators", ".", "numeric", "(", "value", ",", "minimum", "=", "minimum", ",", "maximum", "=",...
Indicate whether ``value`` is a numeric value. :param value: The value to evaluate. :param minimum: If supplied, will make sure that ``value`` is greater than or equal to this value. :type minimum: numeric :param maximum: If supplied, will make sure that ``value`` is less than or equal to...
[ "Indicate", "whether", "value", "is", "a", "numeric", "value", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/checkers.py#L799-L832
1,362
insightindustry/validator-collection
validator_collection/checkers.py
is_integer
def is_integer(value, coerce_value = False, minimum = None, maximum = None, base = 10, **kwargs): """Indicate whether ``value`` contains a whole number. :param value: The value to evaluate. :param coerce_value: If ``True``, will re...
python
def is_integer(value, coerce_value = False, minimum = None, maximum = None, base = 10, **kwargs): try: value = validators.integer(value, coerce_value = coerce_value, ...
[ "def", "is_integer", "(", "value", ",", "coerce_value", "=", "False", ",", "minimum", "=", "None", ",", "maximum", "=", "None", ",", "base", "=", "10", ",", "*", "*", "kwargs", ")", ":", "try", ":", "value", "=", "validators", ".", "integer", "(", ...
Indicate whether ``value`` contains a whole number. :param value: The value to evaluate. :param coerce_value: If ``True``, will return ``True`` if ``value`` can be coerced to whole number. If ``False``, will only return ``True`` if ``value`` is already a whole number (regardless of type). Defaults...
[ "Indicate", "whether", "value", "contains", "a", "whole", "number", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/checkers.py#L836-L886
1,363
insightindustry/validator-collection
validator_collection/checkers.py
is_pathlike
def is_pathlike(value, **kwargs): """Indicate whether ``value`` is a path-like object. :param value: The value to evaluate. :returns: ``True`` if ``value`` is valid, ``False`` if it is not. :rtype: :class:`bool <python:bool>` :raises SyntaxError: if ``kwargs`` contains duplicate keyword parameter...
python
def is_pathlike(value, **kwargs): try: value = validators.path(value, **kwargs) except SyntaxError as error: raise error except Exception: return False return True
[ "def", "is_pathlike", "(", "value", ",", "*", "*", "kwargs", ")", ":", "try", ":", "value", "=", "validators", ".", "path", "(", "value", ",", "*", "*", "kwargs", ")", "except", "SyntaxError", "as", "error", ":", "raise", "error", "except", "Exception"...
Indicate whether ``value`` is a path-like object. :param value: The value to evaluate. :returns: ``True`` if ``value`` is valid, ``False`` if it is not. :rtype: :class:`bool <python:bool>` :raises SyntaxError: if ``kwargs`` contains duplicate keyword parameters or duplicates keyword parameters ...
[ "Indicate", "whether", "value", "is", "a", "path", "-", "like", "object", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/checkers.py#L1045-L1064
1,364
insightindustry/validator-collection
validator_collection/checkers.py
is_on_filesystem
def is_on_filesystem(value, **kwargs): """Indicate whether ``value`` is a file or directory that exists on the local filesystem. :param value: The value to evaluate. :returns: ``True`` if ``value`` is valid, ``False`` if it is not. :rtype: :class:`bool <python:bool>` :raises SyntaxError: if `...
python
def is_on_filesystem(value, **kwargs): try: value = validators.path_exists(value, **kwargs) except SyntaxError as error: raise error except Exception: return False return True
[ "def", "is_on_filesystem", "(", "value", ",", "*", "*", "kwargs", ")", ":", "try", ":", "value", "=", "validators", ".", "path_exists", "(", "value", ",", "*", "*", "kwargs", ")", "except", "SyntaxError", "as", "error", ":", "raise", "error", "except", ...
Indicate whether ``value`` is a file or directory that exists on the local filesystem. :param value: The value to evaluate. :returns: ``True`` if ``value`` is valid, ``False`` if it is not. :rtype: :class:`bool <python:bool>` :raises SyntaxError: if ``kwargs`` contains duplicate keyword parameter...
[ "Indicate", "whether", "value", "is", "a", "file", "or", "directory", "that", "exists", "on", "the", "local", "filesystem", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/checkers.py#L1068-L1088
1,365
insightindustry/validator-collection
validator_collection/checkers.py
is_file
def is_file(value, **kwargs): """Indicate whether ``value`` is a file that exists on the local filesystem. :param value: The value to evaluate. :returns: ``True`` if ``value`` is valid, ``False`` if it is not. :rtype: :class:`bool <python:bool>` :raises SyntaxError: if ``kwargs`` contains duplica...
python
def is_file(value, **kwargs): try: value = validators.file_exists(value, **kwargs) except SyntaxError as error: raise error except Exception: return False return True
[ "def", "is_file", "(", "value", ",", "*", "*", "kwargs", ")", ":", "try", ":", "value", "=", "validators", ".", "file_exists", "(", "value", ",", "*", "*", "kwargs", ")", "except", "SyntaxError", "as", "error", ":", "raise", "error", "except", "Excepti...
Indicate whether ``value`` is a file that exists on the local filesystem. :param value: The value to evaluate. :returns: ``True`` if ``value`` is valid, ``False`` if it is not. :rtype: :class:`bool <python:bool>` :raises SyntaxError: if ``kwargs`` contains duplicate keyword parameters or duplicates ...
[ "Indicate", "whether", "value", "is", "a", "file", "that", "exists", "on", "the", "local", "filesystem", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/checkers.py#L1092-L1111
1,366
insightindustry/validator-collection
validator_collection/checkers.py
is_directory
def is_directory(value, **kwargs): """Indicate whether ``value`` is a directory that exists on the local filesystem. :param value: The value to evaluate. :returns: ``True`` if ``value`` is valid, ``False`` if it is not. :rtype: :class:`bool <python:bool>` :raises SyntaxError: if ``kwargs`` contai...
python
def is_directory(value, **kwargs): try: value = validators.directory_exists(value, **kwargs) except SyntaxError as error: raise error except Exception: return False return True
[ "def", "is_directory", "(", "value", ",", "*", "*", "kwargs", ")", ":", "try", ":", "value", "=", "validators", ".", "directory_exists", "(", "value", ",", "*", "*", "kwargs", ")", "except", "SyntaxError", "as", "error", ":", "raise", "error", "except", ...
Indicate whether ``value`` is a directory that exists on the local filesystem. :param value: The value to evaluate. :returns: ``True`` if ``value`` is valid, ``False`` if it is not. :rtype: :class:`bool <python:bool>` :raises SyntaxError: if ``kwargs`` contains duplicate keyword parameters or duplica...
[ "Indicate", "whether", "value", "is", "a", "directory", "that", "exists", "on", "the", "local", "filesystem", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/checkers.py#L1115-L1134
1,367
insightindustry/validator-collection
validator_collection/checkers.py
is_readable
def is_readable(value, **kwargs): """Indicate whether ``value`` is a readable file. .. caution:: **Use of this validator is an anti-pattern and should be used with caution.** Validating the readability of a file *before* attempting to read it exposes your code to a bug called `TOCTOU ...
python
def is_readable(value, **kwargs): try: validators.readable(value, **kwargs) except SyntaxError as error: raise error except Exception: return False return True
[ "def", "is_readable", "(", "value", ",", "*", "*", "kwargs", ")", ":", "try", ":", "validators", ".", "readable", "(", "value", ",", "*", "*", "kwargs", ")", "except", "SyntaxError", "as", "error", ":", "raise", "error", "except", "Exception", ":", "re...
Indicate whether ``value`` is a readable file. .. caution:: **Use of this validator is an anti-pattern and should be used with caution.** Validating the readability of a file *before* attempting to read it exposes your code to a bug called `TOCTOU <https://en.wikipedia.org/wiki/Time_of_ch...
[ "Indicate", "whether", "value", "is", "a", "readable", "file", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/checkers.py#L1138-L1181
1,368
insightindustry/validator-collection
validator_collection/checkers.py
is_writeable
def is_writeable(value, **kwargs): """Indicate whether ``value`` is a writeable file. .. caution:: This validator does **NOT** work correctly on a Windows file system. This is due to the vagaries of how Windows manages its file system and the various ways in which it can man...
python
def is_writeable(value, **kwargs): if sys.platform in ['win32', 'cygwin']: raise NotImplementedError('not supported on Windows') try: validators.writeable(value, allow_empty = False, **kwargs) except SyntaxError as e...
[ "def", "is_writeable", "(", "value", ",", "*", "*", "kwargs", ")", ":", "if", "sys", ".", "platform", "in", "[", "'win32'", ",", "'cygwin'", "]", ":", "raise", "NotImplementedError", "(", "'not supported on Windows'", ")", "try", ":", "validators", ".", "w...
Indicate whether ``value`` is a writeable file. .. caution:: This validator does **NOT** work correctly on a Windows file system. This is due to the vagaries of how Windows manages its file system and the various ways in which it can manage file permission. If called on a Windows file sys...
[ "Indicate", "whether", "value", "is", "a", "writeable", "file", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/checkers.py#L1185-L1257
1,369
insightindustry/validator-collection
validator_collection/checkers.py
is_executable
def is_executable(value, **kwargs): """Indicate whether ``value`` is an executable file. .. caution:: This validator does **NOT** work correctly on a Windows file system. This is due to the vagaries of how Windows manages its file system and the various ways in which it can...
python
def is_executable(value, **kwargs): if sys.platform in ['win32', 'cygwin']: raise NotImplementedError('not supported on Windows') try: validators.executable(value, **kwargs) except SyntaxError as error: raise error except Exception...
[ "def", "is_executable", "(", "value", ",", "*", "*", "kwargs", ")", ":", "if", "sys", ".", "platform", "in", "[", "'win32'", ",", "'cygwin'", "]", ":", "raise", "NotImplementedError", "(", "'not supported on Windows'", ")", "try", ":", "validators", ".", "...
Indicate whether ``value`` is an executable file. .. caution:: This validator does **NOT** work correctly on a Windows file system. This is due to the vagaries of how Windows manages its file system and the various ways in which it can manage file permission. If called on a Windows file s...
[ "Indicate", "whether", "value", "is", "an", "executable", "file", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/checkers.py#L1260-L1323
1,370
insightindustry/validator-collection
validator_collection/checkers.py
is_email
def is_email(value, **kwargs): """Indicate whether ``value`` is an email address. .. note:: Email address validation is...complicated. The methodology that we have adopted here is *generally* compliant with `RFC 5322 <https://tools.ietf.org/html/rfc5322>`_ and uses a combination of str...
python
def is_email(value, **kwargs): try: value = validators.email(value, **kwargs) except SyntaxError as error: raise error except Exception: return False return True
[ "def", "is_email", "(", "value", ",", "*", "*", "kwargs", ")", ":", "try", ":", "value", "=", "validators", ".", "email", "(", "value", ",", "*", "*", "kwargs", ")", "except", "SyntaxError", "as", "error", ":", "raise", "error", "except", "Exception", ...
Indicate whether ``value`` is an email address. .. note:: Email address validation is...complicated. The methodology that we have adopted here is *generally* compliant with `RFC 5322 <https://tools.ietf.org/html/rfc5322>`_ and uses a combination of string parsing and regular expressions. ...
[ "Indicate", "whether", "value", "is", "an", "email", "address", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/checkers.py#L1329-L1362
1,371
insightindustry/validator-collection
validator_collection/checkers.py
is_url
def is_url(value, **kwargs): """Indicate whether ``value`` is a URL. .. note:: URL validation is...complicated. The methodology that we have adopted here is *generally* compliant with `RFC 1738 <https://tools.ietf.org/html/rfc1738>`_, `RFC 6761 <https://tools.ietf.org/html/rfc6761>`_, ...
python
def is_url(value, **kwargs): try: value = validators.url(value, **kwargs) except SyntaxError as error: raise error except Exception: return False return True
[ "def", "is_url", "(", "value", ",", "*", "*", "kwargs", ")", ":", "try", ":", "value", "=", "validators", ".", "url", "(", "value", ",", "*", "*", "kwargs", ")", "except", "SyntaxError", "as", "error", ":", "raise", "error", "except", "Exception", ":...
Indicate whether ``value`` is a URL. .. note:: URL validation is...complicated. The methodology that we have adopted here is *generally* compliant with `RFC 1738 <https://tools.ietf.org/html/rfc1738>`_, `RFC 6761 <https://tools.ietf.org/html/rfc6761>`_, `RFC 2181 <https://tools.ietf....
[ "Indicate", "whether", "value", "is", "a", "URL", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/checkers.py#L1366-L1402
1,372
insightindustry/validator-collection
validator_collection/checkers.py
is_domain
def is_domain(value, **kwargs): """Indicate whether ``value`` is a valid domain. .. caution:: This validator does not verify that ``value`` **exists** as a domain. It merely verifies that its contents *might* exist as a domain. .. note:: This validator checks to validate that ``value``...
python
def is_domain(value, **kwargs): try: value = validators.domain(value, **kwargs) except SyntaxError as error: raise error except Exception: return False return True
[ "def", "is_domain", "(", "value", ",", "*", "*", "kwargs", ")", ":", "try", ":", "value", "=", "validators", ".", "domain", "(", "value", ",", "*", "*", "kwargs", ")", "except", "SyntaxError", "as", "error", ":", "raise", "error", "except", "Exception"...
Indicate whether ``value`` is a valid domain. .. caution:: This validator does not verify that ``value`` **exists** as a domain. It merely verifies that its contents *might* exist as a domain. .. note:: This validator checks to validate that ``value`` resembles a valid domain name. I...
[ "Indicate", "whether", "value", "is", "a", "valid", "domain", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/checkers.py#L1406-L1450
1,373
insightindustry/validator-collection
validator_collection/checkers.py
is_ipv4
def is_ipv4(value, **kwargs): """Indicate whether ``value`` is a valid IP version 4 address. :param value: The value to evaluate. :returns: ``True`` if ``value`` is valid, ``False`` if it is not. :rtype: :class:`bool <python:bool>` :raises SyntaxError: if ``kwargs`` contains duplicate keyword par...
python
def is_ipv4(value, **kwargs): try: value = validators.ipv4(value, **kwargs) except SyntaxError as error: raise error except Exception: return False return True
[ "def", "is_ipv4", "(", "value", ",", "*", "*", "kwargs", ")", ":", "try", ":", "value", "=", "validators", ".", "ipv4", "(", "value", ",", "*", "*", "kwargs", ")", "except", "SyntaxError", "as", "error", ":", "raise", "error", "except", "Exception", ...
Indicate whether ``value`` is a valid IP version 4 address. :param value: The value to evaluate. :returns: ``True`` if ``value`` is valid, ``False`` if it is not. :rtype: :class:`bool <python:bool>` :raises SyntaxError: if ``kwargs`` contains duplicate keyword parameters or duplicates keyword p...
[ "Indicate", "whether", "value", "is", "a", "valid", "IP", "version", "4", "address", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/checkers.py#L1477-L1496
1,374
insightindustry/validator-collection
validator_collection/checkers.py
is_ipv6
def is_ipv6(value, **kwargs): """Indicate whether ``value`` is a valid IP version 6 address. :param value: The value to evaluate. :returns: ``True`` if ``value`` is valid, ``False`` if it is not. :rtype: :class:`bool <python:bool>` :raises SyntaxError: if ``kwargs`` contains duplicate keyword par...
python
def is_ipv6(value, **kwargs): try: value = validators.ipv6(value, **kwargs) except SyntaxError as error: raise error except Exception: return False return True
[ "def", "is_ipv6", "(", "value", ",", "*", "*", "kwargs", ")", ":", "try", ":", "value", "=", "validators", ".", "ipv6", "(", "value", ",", "*", "*", "kwargs", ")", "except", "SyntaxError", "as", "error", ":", "raise", "error", "except", "Exception", ...
Indicate whether ``value`` is a valid IP version 6 address. :param value: The value to evaluate. :returns: ``True`` if ``value`` is valid, ``False`` if it is not. :rtype: :class:`bool <python:bool>` :raises SyntaxError: if ``kwargs`` contains duplicate keyword parameters or duplicates keyword p...
[ "Indicate", "whether", "value", "is", "a", "valid", "IP", "version", "6", "address", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/checkers.py#L1500-L1518
1,375
insightindustry/validator-collection
validator_collection/checkers.py
is_mac_address
def is_mac_address(value, **kwargs): """Indicate whether ``value`` is a valid MAC address. :param value: The value to evaluate. :returns: ``True`` if ``value`` is valid, ``False`` if it is not. :rtype: :class:`bool <python:bool>` :raises SyntaxError: if ``kwargs`` contains duplicate keyword param...
python
def is_mac_address(value, **kwargs): try: value = validators.mac_address(value, **kwargs) except SyntaxError as error: raise error except Exception: return False return True
[ "def", "is_mac_address", "(", "value", ",", "*", "*", "kwargs", ")", ":", "try", ":", "value", "=", "validators", ".", "mac_address", "(", "value", ",", "*", "*", "kwargs", ")", "except", "SyntaxError", "as", "error", ":", "raise", "error", "except", "...
Indicate whether ``value`` is a valid MAC address. :param value: The value to evaluate. :returns: ``True`` if ``value`` is valid, ``False`` if it is not. :rtype: :class:`bool <python:bool>` :raises SyntaxError: if ``kwargs`` contains duplicate keyword parameters or duplicates keyword parameters...
[ "Indicate", "whether", "value", "is", "a", "valid", "MAC", "address", "." ]
8c8047a0fa36cc88a021771279898278c4cc98e3
https://github.com/insightindustry/validator-collection/blob/8c8047a0fa36cc88a021771279898278c4cc98e3/validator_collection/checkers.py#L1522-L1540
1,376
kevinpt/syntrax
syntrax.py
RailroadLayout.draw_line
def draw_line(self, lx, ltor): '''Draw a series of elements from left to right''' tag = self.get_tag() c = self.canvas s = self.style sep = s.h_sep exx = 0 exy = 0 terms = lx if ltor else reversed(lx) # Reverse so we can draw left to right for term in terms: t, texx,...
python
def draw_line(self, lx, ltor): '''Draw a series of elements from left to right''' tag = self.get_tag() c = self.canvas s = self.style sep = s.h_sep exx = 0 exy = 0 terms = lx if ltor else reversed(lx) # Reverse so we can draw left to right for term in terms: t, texx,...
[ "def", "draw_line", "(", "self", ",", "lx", ",", "ltor", ")", ":", "tag", "=", "self", ".", "get_tag", "(", ")", "c", "=", "self", ".", "canvas", "s", "=", "self", ".", "style", "sep", "=", "s", ".", "h_sep", "exx", "=", "0", "exy", "=", "0",...
Draw a series of elements from left to right
[ "Draw", "a", "series", "of", "elements", "from", "left", "to", "right" ]
eecc2714731ec6475d264326441e0f2a47467c28
https://github.com/kevinpt/syntrax/blob/eecc2714731ec6475d264326441e0f2a47467c28/syntrax.py#L1291-L1325
1,377
akolpakov/django-unused-media
django_unused_media/utils.py
get_file_fields
def get_file_fields(): """ Get all fields which are inherited from FileField """ # get models all_models = apps.get_models() # get fields fields = [] for model in all_models: for field in model._meta.get_fields(): if isinstance(field, models.FileField): ...
python
def get_file_fields(): # get models all_models = apps.get_models() # get fields fields = [] for model in all_models: for field in model._meta.get_fields(): if isinstance(field, models.FileField): fields.append(field) return fields
[ "def", "get_file_fields", "(", ")", ":", "# get models", "all_models", "=", "apps", ".", "get_models", "(", ")", "# get fields", "fields", "=", "[", "]", "for", "model", "in", "all_models", ":", "for", "field", "in", "model", ".", "_meta", ".", "get_fields...
Get all fields which are inherited from FileField
[ "Get", "all", "fields", "which", "are", "inherited", "from", "FileField" ]
0a6c38840f4eac49d285c7be5da7330a564cee92
https://github.com/akolpakov/django-unused-media/blob/0a6c38840f4eac49d285c7be5da7330a564cee92/django_unused_media/utils.py#L7-L25
1,378
akolpakov/django-unused-media
django_unused_media/remove.py
remove_media
def remove_media(files): """ Delete file from media dir """ for filename in files: os.remove(os.path.join(settings.MEDIA_ROOT, filename))
python
def remove_media(files): for filename in files: os.remove(os.path.join(settings.MEDIA_ROOT, filename))
[ "def", "remove_media", "(", "files", ")", ":", "for", "filename", "in", "files", ":", "os", ".", "remove", "(", "os", ".", "path", ".", "join", "(", "settings", ".", "MEDIA_ROOT", ",", "filename", ")", ")" ]
Delete file from media dir
[ "Delete", "file", "from", "media", "dir" ]
0a6c38840f4eac49d285c7be5da7330a564cee92
https://github.com/akolpakov/django-unused-media/blob/0a6c38840f4eac49d285c7be5da7330a564cee92/django_unused_media/remove.py#L8-L13
1,379
akolpakov/django-unused-media
django_unused_media/remove.py
remove_empty_dirs
def remove_empty_dirs(path=None): """ Recursively delete empty directories; return True if everything was deleted. """ if not path: path = settings.MEDIA_ROOT if not os.path.isdir(path): return False listdir = [os.path.join(path, filename) for filename in os.listdir(path)]...
python
def remove_empty_dirs(path=None): if not path: path = settings.MEDIA_ROOT if not os.path.isdir(path): return False listdir = [os.path.join(path, filename) for filename in os.listdir(path)] if all(list(map(remove_empty_dirs, listdir))): os.rmdir(path) return True el...
[ "def", "remove_empty_dirs", "(", "path", "=", "None", ")", ":", "if", "not", "path", ":", "path", "=", "settings", ".", "MEDIA_ROOT", "if", "not", "os", ".", "path", ".", "isdir", "(", "path", ")", ":", "return", "False", "listdir", "=", "[", "os", ...
Recursively delete empty directories; return True if everything was deleted.
[ "Recursively", "delete", "empty", "directories", ";", "return", "True", "if", "everything", "was", "deleted", "." ]
0a6c38840f4eac49d285c7be5da7330a564cee92
https://github.com/akolpakov/django-unused-media/blob/0a6c38840f4eac49d285c7be5da7330a564cee92/django_unused_media/remove.py#L16-L33
1,380
akolpakov/django-unused-media
django_unused_media/cleanup.py
get_used_media
def get_used_media(): """ Get media which are still used in models """ media = set() for field in get_file_fields(): is_null = { '%s__isnull' % field.name: True, } is_empty = { '%s' % field.name: '', } storage = field.storage ...
python
def get_used_media(): media = set() for field in get_file_fields(): is_null = { '%s__isnull' % field.name: True, } is_empty = { '%s' % field.name: '', } storage = field.storage for value in field.model.objects \ .values_l...
[ "def", "get_used_media", "(", ")", ":", "media", "=", "set", "(", ")", "for", "field", "in", "get_file_fields", "(", ")", ":", "is_null", "=", "{", "'%s__isnull'", "%", "field", ".", "name", ":", "True", ",", "}", "is_empty", "=", "{", "'%s'", "%", ...
Get media which are still used in models
[ "Get", "media", "which", "are", "still", "used", "in", "models" ]
0a6c38840f4eac49d285c7be5da7330a564cee92
https://github.com/akolpakov/django-unused-media/blob/0a6c38840f4eac49d285c7be5da7330a564cee92/django_unused_media/cleanup.py#L14-L37
1,381
akolpakov/django-unused-media
django_unused_media/cleanup.py
get_all_media
def get_all_media(exclude=None): """ Get all media from MEDIA_ROOT """ if not exclude: exclude = [] media = set() for root, dirs, files in os.walk(six.text_type(settings.MEDIA_ROOT)): for name in files: path = os.path.abspath(os.path.join(root, name)) ...
python
def get_all_media(exclude=None): if not exclude: exclude = [] media = set() for root, dirs, files in os.walk(six.text_type(settings.MEDIA_ROOT)): for name in files: path = os.path.abspath(os.path.join(root, name)) relpath = os.path.relpath(path, settings.MEDIA_ROOT)...
[ "def", "get_all_media", "(", "exclude", "=", "None", ")", ":", "if", "not", "exclude", ":", "exclude", "=", "[", "]", "media", "=", "set", "(", ")", "for", "root", ",", "dirs", ",", "files", "in", "os", ".", "walk", "(", "six", ".", "text_type", ...
Get all media from MEDIA_ROOT
[ "Get", "all", "media", "from", "MEDIA_ROOT" ]
0a6c38840f4eac49d285c7be5da7330a564cee92
https://github.com/akolpakov/django-unused-media/blob/0a6c38840f4eac49d285c7be5da7330a564cee92/django_unused_media/cleanup.py#L40-L60
1,382
akolpakov/django-unused-media
django_unused_media/cleanup.py
get_unused_media
def get_unused_media(exclude=None): """ Get media which are not used in models """ if not exclude: exclude = [] all_media = get_all_media(exclude) used_media = get_used_media() return all_media - used_media
python
def get_unused_media(exclude=None): if not exclude: exclude = [] all_media = get_all_media(exclude) used_media = get_used_media() return all_media - used_media
[ "def", "get_unused_media", "(", "exclude", "=", "None", ")", ":", "if", "not", "exclude", ":", "exclude", "=", "[", "]", "all_media", "=", "get_all_media", "(", "exclude", ")", "used_media", "=", "get_used_media", "(", ")", "return", "all_media", "-", "use...
Get media which are not used in models
[ "Get", "media", "which", "are", "not", "used", "in", "models" ]
0a6c38840f4eac49d285c7be5da7330a564cee92
https://github.com/akolpakov/django-unused-media/blob/0a6c38840f4eac49d285c7be5da7330a564cee92/django_unused_media/cleanup.py#L63-L74
1,383
njsmith/colorspacious
colorspacious/conversion.py
cspace_converter
def cspace_converter(start, end): """Returns a function for converting from colorspace ``start`` to colorspace ``end``. E.g., these are equivalent:: out = cspace_convert(arr, start, end) :: start_to_end_fn = cspace_converter(start, end) out = start_to_end_fn(arr) If you ...
python
def cspace_converter(start, end): start = norm_cspace_id(start) end = norm_cspace_id(end) return GRAPH.get_transform(start, end)
[ "def", "cspace_converter", "(", "start", ",", "end", ")", ":", "start", "=", "norm_cspace_id", "(", "start", ")", "end", "=", "norm_cspace_id", "(", "end", ")", "return", "GRAPH", ".", "get_transform", "(", "start", ",", "end", ")" ]
Returns a function for converting from colorspace ``start`` to colorspace ``end``. E.g., these are equivalent:: out = cspace_convert(arr, start, end) :: start_to_end_fn = cspace_converter(start, end) out = start_to_end_fn(arr) If you are doing a large number of conversions b...
[ "Returns", "a", "function", "for", "converting", "from", "colorspace", "start", "to", "colorspace", "end", "." ]
59e0226003fb1b894597c5081e8ca5a3aa4fcefd
https://github.com/njsmith/colorspacious/blob/59e0226003fb1b894597c5081e8ca5a3aa4fcefd/colorspacious/conversion.py#L198-L220
1,384
njsmith/colorspacious
colorspacious/conversion.py
cspace_convert
def cspace_convert(arr, start, end): """Converts the colors in ``arr`` from colorspace ``start`` to colorspace ``end``. :param arr: An array-like of colors. :param start, end: Any supported colorspace specifiers. See :ref:`supported-colorspaces` for details. """ converter = cspace_conv...
python
def cspace_convert(arr, start, end): converter = cspace_converter(start, end) return converter(arr)
[ "def", "cspace_convert", "(", "arr", ",", "start", ",", "end", ")", ":", "converter", "=", "cspace_converter", "(", "start", ",", "end", ")", "return", "converter", "(", "arr", ")" ]
Converts the colors in ``arr`` from colorspace ``start`` to colorspace ``end``. :param arr: An array-like of colors. :param start, end: Any supported colorspace specifiers. See :ref:`supported-colorspaces` for details.
[ "Converts", "the", "colors", "in", "arr", "from", "colorspace", "start", "to", "colorspace", "end", "." ]
59e0226003fb1b894597c5081e8ca5a3aa4fcefd
https://github.com/njsmith/colorspacious/blob/59e0226003fb1b894597c5081e8ca5a3aa4fcefd/colorspacious/conversion.py#L222-L232
1,385
njsmith/colorspacious
colorspacious/illuminants.py
as_XYZ100_w
def as_XYZ100_w(whitepoint): """A convenience function for getting whitepoints. ``whitepoint`` can be either a string naming a standard illuminant (see :func:`standard_illuminant_XYZ100`), or else a whitepoint given explicitly as an array-like of XYZ values. We internally call this function anywhe...
python
def as_XYZ100_w(whitepoint): if isinstance(whitepoint, str): return standard_illuminant_XYZ100(whitepoint) else: whitepoint = np.asarray(whitepoint, dtype=float) if whitepoint.shape[-1] != 3: raise ValueError("Bad whitepoint shape") return whitepoint
[ "def", "as_XYZ100_w", "(", "whitepoint", ")", ":", "if", "isinstance", "(", "whitepoint", ",", "str", ")", ":", "return", "standard_illuminant_XYZ100", "(", "whitepoint", ")", "else", ":", "whitepoint", "=", "np", ".", "asarray", "(", "whitepoint", ",", "dty...
A convenience function for getting whitepoints. ``whitepoint`` can be either a string naming a standard illuminant (see :func:`standard_illuminant_XYZ100`), or else a whitepoint given explicitly as an array-like of XYZ values. We internally call this function anywhere you have to specify a whitepoint ...
[ "A", "convenience", "function", "for", "getting", "whitepoints", "." ]
59e0226003fb1b894597c5081e8ca5a3aa4fcefd
https://github.com/njsmith/colorspacious/blob/59e0226003fb1b894597c5081e8ca5a3aa4fcefd/colorspacious/illuminants.py#L97-L116
1,386
njsmith/colorspacious
colorspacious/cvd.py
machado_et_al_2009_matrix
def machado_et_al_2009_matrix(cvd_type, severity): """Retrieve a matrix for simulating anomalous color vision. :param cvd_type: One of "protanomaly", "deuteranomaly", or "tritanomaly". :param severity: A value between 0 and 100. :returns: A 3x3 CVD simulation matrix as computed by Machado et al ...
python
def machado_et_al_2009_matrix(cvd_type, severity): assert 0 <= severity <= 100 fraction = severity % 10 low = int(severity - fraction) high = low + 10 assert low <= severity <= high low_matrix = np.asarray(MACHADO_ET_AL_MATRICES[cvd_type][low]) if severity == 100: # Don't try inte...
[ "def", "machado_et_al_2009_matrix", "(", "cvd_type", ",", "severity", ")", ":", "assert", "0", "<=", "severity", "<=", "100", "fraction", "=", "severity", "%", "10", "low", "=", "int", "(", "severity", "-", "fraction", ")", "high", "=", "low", "+", "10",...
Retrieve a matrix for simulating anomalous color vision. :param cvd_type: One of "protanomaly", "deuteranomaly", or "tritanomaly". :param severity: A value between 0 and 100. :returns: A 3x3 CVD simulation matrix as computed by Machado et al (2009). These matrices were downloaded from: ...
[ "Retrieve", "a", "matrix", "for", "simulating", "anomalous", "color", "vision", "." ]
59e0226003fb1b894597c5081e8ca5a3aa4fcefd
https://github.com/njsmith/colorspacious/blob/59e0226003fb1b894597c5081e8ca5a3aa4fcefd/colorspacious/cvd.py#L21-L54
1,387
h2oai/typesentry
typesentry/signature.py
Signature._make_retval_checker
def _make_retval_checker(self): """Create a function that checks the return value of the function.""" rvchk = self.retval.checker if rvchk: def _checker(value): if not rvchk.check(value): raise self._type_error( "Incorrect r...
python
def _make_retval_checker(self): rvchk = self.retval.checker if rvchk: def _checker(value): if not rvchk.check(value): raise self._type_error( "Incorrect return type in %s: expected %s got %s" % (self.name_bt,...
[ "def", "_make_retval_checker", "(", "self", ")", ":", "rvchk", "=", "self", ".", "retval", ".", "checker", "if", "rvchk", ":", "def", "_checker", "(", "value", ")", ":", "if", "not", "rvchk", ".", "check", "(", "value", ")", ":", "raise", "self", "."...
Create a function that checks the return value of the function.
[ "Create", "a", "function", "that", "checks", "the", "return", "value", "of", "the", "function", "." ]
0ca8ed0e62d15ffe430545e7648c9a9b2547b49c
https://github.com/h2oai/typesentry/blob/0ca8ed0e62d15ffe430545e7648c9a9b2547b49c/typesentry/signature.py#L172-L186
1,388
h2oai/typesentry
typesentry/signature.py
Signature._make_args_checker
def _make_args_checker(self): """ Create a function that checks signature of the source function. """ def _checker(*args, **kws): # Check if too many arguments are provided nargs = len(args) nnonvaargs = min(nargs, self._max_positional_args) ...
python
def _make_args_checker(self): def _checker(*args, **kws): # Check if too many arguments are provided nargs = len(args) nnonvaargs = min(nargs, self._max_positional_args) if nargs > self._max_positional_args and self._ivararg is None: raise self._to...
[ "def", "_make_args_checker", "(", "self", ")", ":", "def", "_checker", "(", "*", "args", ",", "*", "*", "kws", ")", ":", "# Check if too many arguments are provided", "nargs", "=", "len", "(", "args", ")", "nnonvaargs", "=", "min", "(", "nargs", ",", "self...
Create a function that checks signature of the source function.
[ "Create", "a", "function", "that", "checks", "signature", "of", "the", "source", "function", "." ]
0ca8ed0e62d15ffe430545e7648c9a9b2547b49c
https://github.com/h2oai/typesentry/blob/0ca8ed0e62d15ffe430545e7648c9a9b2547b49c/typesentry/signature.py#L189-L249
1,389
h2oai/typesentry
typesentry/checks.py
checker_for_type
def checker_for_type(t): """ Return "checker" function for the given type `t`. This checker function will accept a single argument (of any type), and return True if the argument matches type `t`, or False otherwise. For example: chkr = checker_for_type(int) assert chkr.check(123) i...
python
def checker_for_type(t): try: if t is True: return true_checker if t is False: return false_checker checker = memoized_type_checkers.get(t) if checker is not None: return checker hashable = True except TypeError: # Exception may...
[ "def", "checker_for_type", "(", "t", ")", ":", "try", ":", "if", "t", "is", "True", ":", "return", "true_checker", "if", "t", "is", "False", ":", "return", "false_checker", "checker", "=", "memoized_type_checkers", ".", "get", "(", "t", ")", "if", "check...
Return "checker" function for the given type `t`. This checker function will accept a single argument (of any type), and return True if the argument matches type `t`, or False otherwise. For example: chkr = checker_for_type(int) assert chkr.check(123) is True assert chkr.check("5")...
[ "Return", "checker", "function", "for", "the", "given", "type", "t", "." ]
0ca8ed0e62d15ffe430545e7648c9a9b2547b49c
https://github.com/h2oai/typesentry/blob/0ca8ed0e62d15ffe430545e7648c9a9b2547b49c/typesentry/checks.py#L32-L61
1,390
h2oai/typesentry
typesentry/checks.py
_prepare_value
def _prepare_value(val, maxlen=50, notype=False): """ Stringify value `val`, ensuring that it is not too long. """ if val is None or val is True or val is False: return str(val) sval = repr(val) sval = sval.replace("\n", " ").replace("\t", " ").replace("`", "'") if len(sval) > maxlen...
python
def _prepare_value(val, maxlen=50, notype=False): if val is None or val is True or val is False: return str(val) sval = repr(val) sval = sval.replace("\n", " ").replace("\t", " ").replace("`", "'") if len(sval) > maxlen: sval = sval[:maxlen - 4] + "..." + sval[-1] if notype: ...
[ "def", "_prepare_value", "(", "val", ",", "maxlen", "=", "50", ",", "notype", "=", "False", ")", ":", "if", "val", "is", "None", "or", "val", "is", "True", "or", "val", "is", "False", ":", "return", "str", "(", "val", ")", "sval", "=", "repr", "(...
Stringify value `val`, ensuring that it is not too long.
[ "Stringify", "value", "val", "ensuring", "that", "it", "is", "not", "too", "long", "." ]
0ca8ed0e62d15ffe430545e7648c9a9b2547b49c
https://github.com/h2oai/typesentry/blob/0ca8ed0e62d15ffe430545e7648c9a9b2547b49c/typesentry/checks.py#L774-L788
1,391
muatik/naive-bayes-classifier
naiveBayesClassifier/trainer.py
Trainer.train
def train(self, text, className): """ enhances trained data using the given text and class """ self.data.increaseClass(className) tokens = self.tokenizer.tokenize(text) for token in tokens: token = self.tokenizer.remove_stop_words(token) token = s...
python
def train(self, text, className): self.data.increaseClass(className) tokens = self.tokenizer.tokenize(text) for token in tokens: token = self.tokenizer.remove_stop_words(token) token = self.tokenizer.remove_punctuation(token) self.data.increaseToken(token, cl...
[ "def", "train", "(", "self", ",", "text", ",", "className", ")", ":", "self", ".", "data", ".", "increaseClass", "(", "className", ")", "tokens", "=", "self", ".", "tokenizer", ".", "tokenize", "(", "text", ")", "for", "token", "in", "tokens", ":", "...
enhances trained data using the given text and class
[ "enhances", "trained", "data", "using", "the", "given", "text", "and", "class" ]
cdc1d8681ef6674e946cff38e87ce3b00c732fbb
https://github.com/muatik/naive-bayes-classifier/blob/cdc1d8681ef6674e946cff38e87ce3b00c732fbb/naiveBayesClassifier/trainer.py#L11-L21
1,392
rene-aguirre/pywinusb
pywinusb/hid/core.py
find_all_hid_devices
def find_all_hid_devices(): "Finds all HID devices connected to the system" # # From DDK documentation (finding and Opening HID collection): # After a user-mode application is loaded, it does the following sequence # of operations: # # * Calls HidD_GetHidGuid to obtain the system-de...
python
def find_all_hid_devices(): "Finds all HID devices connected to the system" # # From DDK documentation (finding and Opening HID collection): # After a user-mode application is loaded, it does the following sequence # of operations: # # * Calls HidD_GetHidGuid to obtain the system-de...
[ "def", "find_all_hid_devices", "(", ")", ":", "#\r", "# From DDK documentation (finding and Opening HID collection):\r", "# After a user-mode application is loaded, it does the following sequence\r", "# of operations:\r", "#\r", "# * Calls HidD_GetHidGuid to obtain the system-defined GUID for ...
Finds all HID devices connected to the system
[ "Finds", "all", "HID", "devices", "connected", "to", "the", "system" ]
954c4b2105d9f01cb0c50e24500bb747d4ecdc43
https://github.com/rene-aguirre/pywinusb/blob/954c4b2105d9f01cb0c50e24500bb747d4ecdc43/pywinusb/hid/core.py#L88-L156
1,393
rene-aguirre/pywinusb
pywinusb/hid/core.py
show_hids
def show_hids(target_vid = 0, target_pid = 0, output = None): """Check all HID devices conected to PC hosts.""" # first be kind with local encodings if not output: # beware your script should manage encodings output = sys.stdout # then the big cheese... from . import tools ...
python
def show_hids(target_vid = 0, target_pid = 0, output = None): # first be kind with local encodings if not output: # beware your script should manage encodings output = sys.stdout # then the big cheese... from . import tools all_hids = None if target_vid: if targe...
[ "def", "show_hids", "(", "target_vid", "=", "0", ",", "target_pid", "=", "0", ",", "output", "=", "None", ")", ":", "# first be kind with local encodings\r", "if", "not", "output", ":", "# beware your script should manage encodings\r", "output", "=", "sys", ".", "...
Check all HID devices conected to PC hosts.
[ "Check", "all", "HID", "devices", "conected", "to", "PC", "hosts", "." ]
954c4b2105d9f01cb0c50e24500bb747d4ecdc43
https://github.com/rene-aguirre/pywinusb/blob/954c4b2105d9f01cb0c50e24500bb747d4ecdc43/pywinusb/hid/core.py#L1571-L1609
1,394
rene-aguirre/pywinusb
pywinusb/hid/core.py
HidDeviceFilter.get_devices_by_parent
def get_devices_by_parent(self, hid_filter=None): """Group devices returned from filter query in order \ by devcice parent id. """ all_devs = self.get_devices(hid_filter) dev_group = dict() for hid_device in all_devs: #keep a list of known devices match...
python
def get_devices_by_parent(self, hid_filter=None): all_devs = self.get_devices(hid_filter) dev_group = dict() for hid_device in all_devs: #keep a list of known devices matching parent device Ids parent_id = hid_device.get_parent_instance_id() device_set =...
[ "def", "get_devices_by_parent", "(", "self", ",", "hid_filter", "=", "None", ")", ":", "all_devs", "=", "self", ".", "get_devices", "(", "hid_filter", ")", "dev_group", "=", "dict", "(", ")", "for", "hid_device", "in", "all_devs", ":", "#keep a list of known d...
Group devices returned from filter query in order \ by devcice parent id.
[ "Group", "devices", "returned", "from", "filter", "query", "in", "order", "\\", "by", "devcice", "parent", "id", "." ]
954c4b2105d9f01cb0c50e24500bb747d4ecdc43
https://github.com/rene-aguirre/pywinusb/blob/954c4b2105d9f01cb0c50e24500bb747d4ecdc43/pywinusb/hid/core.py#L168-L182
1,395
rene-aguirre/pywinusb
pywinusb/hid/core.py
HidDeviceFilter.get_devices
def get_devices(self, hid_filter = None): """Filter a HID device list by current object parameters. Devices must match the all of the filtering parameters """ if not hid_filter: #empty list or called without any parameters if type(hid_filter) == type(None): ...
python
def get_devices(self, hid_filter = None): if not hid_filter: #empty list or called without any parameters if type(hid_filter) == type(None): #request to query connected devices hid_filter = find_all_hid_devices() else: return hid_filt...
[ "def", "get_devices", "(", "self", ",", "hid_filter", "=", "None", ")", ":", "if", "not", "hid_filter", ":", "#empty list or called without any parameters\r", "if", "type", "(", "hid_filter", ")", "==", "type", "(", "None", ")", ":", "#request to query connected d...
Filter a HID device list by current object parameters. Devices must match the all of the filtering parameters
[ "Filter", "a", "HID", "device", "list", "by", "current", "object", "parameters", ".", "Devices", "must", "match", "the", "all", "of", "the", "filtering", "parameters" ]
954c4b2105d9f01cb0c50e24500bb747d4ecdc43
https://github.com/rene-aguirre/pywinusb/blob/954c4b2105d9f01cb0c50e24500bb747d4ecdc43/pywinusb/hid/core.py#L184-L242
1,396
rene-aguirre/pywinusb
pywinusb/hid/core.py
HidDevice.get_parent_device
def get_parent_device(self): """Retreive parent device string id""" if not self.parent_instance_id: return "" dev_buffer_type = winapi.c_tchar * MAX_DEVICE_ID_LEN dev_buffer = dev_buffer_type() try: if winapi.CM_Get_Device_ID(self.parent_instance_id...
python
def get_parent_device(self): if not self.parent_instance_id: return "" dev_buffer_type = winapi.c_tchar * MAX_DEVICE_ID_LEN dev_buffer = dev_buffer_type() try: if winapi.CM_Get_Device_ID(self.parent_instance_id, byref(dev_buffer), MAX_DE...
[ "def", "get_parent_device", "(", "self", ")", ":", "if", "not", "self", ".", "parent_instance_id", ":", "return", "\"\"", "dev_buffer_type", "=", "winapi", ".", "c_tchar", "*", "MAX_DEVICE_ID_LEN", "dev_buffer", "=", "dev_buffer_type", "(", ")", "try", ":", "i...
Retreive parent device string id
[ "Retreive", "parent", "device", "string", "id" ]
954c4b2105d9f01cb0c50e24500bb747d4ecdc43
https://github.com/rene-aguirre/pywinusb/blob/954c4b2105d9f01cb0c50e24500bb747d4ecdc43/pywinusb/hid/core.py#L266-L279
1,397
rene-aguirre/pywinusb
pywinusb/hid/core.py
HidDevice.get_physical_descriptor
def get_physical_descriptor(self): """Returns physical HID device descriptor """ raw_data_type = c_ubyte * 1024 raw_data = raw_data_type() if hid_dll.HidD_GetPhysicalDescriptor(self.hid_handle, byref(raw_data), 1024 ): return [x for x in raw_data] ...
python
def get_physical_descriptor(self): raw_data_type = c_ubyte * 1024 raw_data = raw_data_type() if hid_dll.HidD_GetPhysicalDescriptor(self.hid_handle, byref(raw_data), 1024 ): return [x for x in raw_data] return []
[ "def", "get_physical_descriptor", "(", "self", ")", ":", "raw_data_type", "=", "c_ubyte", "*", "1024", "raw_data", "=", "raw_data_type", "(", ")", "if", "hid_dll", ".", "HidD_GetPhysicalDescriptor", "(", "self", ".", "hid_handle", ",", "byref", "(", "raw_data", ...
Returns physical HID device descriptor
[ "Returns", "physical", "HID", "device", "descriptor" ]
954c4b2105d9f01cb0c50e24500bb747d4ecdc43
https://github.com/rene-aguirre/pywinusb/blob/954c4b2105d9f01cb0c50e24500bb747d4ecdc43/pywinusb/hid/core.py#L510-L518
1,398
rene-aguirre/pywinusb
pywinusb/hid/core.py
HidDevice.close
def close(self): """Release system resources""" # free parsed data if not self.is_opened(): return self.__open_status = False # abort all running threads first if self.__reading_thread and self.__reading_thread.is_alive(): self.__reading_...
python
def close(self): # free parsed data if not self.is_opened(): return self.__open_status = False # abort all running threads first if self.__reading_thread and self.__reading_thread.is_alive(): self.__reading_thread.abort() #avoid posting...
[ "def", "close", "(", "self", ")", ":", "# free parsed data\r", "if", "not", "self", ".", "is_opened", "(", ")", ":", "return", "self", ".", "__open_status", "=", "False", "# abort all running threads first\r", "if", "self", ".", "__reading_thread", "and", "self"...
Release system resources
[ "Release", "system", "resources" ]
954c4b2105d9f01cb0c50e24500bb747d4ecdc43
https://github.com/rene-aguirre/pywinusb/blob/954c4b2105d9f01cb0c50e24500bb747d4ecdc43/pywinusb/hid/core.py#L612-L654
1,399
rene-aguirre/pywinusb
pywinusb/hid/core.py
HidDevice._process_raw_report
def _process_raw_report(self, raw_report): "Default raw input report data handler" if not self.is_opened(): return if not self.__evt_handlers and not self.__raw_handler: return if not raw_report[0] and \ (raw_report[0] not in self.__input...
python
def _process_raw_report(self, raw_report): "Default raw input report data handler" if not self.is_opened(): return if not self.__evt_handlers and not self.__raw_handler: return if not raw_report[0] and \ (raw_report[0] not in self.__input...
[ "def", "_process_raw_report", "(", "self", ",", "raw_report", ")", ":", "if", "not", "self", ".", "is_opened", "(", ")", ":", "return", "if", "not", "self", ".", "__evt_handlers", "and", "not", "self", ".", "__raw_handler", ":", "return", "if", "not", "r...
Default raw input report data handler
[ "Default", "raw", "input", "report", "data", "handler" ]
954c4b2105d9f01cb0c50e24500bb747d4ecdc43
https://github.com/rene-aguirre/pywinusb/blob/954c4b2105d9f01cb0c50e24500bb747d4ecdc43/pywinusb/hid/core.py#L717-L763