Пример #1
0
    def test_mydel(self):
        # Test a simple use scenario.

        # Initialize an int delegator.
        mydel = Delegator(int)
        self.assertIs(mydel.delegate, int)
        self.assertEqual(mydel._Delegator__cache, set())
        # Trying to access a non-attribute of int fails.
        self.assertRaises(AttributeError, mydel.__getattr__, 'xyz')

        # Add real int attribute 'bit_length' by accessing it.
        bl = mydel.bit_length
        self.assertIs(bl, int.bit_length)
        self.assertIs(mydel.__dict__['bit_length'], int.bit_length)
        self.assertEqual(mydel._Delegator__cache, {'bit_length'})

        # Add attribute 'numerator'.
        mydel.numerator
        self.assertEqual(mydel._Delegator__cache, {'bit_length', 'numerator'})

        # Delete 'numerator'.
        del mydel.numerator
        self.assertNotIn('numerator', mydel.__dict__)
        # The current implementation leaves  it in the name cache.
        # self.assertIn('numerator', mydel._Delegator__cache)
        # However, this is not required and not part of the specification

        # Change delegate to float, first resetting the attributes.
        mydel.setdelegate(float)  # calls resetcache
        self.assertNotIn('bit_length', mydel.__dict__)
        self.assertEqual(mydel._Delegator__cache, set())
        self.assertIs(mydel.delegate, float)
Пример #2
0
    def test_mydel(self):
        # Test a simple use scenario.

        # Initialize an int delegator.
        mydel = Delegator(int)
        self.assertIs(mydel.delegate, int)
        self.assertEqual(mydel._Delegator__cache, set())
        # Trying to access a non-attribute of int fails.
        self.assertRaises(AttributeError, mydel.__getattr__, 'xyz')

        # Add real int attribute 'bit_length' by accessing it.
        bl = mydel.bit_length
        self.assertIs(bl, int.bit_length)
        self.assertIs(mydel.__dict__['bit_length'], int.bit_length)
        self.assertEqual(mydel._Delegator__cache, {'bit_length'})

        # Add attribute 'numerator'.
        mydel.numerator
        self.assertEqual(mydel._Delegator__cache, {'bit_length', 'numerator'})

        # Delete 'numerator'.
        del mydel.numerator
        self.assertNotIn('numerator', mydel.__dict__)
        # The current implementation leaves  it in the name cache.
        # self.assertIn('numerator', mydel._Delegator__cache)
        # However, this is not required and not part of the specification

        # Change delegate to float, first resetting the attributes.
        mydel.setdelegate(float)  # calls resetcache
        self.assertNotIn('bit_length', mydel.__dict__)
        self.assertEqual(mydel._Delegator__cache, set())
        self.assertIs(mydel.delegate, float)
Пример #3
0
    def test_mydel(self):
        # test a simple use scenario

        # initialize
        mydel = Delegator(int)
        self.assertIs(mydel.delegate, int)
        self.assertEqual(mydel._Delegator__cache, set())

        # add an attribute:
        self.assertRaises(AttributeError, mydel.__getattr__, "xyz")
        bl = mydel.bit_length
        self.assertEqual(bl, int.bit_length)
        self.assertEqual(mydel.__dict__["bit_length"], int.bit_length)
        self.assertEqual(mydel._Delegator__cache, {"bit_length"})

        # add a second attribute
        mydel.numerator
        self.assertEqual(mydel._Delegator__cache, {"bit_length", "numerator"})

        # delete the second (which, however, leaves it in the name cache)
        del mydel.numerator
        self.assertNotIn("numerator", mydel.__dict__)
        self.assertIn("numerator", mydel._Delegator__cache)

        # reset by calling .setdelegate, which calls .resetcache
        mydel.setdelegate(float)
        self.assertIs(mydel.delegate, float)
        self.assertNotIn("bit_length", mydel.__dict__)
        self.assertEqual(mydel._Delegator__cache, set())
    def test_mydel(self):
        # test a simple use scenario

        # initialize
        mydel = Delegator(int)
        self.assertIs(mydel.delegate, int)
        self.assertEqual(mydel._Delegator__cache, set())

        # add an attribute:
        self.assertRaises(AttributeError, mydel.__getattr__, 'xyz')
        bl = mydel.bit_length
        self.assertIs(bl, int.bit_length)
        self.assertIs(mydel.__dict__['bit_length'], int.bit_length)
        self.assertEqual(mydel._Delegator__cache, {'bit_length'})

        # add a second attribute
        mydel.numerator
        self.assertEqual(mydel._Delegator__cache, {'bit_length', 'numerator'})

        # delete the second (which, however, leaves it in the name cache)
        del mydel.numerator
        self.assertNotIn('numerator', mydel.__dict__)
        self.assertIn('numerator', mydel._Delegator__cache)

        # reset by calling .setdelegate, which calls .resetcache
        mydel.setdelegate(float)
        self.assertIs(mydel.delegate, float)
        self.assertNotIn('bit_length', mydel.__dict__)
        self.assertEqual(mydel._Delegator__cache, set())
