def extract_links_from_file(file, link_ignore_regex, link_ignore_list): link_ignore_regex = re.compile(link_ignore_regex) regex = re.compile( r""" ((git\+|bzr\+|svn\+|hg\+|) # For VCS URLs https?:// # http:// or https:// as only these # are supported by the ``requests`` # library [^.:%\s_/?#[\]@\\]+ # Initial part of domain \. # A required dot `.` ( (?:[^\s()%\'"`<>|\\\[\]]+) # Path name # This part does not allow # any parenthesis: balanced or # unbalanced. | # OR \([^\s()%\'"`<>|\\\[\]]*\) # Path name contained within () # This part allows path names that # are explicitly enclosed within one # set of parenthesis. # An example can be: # http://wik.org/Hello_(Adele_song)/200 ) *) # Thus, the whole part above # prevents matching of # Unbalanced parenthesis (?<!\.)(?<!,) # Exclude trailing `.` or `,` from URL """, re.VERBOSE) file_context = {} for line_number, line in enumerate(file): xmlns_regex = re.compile(r'xmlns:?\w*="(.*)"') for match in re.findall(regex, line): link = match[0] link_context = file_context.get(link) if not link_context: link_context = enum( xml_namespace=False, pip_vcs_url=False) xmlns_match = xmlns_regex.search(line) if xmlns_match and link in xmlns_match.groups(): link_context.xml_namespace = True if link.startswith(('hg+', 'bzr+', 'git+', 'svn+')): link_context.pip_vcs_url = True file_context[link] = link_context if not (link_ignore_regex.search(link) or fnmatch(link, link_ignore_list)): yield link, line_number, link_context
def extract_links_from_file(file, link_ignore_regex, link_ignore_list): link_ignore_regex = re.compile(link_ignore_regex) regex = re.compile( r""" ((git\+|bzr\+|svn\+|hg\+|) # For VCS URLs https?:// # http:// or https:// as only these # are supported by the ``requests`` # library [^.:%\s_/?#[\]@\\]+ # Initial part of domain \. # A required dot `.` ( (?:[^\s()%\'"`<>|\\\[\]]+) # Path name # This part does not allow # any parenthesis: balanced or # unbalanced. | # OR \([^\s()%\'"`<>|\\\[\]]*\) # Path name contained within () # This part allows path names that # are explicitly enclosed within one # set of parenthesis. # An example can be: # http://wik.org/Hello_(Adele_song)/200 ) *) # Thus, the whole part above # prevents matching of # Unbalanced parenthesis (?<!\.)(?<!,) # Exclude trailing `.` or `,` from URL """, re.VERBOSE) file_context = {} for line_number, line in enumerate(file): xmlns_regex = re.compile(r'xmlns:?\w*="(.*)"') for match in re.findall(regex, line): link = match[0] link_context = file_context.get(link) if not link_context: link_context = enum(xml_namespace=False, pip_vcs_url=False) xmlns_match = xmlns_regex.search(line) if xmlns_match and link in xmlns_match.groups(): link_context.xml_namespace = True if link.startswith(('hg+', 'bzr+', 'git+', 'svn+')): link_context.pip_vcs_url = True file_context[link] = link_context if not (link_ignore_regex.search(link) or fnmatch(link, link_ignore_list)): yield link, line_number, link_context
from coalib.misc.Enum import enum RESULT_SEVERITY = enum('INFO', 'NORMAL', 'MAJOR') RESULT_SEVERITY.__str__ = lambda x: RESULT_SEVERITY.reverse.get(x, 'NORMAL') RESULT_SEVERITY_COLORS = {RESULT_SEVERITY.INFO: 'green', RESULT_SEVERITY.NORMAL: 'yellow', RESULT_SEVERITY.MAJOR: 'red'}
from coalib.misc.Enum import enum RESULT_SEVERITY = enum("INFO", "NORMAL", "MAJOR") RESULT_SEVERITY.__str__ = lambda x: RESULT_SEVERITY.reverse.get(x, "NORMAL") RESULT_SEVERITY_COLORS = { RESULT_SEVERITY.INFO: "green", RESULT_SEVERITY.NORMAL: "yellow", RESULT_SEVERITY.MAJOR: "red" }
import logging from coalib.misc.Enum import enum LOG_LEVEL = enum(DEBUG=logging.DEBUG, INFO=logging.INFO, WARNING=logging.WARNING, ERROR=logging.ERROR) LOG_LEVEL_COLORS = { LOG_LEVEL.ERROR: "red", LOG_LEVEL.WARNING: "yellow", LOG_LEVEL.INFO: "blue", LOG_LEVEL.DEBUG: "green" }
from coalib.misc.Enum import enum from coalib.misc.i18n import _, N_ RESULT_SEVERITY = enum(N_("INFO"), N_("NORMAL"), N_("MAJOR")) RESULT_SEVERITY.__str__ = lambda x: _(RESULT_SEVERITY.reverse.get(x, "NORMAL"))
class DocstringMetadata: _ParseMode = enum("DESCRIPTION", "PARAM", "RETVAL") def __init__(self, desc, param_dict, retval_desc): """ Represents a docstring of a python class or function. :param desc: A description as string. :param param_dict: A dictionary containing parameter names as key and their description as value. To preserve the order, use OrderedDict. :param retval_desc: A string describing the return value. """ self.desc = desc self.param_dict = param_dict self.retval_desc = retval_desc @classmethod def from_docstring(cls, docstring): """ Parses a python docstring. Usable attributes are: :param @param :return @return """ lines = inspect.cleandoc(docstring).split("\n") parse_mode = cls._ParseMode.DESCRIPTION cur_param = "" desc = "" param_dict = OrderedDict() retval_desc = "" for line in lines: line = line.strip() if line.startswith(":param ") or line.startswith("@param "): parse_mode = cls._ParseMode.PARAM splitted = line[7:].split(":", 1) cur_param = splitted[0] param_dict[cur_param] = splitted[1].strip() continue if line.startswith(":return: ") or line.startswith("@return: "): parse_mode = cls._ParseMode.RETVAL retval_desc = line[9:].strip() continue def concat_doc_parts(old: str, new: str): if new != '' and not old.endswith('\n'): return old + ' ' + new return old + (new if new != '' else '\n') if parse_mode == cls._ParseMode.RETVAL: retval_desc = concat_doc_parts(retval_desc, line) elif parse_mode == cls._ParseMode.PARAM: param_dict[cur_param] = concat_doc_parts(param_dict[cur_param], line) else: desc = concat_doc_parts(desc, line) return (cls(desc=desc.strip(), param_dict=param_dict, retval_desc=retval_desc.strip())) def __str__(self): return str(self.desc)
def setUp(self): self.uut = enum('ZERO', 'ONE', 'TWO', THREE='val')
from coalib.misc.Enum import enum from coalib.misc.i18n import N_ LOG_LEVEL = enum(N_("DEBUG"), N_("INFO"), N_("WARNING"), N_("ERROR")) LOG_LEVEL_COLORS = {LOG_LEVEL.ERROR: "red", LOG_LEVEL.WARNING: "yellow", LOG_LEVEL.INFO: "blue", LOG_LEVEL.DEBUG: "green"}
from coalib.misc.Enum import enum LOG_LEVEL = enum("DEBUG", "INFO", "WARNING", "ERROR") LOG_LEVEL_COLORS = { LOG_LEVEL.ERROR: "red", LOG_LEVEL.WARNING: "yellow", LOG_LEVEL.INFO: "blue", LOG_LEVEL.DEBUG: "green", }
from coalib.misc.Enum import enum from coalib.misc.i18n import N_ LOG_LEVEL = enum(N_("DEBUG"), N_("WARNING"), N_("ERROR"))
from coalib.misc.Enum import enum CONTROL_ELEMENT = enum("LOCAL", "GLOBAL", "FINISHED")
from coalib.misc.Enum import enum BEAR_KIND = enum('LOCAL', 'GLOBAL')
import logging from coalib.misc.Enum import enum LOG_LEVEL = enum(DEBUG=logging.DEBUG, INFO=logging.INFO, WARNING=logging.WARNING, ERROR=logging.ERROR) LOG_LEVEL_COLORS = {LOG_LEVEL.ERROR: 'red', LOG_LEVEL.WARNING: 'yellow', LOG_LEVEL.INFO: 'blue', LOG_LEVEL.DEBUG: 'green'}
from coalib.misc.Enum import enum CONTROL_ELEMENT = enum('LOCAL', 'GLOBAL', 'LOCAL_FINISHED', 'GLOBAL_FINISHED')
return count def is_function(stack): """ Checks if the cursor on top of the stack is used as a method or as a variable. :param stack: A stack holding a tuple holding the parent cursors and the child number. :return: True if this is used as a function, false otherwise. """ return _is_nth_child_of_kind(stack, [0], CursorKind.CALL_EXPR) != 0 FOR_POSITION = enum('UNKNOWN', 'INIT', 'COND', 'INC', 'BODY') def _get_position_in_for_tokens(tokens, position): """ Retrieves the semantic position of the given position in a for loop. It operates under the assumptions that the given tokens represent a for loop and that the given position is within the tokens. :param tokens: The tokens representing the for loop (clang extent) :param position: A tuple holding (line, column) of the position to identify. :return: A FOR_POSITION object indicating where the position is semantically. """ state = FOR_POSITION.INIT
return count def is_function(stack): """ Checks if the cursor on top of the stack is used as a method or as a variable. :param stack: A stack holding a tuple holding the parent cursors and the child number. :return: True if this is used as a function, false otherwise. """ return _is_nth_child_of_kind(stack, [0], CursorKind.CALL_EXPR) != 0 FOR_POSITION = enum("UNKNOWN", "INIT", "COND", "INC", "BODY") def _get_position_in_for_tokens(tokens, position): """ Retrieves the semantic position of the given position in a for loop. It operates under the assumptions that the given tokens represent a for loop and that the given position is within the tokens. :param tokens: The tokens representing the for loop (clang extent) :param position: A tuple holding (line, column) of the position to identify. :return: A FOR_POSITION object indicating where the position is semantically. """ state = FOR_POSITION.INIT
from coalib.misc.Enum import enum LOG_LEVEL = enum("DEBUG", "INFO", "WARNING", "ERROR") LOG_LEVEL_COLORS = { LOG_LEVEL.ERROR: "red", LOG_LEVEL.WARNING: "yellow", LOG_LEVEL.INFO: "blue", LOG_LEVEL.DEBUG: "green" }
from coalib.misc.Enum import enum BEAR_KIND = enum("LOCAL", "GLOBAL")
def setUp(self): self.uut = enum("ZERO", "ONE", "TWO", THREE="val")
from coalib.misc.Enum import enum RESULT_SEVERITY = enum("INFO", "NORMAL", "MAJOR") RESULT_SEVERITY.__str__ = lambda x: RESULT_SEVERITY.reverse.get(x, "NORMAL") RESULT_SEVERITY_COLORS = {RESULT_SEVERITY.INFO: "green", RESULT_SEVERITY.NORMAL: "yellow", RESULT_SEVERITY.MAJOR: "red"}