# Path: src/foolscap/util.py
# class AsyncAND(defer.Deferred):
#     def __init__(self, deferredList):
#     def _cbDeferred(self, result, succeeded):
# def get_local_ip_for(target='A.ROOT-SERVERS.NET'):
# def format_time(when, mode):
# def move_into_place(source, dest):
# def isSubstring(small, big):
# def allocate_tcp_port():
# def _make_socket():
# def ensure_tuple_str(input_tuple):
# def ensure_dict_binary(d):
# def ensure_dict_str(d):
# def ensure_dict_str_keys(d):
# FORMAT_TIME_MODES = ["short-local", "long-local", "utc", "epoch"]


import six
import io
import struct
from twisted.trial import unittest
from twisted.python.failure import Failure
from twisted.python.components import registerAdapter
from twisted.internet import defer
from foolscap.tokens import ISlicer, Violation, BananaError
from foolscap.tokens import BananaFailure, tokenNames, \
     OPEN, CLOSE, ABORT, INT, LONGINT, NEG, LONGNEG, FLOAT, STRING
from foolscap import slicer, schema, storage, banana, vocab
from foolscap.eventual import fireEventually, flushEventualQueue
from foolscap.slicers.allslicers import RootSlicer, DictUnslicer, TupleUnslicer
from foolscap.constraint import IConstraint
from foolscap.banana import int2b128, long_to_bytes
from ..util import long_type
from decimal import Decimal
        # but true/false is a constraint, and is reported with Violation
        self.violate2(self.TRUE(),
                      "<RootUnslicer>.<bool>",
                      schema.BooleanConstraint(False))
        self.violate2(self.FALSE(),
                      "<RootUnslicer>.<bool>",
                      schema.BooleanConstraint(True))


class ThereAndBackAgain(TestBananaMixin, unittest.TestCase):

    def test_int(self):
        d = self.looptest(42)
        d.addCallback(lambda res: self.looptest(-47))
        return d

    def test_bigint(self):
        # some of these are small enough to fit in an INT
        d = self.looptest(int(2**31-1)) # most positive representable INT
        d.addCallback(lambda res: self.looptest(long_type(2**31+0)))
        d.addCallback(lambda res: self.looptest(long_type(2**31+1)))

        d.addCallback(lambda res: self.looptest(long_type(-2**31-1)))
        # the following is the most negative representable INT
        d.addCallback(lambda res: self.looptest(int(-2**31+0)))
        d.addCallback(lambda res: self.looptest(int(-2**31+1)))

        d.addCallback(lambda res: self.looptest(long_type(2**100)))
        d.addCallback(lambda res: self.looptest(long_type(-2**100)))
        d.addCallback(lambda res: self.looptest(long_type(2**1000)))

# Path: src/foolscap/util.py
# class AsyncAND(defer.Deferred):
#     def __init__(self, deferredList):
#     def _cbDeferred(self, result, succeeded):
# def get_local_ip_for(target='A.ROOT-SERVERS.NET'):
# def format_time(when, mode):
# def move_into_place(source, dest):
# def isSubstring(small, big):
# def allocate_tcp_port():
# def _make_socket():
# def ensure_tuple_str(input_tuple):
# def ensure_dict_binary(d):
# def ensure_dict_str(d):
# def ensure_dict_str_keys(d):
# FORMAT_TIME_MODES = ["short-local", "long-local", "utc", "epoch"]


# Path: src/foolscap/test/test_banana.py
import six
import io
import struct
from twisted.trial import unittest
from twisted.python.failure import Failure
from twisted.python.components import registerAdapter
from twisted.internet import defer
from foolscap.tokens import ISlicer, Violation, BananaError
from foolscap.tokens import BananaFailure, tokenNames, \
     OPEN, CLOSE, ABORT, INT, LONGINT, NEG, LONGNEG, FLOAT, STRING
from foolscap import slicer, schema, storage, banana, vocab
from foolscap.eventual import fireEventually, flushEventualQueue
from foolscap.slicers.allslicers import RootSlicer, DictUnslicer, TupleUnslicer
from foolscap.constraint import IConstraint
from foolscap.banana import int2b128, long_to_bytes
from ..util import long_type
from decimal import Decimal

        # but true/false is a constraint, and is reported with Violation
        self.violate2(self.TRUE(),
                      "<RootUnslicer>.<bool>",
                      schema.BooleanConstraint(False))
        self.violate2(self.FALSE(),
                      "<RootUnslicer>.<bool>",
                      schema.BooleanConstraint(True))


class ThereAndBackAgain(TestBananaMixin, unittest.TestCase):

    def test_int(self):
        d = self.looptest(42)
        d.addCallback(lambda res: self.looptest(-47))
        return d

    def test_bigint(self):
        # some of these are small enough to fit in an INT
        d = self.looptest(int(2**31-1)) # most positive representable INT
        d.addCallback(lambda res: self.looptest(long_type(2**31+0)))
        d.addCallback(lambda res: self.looptest(long_type(2**31+1)))

        d.addCallback(lambda res: self.looptest(long_type(-2**31-1)))
        # the following is the most negative representable INT
        d.addCallback(lambda res: self.looptest(int(-2**31+0)))
        d.addCallback(lambda res: self.looptest(int(-2**31+1)))

        d.addCallback(lambda res: self.looptest(long_type(2**100)))
        d.addCallback(lambda res: self.looptest(long_type(-2**100)))
        d.addCallback(lambda res: self.looptest(long_type(2**1000)))

        d.addCallback(lambda res: self.looptest(long_type(-2**1000)))