Skip to content

Commit 5a27c39

Browse files
Experimental code for Python 3.8 no RF installed
1 parent fce171b commit 5a27c39

File tree

3 files changed

+82
-5
lines changed

3 files changed

+82
-5
lines changed

src/robotide/controller/dataloader.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ def __init__(self, path, settings, language=None):
9898

9999
def _run(self):
100100
if not self.language:
101-
self.language = lang.check_file_language(self._path)
101+
try:
102+
self.language = lang.check_file_language(self._path)
103+
except Exception:
104+
self.language = 'en'
102105
return test_data(source=self._path, settings=self._settings, language=self.language)
103106

104107

@@ -115,7 +118,10 @@ def _run(self):
115118
language=self.language)
116119
result.initfile = self._path
117120
if not self.language:
118-
self.language = lang.check_file_language(self._path)
121+
try:
122+
self.language = lang.check_file_language(self._path)
123+
except Exception:
124+
self.language = 'en'
119125
robotapi.FromFilePopulator(result, lang=self.language).populate(self._path)
120126
return result
121127

src/robotide/editor/texteditor.py

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,72 @@ def _set_shared_doc_lang(self, lang='en'):
717717
def set_editor(self, editor):
718718
self._editor = editor
719719

720-
def validate_and_update(self, data, text, lang='en'):
720+
721+
def validate_and_update(self, data, text):
722+
723+
try:
724+
from robot.parsing.parser.parser import get_model # RF > 4.0
725+
except ImportError:
726+
return self._old_validate_and_update(data, text)
727+
return self._new_validate_and_update(data, text)
728+
729+
"""
730+
Backwards compatible code v1.7.4.2
731+
"""
732+
733+
def _old_validate_and_update(self, data, text):
734+
m_text = text.decode("utf-8")
735+
if not self._old_sanity_check(data, m_text):
736+
handled = self._old_handle_sanity_check_failure()
737+
if not handled:
738+
return False
739+
self._editor.reset()
740+
# print("DEBUG: updating text") # %s" % (self._editor.GetCurrentPos()))
741+
data.update_from(m_text)
742+
# print("DEBUG: AFTER updating text")
743+
self._editor.set_editor_caret_position()
744+
# %s" % (self._editor.GetCurrentPos()))
745+
return True
746+
747+
def _old_sanity_check(self, data, text):
748+
formatted_text = data.format_text(text)
749+
c = self._normalize(formatted_text)
750+
e = self._normalize(text)
751+
return len(c) == len(e)
752+
753+
@staticmethod
754+
def _normalize(self, text):
755+
for item in [' ', r'\t', r'\n', r'\r\n', '...', '*']:
756+
if item in text:
757+
# print("DEBUG: _normaliz item %s txt %s" % (item, text))
758+
text = text.replace(item, '')
759+
return text
760+
761+
def _old_handle_sanity_check_failure(self):
762+
if self._last_answer == wx.ID_NO and \
763+
time() - self._last_answer_time <= 0.2:
764+
self._editor._mark_file_dirty()
765+
return False
766+
# TODO: use widgets.Dialog
767+
id = wx.MessageDialog(self._editor,
768+
'ERROR: Data sanity check failed!\n'
769+
'Reset changes?',
770+
'Can not apply changes from Txt Editor',
771+
style=wx.YES | wx.NO).ShowModal()
772+
self._last_answer = id
773+
self._last_answer_time = time()
774+
if id == wx.ID_YES:
775+
self._editor._revert()
776+
return True
777+
else:
778+
self._editor._mark_file_dirty()
779+
return False
780+
781+
"""
782+
End Backwards compatible code v1.7.4.2
783+
"""
784+
785+
def _new_validate_and_update(self, data, text, lang='en'):
721786
from robotide.lib.robot.errors import DataError
722787
m_text = text.decode("utf-8")
723788
# print(f"DEBUG: textedit.py validate_and_update ENTER"

src/robotide/lib/compat/parsing/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from .validator import ErrorReporter
15+
try:
16+
from .validator import ErrorReporter
17+
except ImportError:
18+
pass
1619
from .language import get_english_label, get_localized_setting
17-
from .languages import *
20+
try:
21+
from .languages import *
22+
except ImportError:
23+
pass

0 commit comments

Comments
 (0)