Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/sqlparse/filters/right_margin.py: 22%

27 statements  

« prev     ^ index     » next       coverage.py v6.4.4, created at 2023-07-17 14:22 -0600

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, '\n{}'.format(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