def test_two_locals(self):
     '''Ensures that two locals in the same thread have separate dicts.'''
     first = local()
     first.x = 7
     second = local()
     second.x = 12
     self.assertEquals(7, first.x)
     self.assertEquals(12, second.x)
Beispiel #2
0
 def test_two_locals(self):
     '''Ensures that two locals in the same thread have separate dicts.'''
     first = local()
     first.x = 7
     second = local()
     second.x = 12
     self.assertEquals(7, first.x)
     self.assertEquals(12, second.x)
    def test_local(self):
        mydata = local()
        mydata.number = 42
        self.assertEqual(mydata.number, 42)
        self.assertEqual(mydata.__dict__, {'number': 42})
        mydata.__dict__.setdefault('widgets', [])
        self.assertEqual(mydata.widgets, [])
        log = []

        def f():
            items = mydata.__dict__.items()
            items.sort()
            log.append(items)
            mydata.number = 11
            log.append(mydata.number)

        thread = threading.Thread(target=f)
        thread.start()
        thread.join()
        self.assertEqual(log, [[], 11])
        self.assertEqual(mydata.number, 42)
Beispiel #4
0
    def test_local(self):
        mydata = local()
        mydata.number = 42
        self.assertEqual(mydata.number,42)
        self.assertEqual(mydata.__dict__,{'number': 42})
        mydata.__dict__.setdefault('widgets', [])
        self.assertEqual(mydata.widgets,[])
        log=[]

        def f():
            items = mydata.__dict__.items()
            items.sort()
            log.append(items)
            mydata.number = 11
            log.append(mydata.number)

        thread = threading.Thread(target=f)
        thread.start()
        thread.join()
        self.assertEqual(log,[[], 11])
        self.assertEqual(mydata.number,42)
Beispiel #5
0
    arg = cobj._get_buffer_value()
    return _rawffi.charp2rawstring(arg, lgt)

def set_conversion_mode(encoding, errors):
    old_cm = ConvMode.encoding, ConvMode.errors
    ConvMode.errors = errors
    ConvMode.encoding = encoding
    return old_cm

def _wstring_at_addr(addr, lgt):
    import ctypes
    cobj = ctypes.c_void_p.from_param(addr)
    arg = cobj._get_buffer_value()
    return _rawffi.wcharp2rawunicode(arg, lgt)

_err = local()

def get_errno():
    return getattr(_err, "errno", 0)

def set_errno(errno):
    old_errno = get_errno()
    _err.errno = errno
    return old_errno

def get_last_error():
    return getattr(_err, "winerror", 0)

def set_last_error(winerror):
    old_winerror = get_last_error()
    _err.winerror = winerror
    arg = cobj._get_buffer_value()
    return _rawffi.charp2rawstring(arg, lgt)

def set_conversion_mode(encoding, errors):
    old_cm = ConvMode.encoding, ConvMode.errors
    ConvMode.errors = errors
    ConvMode.encoding = encoding
    return old_cm

def _wstring_at_addr(addr, lgt):
    import ctypes
    cobj = ctypes.c_void_p.from_param(addr)
    arg = cobj._get_buffer_value()
    return _rawffi.wcharp2rawunicode(arg, lgt)

_err = local()

def get_errno():
    return getattr(_err, "errno", 0)

def set_errno(errno):
    old_errno = get_errno()
    _err.errno = errno
    return old_errno

def get_last_error():
    return getattr(_err, "winerror", 0)

def set_last_error(winerror):
    old_winerror = get_last_error()
    _err.winerror = winerror