Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/sqlparse/filters/right_margin.py: 25%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

28 statements  

1# 

2# Copyright (C) 2009-2020 the sqlparse authors and contributors 

3# <see AUTHORS file> 

4# 

5# This module is part of python-sqlparse and is released under 

6# the BSD License: https://opensource.org/licenses/BSD-3-Clause 

7 

8import re 

9 

10from sqlparse import sql, tokens as T 

11 

12 

13# FIXME: Doesn't work 

14class RightMarginFilter: 

15 keep_together = ( 

16 # sql.TypeCast, sql.Identifier, sql.Alias, 

17 ) 

18 

19 def __init__(self, width=79): 

20 self.width = width 

21 self.line = '' 

22 

23 def _process(self, group, stream): 

24 for token in stream: 

25 if token.is_whitespace and '\n' in token.value: 

26 if token.value.endswith('\n'): 

27 self.line = '' 

28 else: 

29 self.line = token.value.splitlines()[-1] 

30 elif token.is_group and type(token) not in self.keep_together: 

31 token.tokens = self._process(token, token.tokens) 

32 else: 

33 val = str(token) 

34 if len(self.line) + len(val) > self.width: 

35 match = re.search(r'^ +', self.line) 

36 if match is not None: 

37 indent = match.group() 

38 else: 

39 indent = '' 

40 yield sql.Token(T.Whitespace, f'\n{indent}') 

41 self.line = indent 

42 self.line += val 

43 yield token 

44 

45 def process(self, group): 

46 # return 

47 # group.tokens = self._process(group, group.tokens) 

48 raise NotImplementedError