1111from .lazyre import LazyReCompile
1212
1313LinePart = namedtuple ("LinePart" , ["start" , "stop" , "word" ])
14- current_word_re = LazyReCompile (r"(?<![)\]\w_.])" r"([\w_][\w0-9._]*[(]?)" )
14+ _current_word_re = LazyReCompile (r"(?<![)\]\w_.])" r"([\w_][\w0-9._]*[(]?)" )
1515
1616
1717def current_word (cursor_offset : int , line : str ) -> Optional [LinePart ]:
1818 """the object.attribute.attribute just before or under the cursor"""
1919 start = cursor_offset
2020 end = cursor_offset
2121 word = None
22- for m in current_word_re .finditer (line ):
22+ for m in _current_word_re .finditer (line ):
2323 if m .start (1 ) < cursor_offset <= m .end (1 ):
2424 start = m .start (1 )
2525 end = m .end (1 )
@@ -29,29 +29,29 @@ def current_word(cursor_offset: int, line: str) -> Optional[LinePart]:
2929 return LinePart (start , end , word )
3030
3131
32- current_dict_key_re = LazyReCompile (r"""[\w_][\w0-9._]*\[([\w0-9._(), '"]*)""" )
32+ _current_dict_key_re = LazyReCompile (r"""[\w_][\w0-9._]*\[([\w0-9._(), '"]*)""" )
3333
3434
3535def current_dict_key (cursor_offset : int , line : str ) -> Optional [LinePart ]:
3636 """If in dictionary completion, return the current key"""
37- for m in current_dict_key_re .finditer (line ):
37+ for m in _current_dict_key_re .finditer (line ):
3838 if m .start (1 ) <= cursor_offset <= m .end (1 ):
3939 return LinePart (m .start (1 ), m .end (1 ), m .group (1 ))
4040 return None
4141
4242
43- current_dict_re = LazyReCompile (r"""([\w_][\w0-9._]*)\[([\w0-9._(), '"]*)""" )
43+ _current_dict_re = LazyReCompile (r"""([\w_][\w0-9._]*)\[([\w0-9._(), '"]*)""" )
4444
4545
4646def current_dict (cursor_offset : int , line : str ) -> Optional [LinePart ]:
4747 """If in dictionary completion, return the dict that should be used"""
48- for m in current_dict_re .finditer (line ):
48+ for m in _current_dict_re .finditer (line ):
4949 if m .start (2 ) <= cursor_offset <= m .end (2 ):
5050 return LinePart (m .start (1 ), m .end (1 ), m .group (1 ))
5151 return None
5252
5353
54- current_string_re = LazyReCompile (
54+ _current_string_re = LazyReCompile (
5555 '''(?P<open>(?:""")|"|(?:''\' )|')(?:((?P<closed>.+?)(?P=open))|'''
5656 """(?P<unclosed>.+))"""
5757)
@@ -63,14 +63,14 @@ def current_string(cursor_offset: int, line: str) -> Optional[LinePart]:
6363
6464 Weaker than bpython.Repl's current_string, because that checks that a
6565 string is a string based on previous lines in the buffer."""
66- for m in current_string_re .finditer (line ):
66+ for m in _current_string_re .finditer (line ):
6767 i = 3 if m .group (3 ) else 4
6868 if m .start (i ) <= cursor_offset <= m .end (i ):
6969 return LinePart (m .start (i ), m .end (i ), m .group (i ))
7070 return None
7171
7272
73- current_object_re = LazyReCompile (r"([\w_][\w0-9_]*)[.]" )
73+ _current_object_re = LazyReCompile (r"([\w_][\w0-9_]*)[.]" )
7474
7575
7676def current_object (cursor_offset : int , line : str ) -> Optional [LinePart ]:
@@ -82,15 +82,15 @@ def current_object(cursor_offset: int, line: str) -> Optional[LinePart]:
8282 start , end , word = match
8383 s = "." .join (
8484 m .group (1 )
85- for m in current_object_re .finditer (word )
85+ for m in _current_object_re .finditer (word )
8686 if m .end (1 ) + start < cursor_offset
8787 )
8888 if not s :
8989 return None
9090 return LinePart (start , start + len (s ), s )
9191
9292
93- current_object_attribute_re = LazyReCompile (r"([\w_][\w0-9_]*)[.]?" )
93+ _current_object_attribute_re = LazyReCompile (r"([\w_][\w0-9_]*)[.]?" )
9494
9595
9696def current_object_attribute (
@@ -102,15 +102,15 @@ def current_object_attribute(
102102 if match is None :
103103 return None
104104 start , end , word = match
105- matches = current_object_attribute_re .finditer (word )
105+ matches = _current_object_attribute_re .finditer (word )
106106 next (matches )
107107 for m in matches :
108108 if m .start (1 ) + start <= cursor_offset <= m .end (1 ) + start :
109109 return LinePart (m .start (1 ) + start , m .end (1 ) + start , m .group (1 ))
110110 return None
111111
112112
113- current_from_import_from_re = LazyReCompile (
113+ _current_from_import_from_re = LazyReCompile (
114114 r"from +([\w0-9_.]*)(?:\s+import\s+([\w0-9_]+[,]?\s*)+)*"
115115)
116116
@@ -124,17 +124,19 @@ def current_from_import_from(
124124 parts of an import: from (module) import (name1, name2)
125125 """
126126 # TODO allow for as's
127- for m in current_from_import_from_re .finditer (line ):
127+ for m in _current_from_import_from_re .finditer (line ):
128128 if (m .start (1 ) < cursor_offset <= m .end (1 )) or (
129129 m .start (2 ) < cursor_offset <= m .end (2 )
130130 ):
131131 return LinePart (m .start (1 ), m .end (1 ), m .group (1 ))
132132 return None
133133
134134
135- current_from_import_import_re_1 = LazyReCompile (r"from\s+([\w0-9_.]*)\s+import" )
136- current_from_import_import_re_2 = LazyReCompile (r"([\w0-9_]+)" )
137- current_from_import_import_re_3 = LazyReCompile (r", *([\w0-9_]*)" )
135+ _current_from_import_import_re_1 = LazyReCompile (
136+ r"from\s+([\w0-9_.]*)\s+import"
137+ )
138+ _current_from_import_import_re_2 = LazyReCompile (r"([\w0-9_]+)" )
139+ _current_from_import_import_re_3 = LazyReCompile (r", *([\w0-9_]*)" )
138140
139141
140142def current_from_import_import (
@@ -144,15 +146,15 @@ def current_from_import_import(
144146
145147 returns None if cursor not in or just after one of these words
146148 """
147- baseline = current_from_import_import_re_1 .search (line )
149+ baseline = _current_from_import_import_re_1 .search (line )
148150 if baseline is None :
149151 return None
150- match1 = current_from_import_import_re_2 .search (line [baseline .end () :])
152+ match1 = _current_from_import_import_re_2 .search (line [baseline .end () :])
151153 if match1 is None :
152154 return None
153155 for m in chain (
154156 (match1 ,),
155- current_from_import_import_re_3 .finditer (line [baseline .end () :]),
157+ _current_from_import_import_re_3 .finditer (line [baseline .end () :]),
156158 ):
157159 start = baseline .end () + m .start (1 )
158160 end = baseline .end () + m .end (1 )
@@ -161,21 +163,21 @@ def current_from_import_import(
161163 return None
162164
163165
164- current_import_re_1 = LazyReCompile (r"import" )
165- current_import_re_2 = LazyReCompile (r"([\w0-9_.]+)" )
166- current_import_re_3 = LazyReCompile (r"[,][ ]*([\w0-9_.]*)" )
166+ _current_import_re_1 = LazyReCompile (r"import" )
167+ _current_import_re_2 = LazyReCompile (r"([\w0-9_.]+)" )
168+ _current_import_re_3 = LazyReCompile (r"[,][ ]*([\w0-9_.]*)" )
167169
168170
169171def current_import (cursor_offset : int , line : str ) -> Optional [LinePart ]:
170172 # TODO allow for multiple as's
171- baseline = current_import_re_1 .search (line )
173+ baseline = _current_import_re_1 .search (line )
172174 if baseline is None :
173175 return None
174- match1 = current_import_re_2 .search (line [baseline .end () :])
176+ match1 = _current_import_re_2 .search (line [baseline .end () :])
175177 if match1 is None :
176178 return None
177179 for m in chain (
178- (match1 ,), current_import_re_3 .finditer (line [baseline .end () :])
180+ (match1 ,), _current_import_re_3 .finditer (line [baseline .end () :])
179181 ):
180182 start = baseline .end () + m .start (1 )
181183 end = baseline .end () + m .end (1 )
@@ -184,25 +186,25 @@ def current_import(cursor_offset: int, line: str) -> Optional[LinePart]:
184186 return None
185187
186188
187- current_method_definition_name_re = LazyReCompile (r"def\s+([a-zA-Z_][\w]*)" )
189+ _current_method_definition_name_re = LazyReCompile (r"def\s+([a-zA-Z_][\w]*)" )
188190
189191
190192def current_method_definition_name (
191193 cursor_offset : int , line : str
192194) -> Optional [LinePart ]:
193195 """The name of a method being defined"""
194- for m in current_method_definition_name_re .finditer (line ):
196+ for m in _current_method_definition_name_re .finditer (line ):
195197 if m .start (1 ) <= cursor_offset <= m .end (1 ):
196198 return LinePart (m .start (1 ), m .end (1 ), m .group (1 ))
197199 return None
198200
199201
200- current_single_word_re = LazyReCompile (r"(?<![.])\b([a-zA-Z_][\w]*)" )
202+ _current_single_word_re = LazyReCompile (r"(?<![.])\b([a-zA-Z_][\w]*)" )
201203
202204
203205def current_single_word (cursor_offset : int , line : str ) -> Optional [LinePart ]:
204206 """the un-dotted word just before or under the cursor"""
205- for m in current_single_word_re .finditer (line ):
207+ for m in _current_single_word_re .finditer (line ):
206208 if m .start (1 ) <= cursor_offset <= m .end (1 ):
207209 return LinePart (m .start (1 ), m .end (1 ), m .group (1 ))
208210 return None
@@ -221,7 +223,7 @@ def current_dotted_attribute(
221223 return None
222224
223225
224- current_expression_attribute_re = LazyReCompile (
226+ _current_expression_attribute_re = LazyReCompile (
225227 r"[.]\s*((?:[\w_][\w0-9_]*)|(?:))"
226228)
227229
@@ -231,7 +233,7 @@ def current_expression_attribute(
231233) -> Optional [LinePart ]:
232234 """If after a dot, the attribute being completed"""
233235 # TODO replace with more general current_expression_attribute
234- for m in current_expression_attribute_re .finditer (line ):
236+ for m in _current_expression_attribute_re .finditer (line ):
235237 if m .start (1 ) <= cursor_offset <= m .end (1 ):
236238 return LinePart (m .start (1 ), m .end (1 ), m .group (1 ))
237239 return None
0 commit comments