Пример #5
0
 def setdelegate(self, delegate):
     if self.delegate is not None:
         self.unbind("<<toggle-auto-coloring>>")
     Delegator.setdelegate(self, delegate)
     if delegate is not None:
         self.config_colors()
         self.bind("<<toggle-auto-coloring>>", self.toggle_colorize_event)
         self.notify_range("1.0", "end")
Пример #6
0
 def setdelegate(self, delegate):
     if self.delegate is not None:
         self.unbind('<<toggle-auto-coloring>>')
     Delegator.setdelegate(self, delegate)
     if delegate is not None:
         self.config_colors()
         self.bind('<<toggle-auto-coloring>>', self.toggle_colorize_event)
         self.notify_range('1.0', 'end')
     return
Пример #7
0
 def setdelegate(self, delegate):
     if self.delegate is not None:
         self.unbind("<<undo>>")
         self.unbind("<<redo>>")
         self.unbind("<<dump-undo-state>>")
     Delegator.setdelegate(self, delegate)
     if delegate is not None:
         self.bind("<<undo>>", self.undo_event)
         self.bind("<<redo>>", self.redo_event)
         self.bind("<<dump-undo-state>>", self.dump_event)
Пример #8
0
 def setdelegate(self, delegate):
     if self.delegate is not None:
         self.unbind('<<toggle-auto-coloring>>')
     Delegator.setdelegate(self, delegate)
     if delegate is not None:
         self.config_colors()
         self.bind('<<toggle-auto-coloring>>', self.toggle_colorize_event)
         self.notify_range('1.0', 'end')
     else:
         self.stop_colorizing = True
         self.allow_colorizing = False
     return
Пример #9
0
 def setdelegate(self, delegate):
     if self.delegate is not None:
         self.unbind("<<toggle-auto-coloring>>")
     Delegator.setdelegate(self, delegate)
     if delegate is not None:
         self.config_colors()
         self.bind("<<toggle-auto-coloring>>", self.toggle_colorize_event)
         self.notify_range("1.0", "end")
     else:
         # No delegate - stop any colorizing
         self.stop_colorizing = True
         self.allow_colorizing = False
Пример #10
0
 def setdelegate(self, delegate):
     if self.delegate is not None:
         self.unbind("<<toggle-auto-coloring>>")
     Delegator.setdelegate(self, delegate)
     if delegate is not None:
         self.config_colors()
         self.bind("<<toggle-auto-coloring>>", self.toggle_colorize_event)
         self.notify_range("1.0", "end")
     else:
         # No delegate - stop any colorizing
         self.stop_colorizing = True
         self.allow_colorizing = False
Пример #11
0
 def __init__(self, glpane, staterefs, delegate = None, lexmods = {}):
     #e rename glpane?
     #e type of staterefs? [just an external dict, as of 061116 calling code; the 'refs' in the name is to remind you it's not owned]
     #e rules/lexenv too?
     #e ipath? [061116: no, that's separate, tho if we end up splitting it by state-layer,
     #    we might have to change that, or let env have ipaths per layer with the separately-passed one relative to all those ]
     self.glpane = glpane
     self.staterefs = staterefs ###k
     ###KLUGES, explained below [061028]:
     Delegator.__init__(self, delegate) # this will be None or the parent env
     for k,v in lexmods.iteritems():
         setattr(self, k,v) # worst part of the kluge -- dangerous if symnames overlap method names
         # next worst part: special methods like __repr__ end up delegating
     pass
Пример #12
0
 def __init__(self, text):
     self.text = text
     self.redir = WidgetRedirector(text)
     self.top = self.bottom = Delegator(text)
     self.bottom.insert = self.redir.register('insert', self.insert)
     self.bottom.delete = self.redir.register('delete', self.delete)
     self.filters = []
Пример #13
0
 def __init__(self, text):
     # XXX would be nice to inherit from Delegator
     self.text = text
     self.redir = WidgetRedirector(text)
     self.top = self.bottom = Delegator(text)
     self.bottom.insert = self.redir.register("insert", self.insert)
     self.bottom.delete = self.redir.register("delete", self.delete)
     self.filters = []
