def register_common_name(name, cmodule, cname): s = cmodule + '.' + cname cmodule_mark = Mark('<common name definition>', 1, 1, s, 1) cname_mark = Mark('<common name definition>', 1, len(cmodule) + 1, s, len(cmodule) + 1) common_names[name].add( (MarkedUnicode(cmodule, cmodule_mark), MarkedUnicode(cname, cname_mark)))
def update(self, length): if self.raw_buffer is None: return self.buffer = self.buffer[self.pointer:] self.pointer = 0 while len(self.buffer) < length: if not self.eof: self.update_raw() try: data, converted = self.raw_decode(self.raw_buffer, 'strict', self.eof) except UnicodeDecodeError as exc: character = self.raw_buffer[exc.start] position = self.stream_pointer - len( self.raw_buffer) + exc.start data, converted = self.raw_decode(self.raw_buffer[:exc.start], 'strict', self.eof) self.buffer += data self.full_buffer += data + '<' + str(ord(character)) + '>' self.raw_buffer = self.raw_buffer[converted:] self.update_pointer(exc.start - 1) raise ReaderError( 'while reading from stream', None, 'found character #x%04x that cannot be decoded by UTF-8 codec' % ord(character), Mark(self.name, self.line, self.column, self.full_buffer, position)) self.buffer += data self.full_buffer += data self.raw_buffer = self.raw_buffer[converted:] self.check_printable(data) if self.eof: self.buffer += '\0' self.raw_buffer = None break
def check_printable(self, data): match = NON_PRINTABLE_RE.search(data) if match: self.update_pointer(match.start()) raise ReaderError( 'while reading from stream', None, 'found special characters which are not allowed', Mark(self.name, self.line, self.column, self.full_buffer, self.full_pointer))
def get_mark(self): return Mark(self.name, self.line, self.column, self.full_buffer, self.full_pointer)
def check_segment_function(function_name, data, context, echoerr): havemarks(function_name) ext = data['ext'] module, function_name = get_function_strings(function_name, context, ext) if context[-2][1].get('type', 'function') == 'function': func = import_segment(function_name, data, context, echoerr, module=module) if not func: return True, False, True hl_groups = [] divider_hl_group = None if func.__doc__: H_G_USED_STR = 'Highlight groups used: ' LHGUS = len(H_G_USED_STR) D_H_G_USED_STR = 'Divider highlight group used: ' LDHGUS = len(D_H_G_USED_STR) pointer = 0 mark_name = '<{0} docstring>'.format(function_name) for i, line in enumerate(func.__doc__.split('\n')): if H_G_USED_STR in line: idx = line.index(H_G_USED_STR) + LHGUS hl_groups.append(( line[idx:], (mark_name, i + 1, idx + 1, func.__doc__), pointer + idx )) elif D_H_G_USED_STR in line: idx = line.index(D_H_G_USED_STR) + LDHGUS + 2 mark = Mark(mark_name, i + 1, idx + 1, func.__doc__, pointer + idx) divider_hl_group = MarkedUnicode(line[idx:-3], mark) pointer += len(line) + len('\n') hadproblem = False if divider_hl_group: r = hl_exists(divider_hl_group, data, context, echoerr, allow_gradients=True) if r: echoerr( context='Error while checking theme (key {key})'.format(key=context.key), context_mark=function_name.mark, problem=( 'found highlight group {0} not defined in the following colorschemes: {1}\n' '(Group name was obtained from function documentation.)' ).format(divider_hl_group, list_sep.join(r)), problem_mark=divider_hl_group.mark, ) hadproblem = True if check_hl_group_name(divider_hl_group, function_name.mark, context, echoerr): hadproblem = True if hl_groups: greg = re.compile(r'``([^`]+)``( \(gradient\))?') parsed_hl_groups = [] for line, mark_args, pointer in hl_groups: for s in line.split(', '): required_pack = [] sub_pointer = pointer for subs in s.split(' or '): match = greg.match(subs) try: if not match: continue hl_group = MarkedUnicode( match.group(1), Mark(*mark_args, pointer=sub_pointer + match.start(1)) ) if check_hl_group_name(hl_group, function_name.mark, context, echoerr): hadproblem = True gradient = bool(match.group(2)) required_pack.append((hl_group, gradient)) finally: sub_pointer += len(subs) + len(' or ') parsed_hl_groups.append(required_pack) pointer += len(s) + len(', ') del hl_group, gradient for required_pack in parsed_hl_groups: rs = [ hl_exists(hl_group, data, context, echoerr, allow_gradients=('force' if gradient else False)) for hl_group, gradient in required_pack ] if all(rs): echoerr( context='Error while checking theme (key {key})'.format(key=context.key), problem=( 'found highlight groups list ({0}) with all groups not defined in some colorschemes\n' '(Group names were taken from function documentation.)' ).format(list_sep.join((h[0] for h in required_pack))), problem_mark=function_name.mark ) for r, h in zip(rs, required_pack): echoerr( context='Error while checking theme (key {key})'.format(key=context.key), problem='found highlight group {0} not defined in the following colorschemes: {1}'.format( h[0], list_sep.join(r)) ) hadproblem = True else: r = hl_exists(function_name, data, context, echoerr, allow_gradients=True) if r: echoerr( context='Error while checking theme (key {key})'.format(key=context.key), problem=( 'found highlight group {0} not defined in the following colorschemes: {1}\n' '(If not specified otherwise in documentation, ' 'highlight group for function segments\n' 'is the same as the function name.)' ).format(function_name, list_sep.join(r)), problem_mark=function_name.mark ) hadproblem = True return True, False, hadproblem elif context[-2][1].get('type') != 'segment_list': if function_name not in context[0][1].get('segment_data', {}): main_theme_name = data['main_config'].get('ext', {}).get(ext, {}).get('theme', None) if data['theme'] == main_theme_name: main_theme = {} else: main_theme = data['ext_theme_configs'].get(main_theme_name, {}) if ( function_name not in main_theme.get('segment_data', {}) and function_name not in data['ext_theme_configs'].get('__main__', {}).get('segment_data', {}) and not any(((function_name in theme.get('segment_data', {})) for theme in data['top_themes'].values())) ): echoerr(context='Error while checking segments (key {key})'.format(key=context.key), problem='found useless use of name key (such name is not present in theme/segment_data)', problem_mark=function_name.mark) return True, False, False