• Need help

Question related to mission Text Editor

 

Hello to everybody!

I need any help with mission "Text Editor". I wrote my code, it works on my PC with python3.6. When I try to check my code here, I get en error: "TypeError: <class 'dict'> is wrong data type". I don't know where the problem is and I can't be helped by somebody around me. I've just started to learn Classes and OOP and unfortunately my code so far from ideal, but I want to progress in python... My code is below:

import re, copy

res = ''
saved_states = []

class Memento(object):

    def __init__(self, state):
    self._state = state

    def get_saved_state(self):
    return self._state


class Originator(object):   

    def set(self, state):
        global res
        self._state = state
        res = self._state

    def save_to_memento(self):
        return Memento(copy.deepcopy(self._state))

    def restore_from_memento(self, memento):
        global res
        self._state = memento.get_saved_state()
        res = self._state

class Text(Originator):

    font = None

    def __init__(self, data = ''):
        self.data = data

    def __str__(self):
        return self.data

    def write(self, data):
        if Text.font:
            self.data = re.sub("\['\w*']", '', self.data)
            self.data = '{0}{1}{2}'.format([Text.font], self.data + data, [Text.font])
        else:
            self.data = '{0}{1}{2}'.format('', self.data + data, '')

    def set_font(self, font_name):
        if Text.font:
            self.data = re.sub(r'\[\w*]', '', self.data)
        Text.font = font_name
        self.data = '{0}{1}{2}'.format([Text.font], self.data, [Text.font])

    @staticmethod           
    def show():
        return res

    @staticmethod       
    def restore(ex):
        return ex


    class SavedText(Originator):

    def save_text(self, text):
        Originator.set(self, text)
        saved_states.append(Originator.save_to_memento(self))

    def get_version(self, number):
        return Originator.restore_from_memento(self, saved_states[number])