Пример #14
0
 def test_mydel(self):
     mydel = Delegator(int)
     self.assertIs(mydel.delegate, int)
     self.assertEqual(mydel._Delegator__cache, set())
     self.assertRaises(AttributeError, mydel.__getattr__, 'xyz')
     bl = mydel.bit_length
     self.assertIs(bl, int.bit_length)
     self.assertIs(mydel.__dict__['bit_length'], int.bit_length)
     self.assertEqual(mydel._Delegator__cache, {'bit_length'})
     mydel.numerator
     self.assertEqual(mydel._Delegator__cache, {'bit_length', 'numerator'})
     del mydel.numerator
     self.assertNotIn('numerator', mydel.__dict__)
     self.assertIn('numerator', mydel._Delegator__cache)
     mydel.setdelegate(float)
     self.assertIs(mydel.delegate, float)
     self.assertNotIn('bit_length', mydel.__dict__)
     self.assertEqual(mydel._Delegator__cache, set())
Пример #15
0
 def test_mydel(self):
     mydel = Delegator(int)
     self.assertIs(mydel.delegate, int)
     self.assertEqual(mydel._Delegator__cache, set())
     self.assertRaises(AttributeError, mydel.__getattr__, 'xyz')
     bl = mydel.bit_length
     self.assertIs(bl, int.bit_length)
     self.assertIs(mydel.__dict__['bit_length'], int.bit_length)
     self.assertEqual(mydel._Delegator__cache, {'bit_length'})
     mydel.numerator
     self.assertEqual(mydel._Delegator__cache, {'bit_length', 'numerator'})
     del mydel.numerator
     self.assertNotIn('numerator', mydel.__dict__)
     self.assertIn('numerator', mydel._Delegator__cache)
     mydel.setdelegate(float)
     self.assertIs(mydel.delegate, float)
     self.assertNotIn('bit_length', mydel.__dict__)
     self.assertEqual(mydel._Delegator__cache, set())
Пример #16
0
    def __init__(self, ext):
        Delegator.__init__(self)
        self.ext = altext(ext)
        self.prog = regex.compile(make_pat(ext), flags=regex.S|regex.M)

        try:
            self.lang = getattr(__import__('languages'+ext), ext[1:])
            if hasattr(self.lang, 'read_twice'):
                self.read_twice = self.lang.read_twice
            else:
                self.read_twice = None

            self.more_decorate = {}
            if hasattr(self.lang, 'more_decorate'):
                self.more_decorate = self.lang.more_decorate

        except Exception as e:
            self.lang = None
            self.read_twice = None
        finally:
            self.LoadTagDefs()
Пример #17
0
    def __init__(self, ext):
        Delegator.__init__(self)
        self.ext = altext(ext)
        self.prog = regex.compile(make_pat(ext), flags=regex.S | regex.M)

        try:
            self.lang = getattr(__import__('languages' + ext), ext[1:])
            if hasattr(self.lang, 'read_twice'):
                self.read_twice = self.lang.read_twice
            else:
                self.read_twice = None

            self.more_decorate = {}
            if hasattr(self.lang, 'more_decorate'):
                self.more_decorate = self.lang.more_decorate

        except Exception as e:
            self.lang = None
            self.read_twice = None
        finally:
            self.LoadTagDefs()
Пример #18
0
 def __init__(self, callback):
     Delegator.__init__(self)
     self.callback = callback
     self.paste = False
Пример #19
0
 def __init__(self):
     Delegator.__init__(self)
     self.prog = prog
     self.idprog = idprog
     self.asprog = asprog
     self.LoadTagDefs()
Пример #20
0
 def __init__(self):
     Delegator.__init__(self)
     self.prog = re.compile(make_pat(), re.S)
     self.idprog = re.compile(r"\s+(\w+)", re.S)
     self.LoadTagDefs()
Пример #21
0
 def __init__(self):
     Delegator.__init__(self)
     self.prog = re.compile(self.make_pat(), re.S)
     self.idprog = re.compile(r"\s+(\w+)", re.S)
     self.LoadTagDefs()
Пример #22
0
 def __init__(self):
     Delegator.__init__(self)
     self.reset_undo()
Пример #23
0
 def __init__(self, name):
     self.name = name
     Delegator.__init__(self, None)
Пример #24
0
 def __init__(self, line_number_instance):
     Delegator.__init__(self)
     self.ext = line_number_instance
Пример #25
0
 def __init__(self, line_number_instance):
     Delegator.__init__(self)
     self.ext = line_number_instance
Пример #26
0
 def __init__(self, name):
     self.name = name
     Delegator.__init__(self, None)