Python keyword.kwlist() Examples
The following are 30
code examples of keyword.kwlist().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
keyword
, or try the search function
.
Example #1
Source File: rlcompleter.py From meddle with MIT License | 7 votes |
def global_matches(self, text): """Compute matches when text is a simple name. Return a list of all keywords, built-in functions and names currently defined in self.namespace that match. """ import keyword matches = [] n = len(text) for word in keyword.kwlist: if word[:n] == text: matches.append(word) for nspace in [__builtin__.__dict__, self.namespace]: for word, val in nspace.items(): if word[:n] == text and word != "__builtins__": matches.append(self._callable_postfix(val, word)) return matches
Example #2
Source File: i_to_m.py From cWMI with Apache License 2.0 | 6 votes |
def convert_param(method, param): # remove notation, split by upper, convert to lowercase param_sanitized = param.replace('*', '') substr = param_sanitized try: substr = re.search('([A-Z]\w+)', param_sanitized).group(1) except: pass case_re = re.compile(r'((?<=[a-z0-9])[A-Z]|(?!^)[A-Z](?=[a-z]))') converted_param = case_re.sub(r'_\1', substr).lower() if converted_param in keyword.kwlist or converted_param in dir(__builtins__): converted_param += '_param' # check for duplicates. if seen, append number to end if 'params' in method and len([param for param in method['params'] if param['name'] == converted_param]): param_names = [param['name'] for param in method['params']] for x in range(2, 10): count_name = '{:s}{:d}'.format(converted_param, x) if count_name not in param_names: converted_param = count_name break return converted_param
Example #3
Source File: rlcompleter.py From BinderFilter with MIT License | 6 votes |
def global_matches(self, text): """Compute matches when text is a simple name. Return a list of all keywords, built-in functions and names currently defined in self.namespace that match. """ import keyword matches = [] n = len(text) for word in keyword.kwlist: if word[:n] == text: matches.append(word) for nspace in [__builtin__.__dict__, self.namespace]: for word, val in nspace.items(): if word[:n] == text and word != "__builtins__": matches.append(self._callable_postfix(val, word)) return matches
Example #4
Source File: cgitb.py From Computable with MIT License | 6 votes |
def scanvars(reader, frame, locals): """Scan one logical line of Python and look up values of variables used.""" vars, lasttoken, parent, prefix, value = [], None, None, '', __UNDEF__ for ttype, token, start, end, line in tokenize.generate_tokens(reader): if ttype == tokenize.NEWLINE: break if ttype == tokenize.NAME and token not in keyword.kwlist: if lasttoken == '.': if parent is not __UNDEF__: value = getattr(parent, token, __UNDEF__) vars.append((prefix + token, prefix, value)) else: where, value = lookup(token, frame, locals) vars.append((token, where, value)) elif token == '.': prefix += lasttoken + '.' parent = value else: parent, prefix = None, '' lasttoken = token return vars
Example #5
Source File: rlcompleter.py From ironpython2 with Apache License 2.0 | 6 votes |
def global_matches(self, text): """Compute matches when text is a simple name. Return a list of all keywords, built-in functions and names currently defined in self.namespace that match. """ import keyword matches = [] seen = {"__builtins__"} n = len(text) for word in keyword.kwlist: if word[:n] == text: seen.add(word) matches.append(word) for nspace in [self.namespace, __builtin__.__dict__]: for word, val in nspace.items(): if word[:n] == text and word not in seen: seen.add(word) matches.append(self._callable_postfix(val, word)) return matches
Example #6
Source File: show_text_window.py From easygui_qt with BSD 3-Clause "New" or "Revised" License | 6 votes |
def __init__(self, parent=None): super(Highlighter, self).__init__(parent) keywordFormat = QtGui.QTextCharFormat() keywordFormat.setForeground(QtCore.Qt.blue) keywordFormat.setFontWeight(QtGui.QFont.Bold) keywordPatterns = ["\\b{}\\b".format(k) for k in keyword.kwlist] self.highlightingRules = [(QtCore.QRegExp(pattern), keywordFormat) for pattern in keywordPatterns] classFormat = QtGui.QTextCharFormat() classFormat.setFontWeight(QtGui.QFont.Bold) self.highlightingRules.append((QtCore.QRegExp("\\bQ[A-Za-z]+\\b"), classFormat)) singleLineCommentFormat = QtGui.QTextCharFormat() singleLineCommentFormat.setForeground(QtCore.Qt.gray) self.highlightingRules.append((QtCore.QRegExp("#[^\n]*"), singleLineCommentFormat)) quotationFormat = QtGui.QTextCharFormat() quotationFormat.setForeground(QtCore.Qt.darkGreen) self.highlightingRules.append((QtCore.QRegExp("\".*\""), quotationFormat)) self.highlightingRules.append((QtCore.QRegExp("'.*'"), quotationFormat))
Example #7
Source File: cgitb.py From meddle with MIT License | 6 votes |
def scanvars(reader, frame, locals): """Scan one logical line of Python and look up values of variables used.""" vars, lasttoken, parent, prefix, value = [], None, None, '', __UNDEF__ for ttype, token, start, end, line in tokenize.generate_tokens(reader): if ttype == tokenize.NEWLINE: break if ttype == tokenize.NAME and token not in keyword.kwlist: if lasttoken == '.': if parent is not __UNDEF__: value = getattr(parent, token, __UNDEF__) vars.append((prefix + token, prefix, value)) else: where, value = lookup(token, frame, locals) vars.append((token, where, value)) elif token == '.': prefix += lasttoken + '.' parent = value else: parent, prefix = None, '' lasttoken = token return vars
Example #8
Source File: cgitb.py From ironpython2 with Apache License 2.0 | 6 votes |
def scanvars(reader, frame, locals): """Scan one logical line of Python and look up values of variables used.""" vars, lasttoken, parent, prefix, value = [], None, None, '', __UNDEF__ for ttype, token, start, end, line in tokenize.generate_tokens(reader): if ttype == tokenize.NEWLINE: break if ttype == tokenize.NAME and token not in keyword.kwlist: if lasttoken == '.': if parent is not __UNDEF__: value = getattr(parent, token, __UNDEF__) vars.append((prefix + token, prefix, value)) else: where, value = lookup(token, frame, locals) vars.append((token, where, value)) elif token == '.': prefix += lasttoken + '.' parent = value else: parent, prefix = None, '' lasttoken = token return vars
Example #9
Source File: cgitb.py From BinderFilter with MIT License | 6 votes |
def scanvars(reader, frame, locals): """Scan one logical line of Python and look up values of variables used.""" vars, lasttoken, parent, prefix, value = [], None, None, '', __UNDEF__ for ttype, token, start, end, line in tokenize.generate_tokens(reader): if ttype == tokenize.NEWLINE: break if ttype == tokenize.NAME and token not in keyword.kwlist: if lasttoken == '.': if parent is not __UNDEF__: value = getattr(parent, token, __UNDEF__) vars.append((prefix + token, prefix, value)) else: where, value = lookup(token, frame, locals) vars.append((token, where, value)) elif token == '.': prefix += lasttoken + '.' parent = value else: parent, prefix = None, '' lasttoken = token return vars
Example #10
Source File: rlcompleter.py From kobo-predict with BSD 2-Clause "Simplified" License | 6 votes |
def global_matches(self, text): """Compute matches when text is a simple name. Return a list of all keywords, built-in functions and names currently defined in self.namespace that match. """ import keyword matches = [] seen = {"__builtins__"} n = len(text) for word in keyword.kwlist: if word[:n] == text: seen.add(word) matches.append(word) for nspace in [self.namespace, builtins.__dict__]: for word, val in nspace.items(): if word[:n] == text and word not in seen: seen.add(word) matches.append(self._callable_postfix(val, word)) return matches
Example #11
Source File: completer.py From Computable with MIT License | 6 votes |
def global_matches(self, text): """Compute matches when text is a simple name. Return a list of all keywords, built-in functions and names currently defined in self.namespace or self.global_namespace that match. """ #print 'Completer->global_matches, txt=%r' % text # dbg matches = [] match_append = matches.append n = len(text) for lst in [keyword.kwlist, __builtin__.__dict__.keys(), self.namespace.keys(), self.global_namespace.keys()]: for word in lst: if word[:n] == text and word != "__builtins__": match_append(word) return matches
Example #12
Source File: cgitb.py From oss-ftp with MIT License | 6 votes |
def scanvars(reader, frame, locals): """Scan one logical line of Python and look up values of variables used.""" vars, lasttoken, parent, prefix, value = [], None, None, '', __UNDEF__ for ttype, token, start, end, line in tokenize.generate_tokens(reader): if ttype == tokenize.NEWLINE: break if ttype == tokenize.NAME and token not in keyword.kwlist: if lasttoken == '.': if parent is not __UNDEF__: value = getattr(parent, token, __UNDEF__) vars.append((prefix + token, prefix, value)) else: where, value = lookup(token, frame, locals) vars.append((token, where, value)) elif token == '.': prefix += lasttoken + '.' parent = value else: parent, prefix = None, '' lasttoken = token return vars
Example #13
Source File: rlcompleter.py From oss-ftp with MIT License | 6 votes |
def global_matches(self, text): """Compute matches when text is a simple name. Return a list of all keywords, built-in functions and names currently defined in self.namespace that match. """ import keyword matches = [] n = len(text) for word in keyword.kwlist: if word[:n] == text: matches.append(word) for nspace in [__builtin__.__dict__, self.namespace]: for word, val in nspace.items(): if word[:n] == text and word != "__builtins__": matches.append(self._callable_postfix(val, word)) return matches
Example #14
Source File: ColorDelegator.py From oss-ftp with MIT License | 6 votes |
def make_pat(): kw = r"\b" + any("KEYWORD", keyword.kwlist) + r"\b" builtinlist = [str(name) for name in dir(__builtin__) if not name.startswith('_')] # We don't know whether "print" is a function or a keyword, # so we always treat is as a keyword (the most common case). builtinlist.remove('print') # self.file = file("file") : # 1st 'file' colorized normal, 2nd as builtin, 3rd as string builtin = r"([^.'\"\\#]\b|^)" + any("BUILTIN", builtinlist) + r"\b" comment = any("COMMENT", [r"#[^\n]*"]) stringprefix = r"(\br|u|ur|R|U|UR|Ur|uR|b|B|br|Br|bR|BR)?" sqstring = stringprefix + r"'[^'\\\n]*(\\.[^'\\\n]*)*'?" dqstring = stringprefix + r'"[^"\\\n]*(\\.[^"\\\n]*)*"?' sq3string = stringprefix + r"'''[^'\\]*((\\.|'(?!''))[^'\\]*)*(''')?" dq3string = stringprefix + r'"""[^"\\]*((\\.|"(?!""))[^"\\]*)*(""")?' string = any("STRING", [sq3string, dq3string, sqstring, dqstring]) return kw + "|" + builtin + "|" + comment + "|" + string +\ "|" + any("SYNC", [r"\n"])
Example #15
Source File: box.py From Box with MIT License | 6 votes |
def __dir__(self): allowed = string.ascii_letters + string.digits + '_' items = set(super().__dir__()) # Only show items accessible by dot notation for key in self.keys(): key = str(key) if ' ' not in key and key[0] not in string.digits and key not in kwlist: for letter in key: if letter not in allowed: break else: items.add(key) for key in self.keys(): if key not in items: if self._box_config['conversion_box']: key = self._safe_attr(key) if key: items.add(key) return list(items)
Example #16
Source File: cgitb.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def scanvars(reader, frame, locals): """Scan one logical line of Python and look up values of variables used.""" vars, lasttoken, parent, prefix, value = [], None, None, '', __UNDEF__ for ttype, token, start, end, line in tokenize.generate_tokens(reader): if ttype == tokenize.NEWLINE: break if ttype == tokenize.NAME and token not in keyword.kwlist: if lasttoken == '.': if parent is not __UNDEF__: value = getattr(parent, token, __UNDEF__) vars.append((prefix + token, prefix, value)) else: where, value = lookup(token, frame, locals) vars.append((token, where, value)) elif token == '.': prefix += lasttoken + '.' parent = value else: parent, prefix = None, '' lasttoken = token return vars
Example #17
Source File: rlcompleter.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def global_matches(self, text): """Compute matches when text is a simple name. Return a list of all keywords, built-in functions and names currently defined in self.namespace that match. """ import keyword matches = [] n = len(text) for word in keyword.kwlist: if word[:n] == text: matches.append(word) for nspace in [builtins.__dict__, self.namespace]: for word, val in nspace.items(): if word[:n] == text and word != "__builtins__": matches.append(self._callable_postfix(val, word)) return matches
Example #18
Source File: cgitb.py From Imogen with MIT License | 6 votes |
def scanvars(reader, frame, locals): """Scan one logical line of Python and look up values of variables used.""" vars, lasttoken, parent, prefix, value = [], None, None, '', __UNDEF__ for ttype, token, start, end, line in tokenize.generate_tokens(reader): if ttype == tokenize.NEWLINE: break if ttype == tokenize.NAME and token not in keyword.kwlist: if lasttoken == '.': if parent is not __UNDEF__: value = getattr(parent, token, __UNDEF__) vars.append((prefix + token, prefix, value)) else: where, value = lookup(token, frame, locals) vars.append((token, where, value)) elif token == '.': prefix += lasttoken + '.' parent = value else: parent, prefix = None, '' lasttoken = token return vars
Example #19
Source File: rlcompleter.py From scylla with Apache License 2.0 | 6 votes |
def global_matches(self, text): """Compute matches when text is a simple name. Return a list of all keywords, built-in functions and names currently defined in self.namespace that match. """ import keyword matches = [] seen = {"__builtins__"} n = len(text) for word in keyword.kwlist: if word[:n] == text: seen.add(word) matches.append(word) for nspace in [self.namespace, builtins.__dict__]: for word, val in nspace.items(): if word[:n] == text and word not in seen: seen.add(word) matches.append(self._callable_postfix(val, word)) return matches
Example #20
Source File: cgitb.py From ironpython3 with Apache License 2.0 | 6 votes |
def scanvars(reader, frame, locals): """Scan one logical line of Python and look up values of variables used.""" vars, lasttoken, parent, prefix, value = [], None, None, '', __UNDEF__ for ttype, token, start, end, line in tokenize.generate_tokens(reader): if ttype == tokenize.NEWLINE: break if ttype == tokenize.NAME and token not in keyword.kwlist: if lasttoken == '.': if parent is not __UNDEF__: value = getattr(parent, token, __UNDEF__) vars.append((prefix + token, prefix, value)) else: where, value = lookup(token, frame, locals) vars.append((token, where, value)) elif token == '.': prefix += lasttoken + '.' parent = value else: parent, prefix = None, '' lasttoken = token return vars
Example #21
Source File: rlcompleter.py From ironpython3 with Apache License 2.0 | 6 votes |
def global_matches(self, text): """Compute matches when text is a simple name. Return a list of all keywords, built-in functions and names currently defined in self.namespace that match. """ import keyword matches = [] seen = {"__builtins__"} n = len(text) for word in keyword.kwlist: if word[:n] == text: seen.add(word) matches.append(word) for nspace in [self.namespace, builtins.__dict__]: for word, val in nspace.items(): if word[:n] == text and word not in seen: seen.add(word) matches.append(self._callable_postfix(val, word)) return matches
Example #22
Source File: serialize.py From sdk-codegen with MIT License | 6 votes |
def unstructure_hook(api_model): """cattr unstructure hook Map reserved_ words in models to correct json field names. Also handle stripping None fields from dict while setting EXPLICIT_NULL fields to None so that we only send null in the json for fields the caller set EXPLICIT_NULL on. """ data = cattr.global_converter.unstructure_attrs_asdict(api_model) for key, value in data.copy().items(): if value is None: del data[key] elif value == model.EXPLICIT_NULL: data[key] = None for reserved in keyword.kwlist: if f"{reserved}_" in data: data[reserved] = data.pop(f"{reserved}_") return data
Example #23
Source File: json_operator.py From lale with Apache License 2.0 | 6 votes |
def __init__(self, op: 'lale.operators.Operator', cls2label: Dict[str, str]): label2count: Dict[str, int] = {} def populate_label2count(op: 'lale.operators.Operator'): if isinstance(op, lale.operators.IndividualOp): label = cls2label.get(op.class_name(), op.name()) elif isinstance(op, lale.operators.BasePipeline): for s in op.steps(): populate_label2count(s) label = 'pipeline' elif isinstance(op, lale.operators.OperatorChoice): for s in op.steps(): populate_label2count(s) label = 'choice' label2count[label] = label2count.get(label, 0) + 1 populate_label2count(op) non_unique_labels = {l for l, c in label2count.items() if c > 1} snakes = {_camelCase_to_snake(l) for l in non_unique_labels} self._names = ({'lale', 'make_pipeline', 'make_union', 'make_choice'} | set(keyword.kwlist) | non_unique_labels | snakes)
Example #24
Source File: cgitb.py From datafari with Apache License 2.0 | 6 votes |
def scanvars(reader, frame, locals): """Scan one logical line of Python and look up values of variables used.""" vars, lasttoken, parent, prefix, value = [], None, None, '', __UNDEF__ for ttype, token, start, end, line in tokenize.generate_tokens(reader): if ttype == tokenize.NEWLINE: break if ttype == tokenize.NAME and token not in keyword.kwlist: if lasttoken == '.': if parent is not __UNDEF__: value = getattr(parent, token, __UNDEF__) vars.append((prefix + token, prefix, value)) else: where, value = lookup(token, frame, locals) vars.append((token, where, value)) elif token == '.': prefix += lasttoken + '.' parent = value else: parent, prefix = None, '' lasttoken = token return vars
Example #25
Source File: tb.py From owasp-pysec with Apache License 2.0 | 6 votes |
def linevars(code, frame=None): if frame is None: frame = sys._getframe().f_back last = None parent = None prefix = '' value = NOVAL for tok_type, token, start, end, line in tokenize.generate_tokens(StringReadline(code).readline): if tok_type == tokenize.NEWLINE: break elif tok_type == tokenize.NAME and token not in keyword.kwlist: if last == '.': if parent is not NOVAL: value = getattr(parent, token, NOVAL) yield prefix + token, prefix, value else: where, value = getvar(token, frame) yield token, where, value elif token == '.': prefix = '%s%s.' % (prefix, last) parent = value else: parent = None prefix = '' last = token
Example #26
Source File: cgitb.py From Splunking-Crime with GNU Affero General Public License v3.0 | 6 votes |
def scanvars(reader, frame, locals): """Scan one logical line of Python and look up values of variables used.""" vars, lasttoken, parent, prefix, value = [], None, None, '', __UNDEF__ for ttype, token, start, end, line in tokenize.generate_tokens(reader): if ttype == tokenize.NEWLINE: break if ttype == tokenize.NAME and token not in keyword.kwlist: if lasttoken == '.': if parent is not __UNDEF__: value = getattr(parent, token, __UNDEF__) vars.append((prefix + token, prefix, value)) else: where, value = lookup(token, frame, locals) vars.append((token, where, value)) elif token == '.': prefix += lasttoken + '.' parent = value else: parent, prefix = None, '' lasttoken = token return vars
Example #27
Source File: rlcompleter.py From Splunking-Crime with GNU Affero General Public License v3.0 | 6 votes |
def global_matches(self, text): """Compute matches when text is a simple name. Return a list of all keywords, built-in functions and names currently defined in self.namespace that match. """ import keyword matches = [] n = len(text) for word in keyword.kwlist: if word[:n] == text: matches.append(word) for nspace in [__builtin__.__dict__, self.namespace]: for word, val in nspace.items(): if word[:n] == text and word != "__builtins__": matches.append(self._callable_postfix(val, word)) return matches
Example #28
Source File: ColorDelegator.py From Splunking-Crime with GNU Affero General Public License v3.0 | 6 votes |
def make_pat(): kw = r"\b" + any("KEYWORD", keyword.kwlist) + r"\b" builtinlist = [str(name) for name in dir(__builtin__) if not name.startswith('_')] # We don't know whether "print" is a function or a keyword, # so we always treat is as a keyword (the most common case). builtinlist.remove('print') # self.file = file("file") : # 1st 'file' colorized normal, 2nd as builtin, 3rd as string builtin = r"([^.'\"\\#]\b|^)" + any("BUILTIN", builtinlist) + r"\b" comment = any("COMMENT", [r"#[^\n]*"]) stringprefix = r"(\br|u|ur|R|U|UR|Ur|uR|b|B|br|Br|bR|BR)?" sqstring = stringprefix + r"'[^'\\\n]*(\\.[^'\\\n]*)*'?" dqstring = stringprefix + r'"[^"\\\n]*(\\.[^"\\\n]*)*"?' sq3string = stringprefix + r"'''[^'\\]*((\\.|'(?!''))[^'\\]*)*(''')?" dq3string = stringprefix + r'"""[^"\\]*((\\.|"(?!""))[^"\\]*)*(""")?' string = any("STRING", [sq3string, dq3string, sqstring, dqstring]) return kw + "|" + builtin + "|" + comment + "|" + string +\ "|" + any("SYNC", [r"\n"])
Example #29
Source File: cgitb.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def scanvars(reader, frame, locals): """Scan one logical line of Python and look up values of variables used.""" vars, lasttoken, parent, prefix, value = [], None, None, '', __UNDEF__ for ttype, token, start, end, line in tokenize.generate_tokens(reader): if ttype == tokenize.NEWLINE: break if ttype == tokenize.NAME and token not in keyword.kwlist: if lasttoken == '.': if parent is not __UNDEF__: value = getattr(parent, token, __UNDEF__) vars.append((prefix + token, prefix, value)) else: where, value = lookup(token, frame, locals) vars.append((token, where, value)) elif token == '.': prefix += lasttoken + '.' parent = value else: parent, prefix = None, '' lasttoken = token return vars
Example #30
Source File: rlcompleter.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def global_matches(self, text): """Compute matches when text is a simple name. Return a list of all keywords, built-in functions and names currently defined in self.namespace that match. """ import keyword matches = [] seen = {"__builtins__"} n = len(text) for word in keyword.kwlist: if word[:n] == text: seen.add(word) matches.append(word) for nspace in [self.namespace, builtins.__dict__]: for word, val in nspace.items(): if word[:n] == text and word not in seen: seen.add(word) matches.append(self._callable_postfix(val, word)) return matches