Python sets.ImmutableSet() Examples

The following are 30 code examples of sets.ImmutableSet(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module sets , or try the search function .
Example #1
Source File: pkg_resources.py    From pledgeservice with Apache License 2.0 6 votes vote down vote up
def __init__(self, project_name, specs, extras):
        """DO NOT CALL THIS UNDOCUMENTED METHOD; use Requirement.parse()!"""
        self.unsafe_name, project_name = project_name, safe_name(project_name)
        self.project_name, self.key = project_name, project_name.lower()
        index = [
            (parse_version(v), state_machine[op], op, v)
            for op, v in specs
        ]
        index.sort()
        self.specs = [(op, ver) for parsed, trans, op, ver in index]
        self.index, self.extras = index, tuple(map(safe_extra, extras))
        self.hashCmp = (
            self.key,
            tuple((op, parsed) for parsed, trans, op, ver in index),
            frozenset(self.extras),
        )
        self.__hash = hash(self.hashCmp) 
Example #2
Source File: case.py    From ConTroll_Remote_Access_Trojan with Apache License 2.0 6 votes vote down vote up
def __init__(self, methodName='runTest'):
        """Create an instance of the class that will use the named test
           method when executed. Raises a ValueError if the instance does
           not have a method with the specified name.
        """
        self._testMethodName = methodName
        self._resultForDoCleanups = None
        try:
            testMethod = getattr(self, methodName)
        except AttributeError:
            raise ValueError("no such test method in %s: %s" % \
                  (self.__class__, methodName))
        self._testMethodDoc = testMethod.__doc__
        self._cleanups = []

        # Map types to custom assertEqual functions that will compare
        # instances of said type in more detail to generate a more useful
        # error message.
        self._type_equality_funcs = _TypeEqualityDict(self)
        self.addTypeEqualityFunc(dict, 'assertDictEqual')
        self.addTypeEqualityFunc(list, 'assertListEqual')
        self.addTypeEqualityFunc(tuple, 'assertTupleEqual')
        self.addTypeEqualityFunc(set, 'assertSetEqual')
        self.addTypeEqualityFunc(frozenset, 'assertSetEqual')
        self.addTypeEqualityFunc(unicode, 'assertMultiLineEqual') 
Example #3
Source File: Obs.py    From jeeves with MIT License 6 votes vote down vote up
def getRelatedObservations(self):
        ret = sets.Set() #Supposed to be ImmutableSet but we can't add elts to that; Set isnt hashed
        if self.isObsGrouping():
            for i in self.getGroupMembers():
                ret.add(i)
            parentObs = self
            while parentObs.getObsGroup() != None :
                for obsSibling in parentObs.getObsGroup().getGroupMembers():
                    if not(obsSibling.isObsGrouping()):
                        ret.add(obsSibling)
                parentObs = parentObs.getObsGroup()
        elif self.getObsGroup() != None:
            for obsSibling in self.getObsGroup().getGroupMembers():
                if not(obsSibling.isObsGrouping()):
                    ret.add(obsSibling)
        return ret 
Example #4
Source File: tokenizer.py    From nzb-subliminal with GNU General Public License v3.0 6 votes vote down vote up
def attributeValueUnQuotedState(self):
        data = self.stream.char()
        if data in spaceCharacters:
            self.state = self.beforeAttributeNameState
        elif data == u"&":
            self.processEntityInAttribute(">")
        elif data == u">":
            self.emitCurrentToken()
        elif data in (u'"', u"'", u"=", u"<", u"`"):
            self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
              "unexpected-character-in-unquoted-attribute-value"})
            self.currentToken["data"][-1][1] += data
        elif data == u"\u0000":
            self.tokenQueue.append({"type": tokenTypes["ParseError"], 
                                    "data": "invalid-codepoint"})
            self.currentToken["data"][-1][1] += u"\uFFFD"
        elif data is EOF:
            self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
              "eof-in-attribute-value-no-quotes"})
            self.state = self.dataState
        else:
            self.currentToken["data"][-1][1] += data + self.stream.charsUntil(
              frozenset((u"&", u">", u'"', u"'", u"=", u"<", u"`")) | spaceCharacters)
        return True 
Example #5
Source File: pkg_resources.py    From bazarr with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, project_name, specs, extras):
        """DO NOT CALL THIS UNDOCUMENTED METHOD; use Requirement.parse()!"""
        self.unsafe_name, project_name = project_name, safe_name(project_name)
        self.project_name, self.key = project_name, project_name.lower()
        index = [
            (parse_version(v), state_machine[op], op, v)
            for op, v in specs
        ]
        index.sort()
        self.specs = [(op, ver) for parsed, trans, op, ver in index]
        self.index, self.extras = index, tuple(map(safe_extra, extras))
        self.hashCmp = (
            self.key,
            tuple((op, parsed) for parsed, trans, op, ver in index),
            frozenset(self.extras),
        )
        self.__hash = hash(self.hashCmp) 
Example #6
Source File: pkg_resources.py    From Flask with Apache License 2.0 5 votes vote down vote up
def __init__(self, project_name, specs, extras):
        """DO NOT CALL THIS UNDOCUMENTED METHOD; use Requirement.parse()!"""
        self.unsafe_name, project_name = project_name, safe_name(project_name)
        self.project_name, self.key = project_name, project_name.lower()
        index = [(parse_version(v),state_machine[op],op,v) for op,v in specs]
        index.sort()
        self.specs = [(op,ver) for parsed,trans,op,ver in index]
        self.index, self.extras = index, tuple(map(safe_extra,extras))
        self.hashCmp = (
            self.key, tuple([(op,parsed) for parsed,trans,op,ver in index]),
            frozenset(self.extras)
        )
        self.__hash = hash(self.hashCmp) 
Example #7
Source File: pkg_resources.py    From Flask with Apache License 2.0 5 votes vote down vote up
def _compute_dependencies(self):
        """Recompute this distribution's dependencies."""
        from _markerlib import compile as compile_marker
        dm = self.__dep_map = {None: []}

        reqs = []
        # Including any condition expressions
        for req in self._parsed_pkg_info.get_all('Requires-Dist') or []:
            distvers, mark = self._preparse_requirement(req)
            parsed = next(parse_requirements(distvers))
            parsed.marker_fn = compile_marker(mark)
            reqs.append(parsed)

        def reqs_for_extra(extra):
            for req in reqs:
                if req.marker_fn(override={'extra':extra}):
                    yield req

        common = frozenset(reqs_for_extra(None))
        dm[None].extend(common)

        for extra in self._parsed_pkg_info.get_all('Provides-Extra') or []:
            extra = safe_extra(extra.strip())
            dm[extra] = list(frozenset(reqs_for_extra(extra)) - common)

        return dm 
Example #8
Source File: pkg_resources.py    From Flask with Apache License 2.0 5 votes vote down vote up
def __init__(self, project_name, specs, extras):
        """DO NOT CALL THIS UNDOCUMENTED METHOD; use Requirement.parse()!"""
        self.unsafe_name, project_name = project_name, safe_name(project_name)
        self.project_name, self.key = project_name, project_name.lower()
        index = [(parse_version(v),state_machine[op],op,v) for op,v in specs]
        index.sort()
        self.specs = [(op,ver) for parsed,trans,op,ver in index]
        self.index, self.extras = index, tuple(map(safe_extra,extras))
        self.hashCmp = (
            self.key, tuple([(op,parsed) for parsed,trans,op,ver in index]),
            frozenset(self.extras)
        )
        self.__hash = hash(self.hashCmp) 
Example #9
Source File: pkg_resources.py    From Flask with Apache License 2.0 5 votes vote down vote up
def _compute_dependencies(self):
        """Recompute this distribution's dependencies."""
        from pip._vendor._markerlib import compile as compile_marker
        dm = self.__dep_map = {None: []}

        reqs = []
        # Including any condition expressions
        for req in self._parsed_pkg_info.get_all('Requires-Dist') or []:
            distvers, mark = self._preparse_requirement(req)
            parsed = next(parse_requirements(distvers))
            parsed.marker_fn = compile_marker(mark)
            reqs.append(parsed)

        def reqs_for_extra(extra):
            for req in reqs:
                if req.marker_fn(override={'extra':extra}):
                    yield req

        common = frozenset(reqs_for_extra(None))
        dm[None].extend(common)

        for extra in self._parsed_pkg_info.get_all('Provides-Extra') or []:
            extra = safe_extra(extra.strip())
            dm[extra] = list(frozenset(reqs_for_extra(extra)) - common)

        return dm 
Example #10
Source File: test_sets.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def setUp(self):
        self.set   = Set((1, 2, 3))
        self.other = [Set('ab'), ImmutableSet('cd')]
        self.otherIsIterable = True

#============================================================================== 
Example #11
Source File: test_sets.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_constructor(self):
        inner = Set([1])
        outer = Set([inner])
        element = outer.pop()
        self.assertEqual(type(element), ImmutableSet)
        outer.add(inner)        # Rebuild set of sets with .add method
        outer.remove(inner)
        self.assertEqual(outer, Set())   # Verify that remove worked
        outer.discard(inner)    # Absence of KeyError indicates working fine

#============================================================================== 
Example #12
Source File: pkg_resources.py    From Flask with Apache License 2.0 5 votes vote down vote up
def _compute_dependencies(self):
        """Recompute this distribution's dependencies."""
        from pip._vendor._markerlib import compile as compile_marker
        dm = self.__dep_map = {None: []}

        reqs = []
        # Including any condition expressions
        for req in self._parsed_pkg_info.get_all('Requires-Dist') or []:
            distvers, mark = self._preparse_requirement(req)
            parsed = next(parse_requirements(distvers))
            parsed.marker_fn = compile_marker(mark)
            reqs.append(parsed)

        def reqs_for_extra(extra):
            for req in reqs:
                if req.marker_fn(override={'extra':extra}):
                    yield req

        common = frozenset(reqs_for_extra(None))
        dm[None].extend(common)

        for extra in self._parsed_pkg_info.get_all('Provides-Extra') or []:
            extra = safe_extra(extra.strip())
            dm[extra] = list(frozenset(reqs_for_extra(extra)) - common)

        return dm 
Example #13
Source File: pkg_resources.py    From bazarr with GNU General Public License v3.0 5 votes vote down vote up
def _compute_dependencies(self):
        """Recompute this distribution's dependencies."""
        from _markerlib import compile as compile_marker
        dm = self.__dep_map = {None: []}

        reqs = []
        # Including any condition expressions
        for req in self._parsed_pkg_info.get_all('Requires-Dist') or []:
            distvers, mark = self._preparse_requirement(req)
            parsed = next(parse_requirements(distvers))
            parsed.marker_fn = compile_marker(mark)
            reqs.append(parsed)

        def reqs_for_extra(extra):
            for req in reqs:
                if req.marker_fn(override={'extra':extra}):
                    yield req

        common = frozenset(reqs_for_extra(None))
        dm[None].extend(common)

        for extra in self._parsed_pkg_info.get_all('Provides-Extra') or []:
            extra = safe_extra(extra.strip())
            dm[extra] = list(frozenset(reqs_for_extra(extra)) - common)

        return dm 
Example #14
Source File: pkg_resources.py    From Flask with Apache License 2.0 5 votes vote down vote up
def _compute_dependencies(self):
        """Recompute this distribution's dependencies."""
        from _markerlib import compile as compile_marker
        dm = self.__dep_map = {None: []}

        reqs = []
        # Including any condition expressions
        for req in self._parsed_pkg_info.get_all('Requires-Dist') or []:
            distvers, mark = self._preparse_requirement(req)
            parsed = next(parse_requirements(distvers))
            parsed.marker_fn = compile_marker(mark)
            reqs.append(parsed)

        def reqs_for_extra(extra):
            for req in reqs:
                if req.marker_fn(override={'extra':extra}):
                    yield req

        common = frozenset(reqs_for_extra(None))
        dm[None].extend(common)

        for extra in self._parsed_pkg_info.get_all('Provides-Extra') or []:
            extra = safe_extra(extra.strip())
            dm[extra] = list(frozenset(reqs_for_extra(extra)) - common)

        return dm 
Example #15
Source File: pkg_resources.py    From pledgeservice with Apache License 2.0 5 votes vote down vote up
def _compute_dependencies(self):
        """Recompute this distribution's dependencies."""
        from _markerlib import compile as compile_marker
        dm = self.__dep_map = {None: []}

        reqs = []
        # Including any condition expressions
        for req in self._parsed_pkg_info.get_all('Requires-Dist') or []:
            distvers, mark = self._preparse_requirement(req)
            parsed = next(parse_requirements(distvers))
            parsed.marker_fn = compile_marker(mark)
            reqs.append(parsed)

        def reqs_for_extra(extra):
            for req in reqs:
                if req.marker_fn(override={'extra':extra}):
                    yield req

        common = frozenset(reqs_for_extra(None))
        dm[None].extend(common)

        for extra in self._parsed_pkg_info.get_all('Provides-Extra') or []:
            extra = safe_extra(extra.strip())
            dm[extra] = list(frozenset(reqs_for_extra(extra)) - common)

        return dm 
Example #16
Source File: Obs.py    From jeeves with MIT License 5 votes vote down vote up
def addGroupMember(self, member):
        if member == None:
            return None
        if self.getGroupMembers() == None:
            self.groupMembers = sets.ImmutableSet() #Same as HashSet?
##        if member == self:
##            raise APIException("An obsGroup cannot have itself as a mentor. obsGroup: " + self \
##			        + " obsMember attempting to add: " + member)
            #I think APIException is defined in another JAVA class file; not sure if Python has this
        member.setObsGroup(self)
        self.groupMembers.add(member) 
Example #17
Source File: test_sets.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def setUp(self):
        self.set   = Set((1, 2, 3))
        self.other = [Set('ab'), ImmutableSet('cd')]
        self.otherIsIterable = True

#============================================================================== 
Example #18
Source File: test_sets.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_constructor(self):
        inner = Set([1])
        outer = Set([inner])
        element = outer.pop()
        self.assertEqual(type(element), ImmutableSet)
        outer.add(inner)        # Rebuild set of sets with .add method
        outer.remove(inner)
        self.assertEqual(outer, Set())   # Verify that remove worked
        outer.discard(inner)    # Absence of KeyError indicates working fine

#============================================================================== 
Example #19
Source File: test_case.py    From ConTroll_Remote_Access_Trojan with Apache License 2.0 5 votes vote down vote up
def testAssertSetEqual(self):
        set1 = set()
        set2 = set()
        self.assertSetEqual(set1, set2)

        self.assertRaises(self.failureException, self.assertSetEqual, None, set2)
        self.assertRaises(self.failureException, self.assertSetEqual, [], set2)
        self.assertRaises(self.failureException, self.assertSetEqual, set1, None)
        self.assertRaises(self.failureException, self.assertSetEqual, set1, [])

        set1 = set(['a'])
        set2 = set()
        self.assertRaises(self.failureException, self.assertSetEqual, set1, set2)

        set1 = set(['a'])
        set2 = set(['a'])
        self.assertSetEqual(set1, set2)

        set1 = set(['a'])
        set2 = set(['a', 'b'])
        self.assertRaises(self.failureException, self.assertSetEqual, set1, set2)

        set1 = set(['a'])
        set2 = frozenset(['a', 'b'])
        self.assertRaises(self.failureException, self.assertSetEqual, set1, set2)

        set1 = set(['a', 'b'])
        set2 = frozenset(['a', 'b'])
        self.assertSetEqual(set1, set2)

        set1 = set()
        set2 = "foo"
        self.assertRaises(self.failureException, self.assertSetEqual, set1, set2)
        self.assertRaises(self.failureException, self.assertSetEqual, set2, set1)

        # make sure any string formatting is tuple-safe
        set1 = set([(0, 1), (2, 3)])
        set2 = set([(4, 5)])
        self.assertRaises(self.failureException, self.assertSetEqual, set1, set2) 
Example #20
Source File: test_case.py    From ConTroll_Remote_Access_Trojan with Apache License 2.0 5 votes vote down vote up
def testAssertEqual(self):
        equal_pairs = [
                ((), ()),
                ({}, {}),
                ([], []),
                (set(), set()),
                (frozenset(), frozenset())]
        for a, b in equal_pairs:
            # This mess of try excepts is to test the assertEqual behavior
            # itself.
            try:
                self.assertEqual(a, b)
            except self.failureException:
                self.fail('assertEqual(%r, %r) failed' % (a, b))
            try:
                self.assertEqual(a, b, msg='foo')
            except self.failureException:
                self.fail('assertEqual(%r, %r) with msg= failed' % (a, b))
            try:
                self.assertEqual(a, b, 'foo')
            except self.failureException:
                self.fail('assertEqual(%r, %r) with third parameter failed' %
                          (a, b))

        unequal_pairs = [
               ((), []),
               ({}, set()),
               (set([4,1]), frozenset([4,2])),
               (frozenset([4,5]), set([2,3])),
               (set([3,4]), set([5,4]))]
        for a, b in unequal_pairs:
            self.assertRaises(self.failureException, self.assertEqual, a, b)
            self.assertRaises(self.failureException, self.assertEqual, a, b,
                              'foo')
            self.assertRaises(self.failureException, self.assertEqual, a, b,
                              msg='foo') 
Example #21
Source File: pkg_resources.py    From Flask with Apache License 2.0 5 votes vote down vote up
def __init__(self, project_name, specs, extras):
        """DO NOT CALL THIS UNDOCUMENTED METHOD; use Requirement.parse()!"""
        self.unsafe_name, project_name = project_name, safe_name(project_name)
        self.project_name, self.key = project_name, project_name.lower()
        index = [(parse_version(v),state_machine[op],op,v) for op,v in specs]
        index.sort()
        self.specs = [(op,ver) for parsed,trans,op,ver in index]
        self.index, self.extras = index, tuple(map(safe_extra,extras))
        self.hashCmp = (
            self.key, tuple([(op,parsed) for parsed,trans,op,ver in index]),
            frozenset(self.extras)
        )
        self.__hash = hash(self.hashCmp) 
Example #22
Source File: tokenizer.py    From nzb-subliminal with GNU General Public License v3.0 5 votes vote down vote up
def scriptDataDoubleEscapeStartState(self):
        data = self.stream.char()
        if data in (spaceCharacters | frozenset(("/", ">"))):
            self.tokenQueue.append({"type": tokenTypes["Characters"], "data": data})
            if self.temporaryBuffer.lower() == "script":
                self.state = self.scriptDataDoubleEscapedState
            else:
                self.state = self.scriptDataEscapedState
        elif data in asciiLetters:
            self.tokenQueue.append({"type": tokenTypes["Characters"], "data": data})
            self.temporaryBuffer += data
        else:
            self.stream.unget(data)
            self.state = self.scriptDataEscapedState
        return True 
Example #23
Source File: test_sets.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_constructor(self):
        inner = Set([1])
        outer = Set([inner])
        element = outer.pop()
        self.assertEqual(type(element), ImmutableSet)
        outer.add(inner)        # Rebuild set of sets with .add method
        outer.remove(inner)
        self.assertEqual(outer, Set())   # Verify that remove worked
        outer.discard(inner)    # Absence of KeyError indicates working fine

#============================================================================== 
Example #24
Source File: test_sets.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        self.set   = Set((1, 2, 3))
        self.other = [Set('ab'), ImmutableSet('cd')]
        self.otherIsIterable = True

#============================================================================== 
Example #25
Source File: test_sets.py    From BinderFilter with MIT License 5 votes vote down vote up
def test_constructor(self):
        inner = Set([1])
        outer = Set([inner])
        element = outer.pop()
        self.assertEqual(type(element), ImmutableSet)
        outer.add(inner)        # Rebuild set of sets with .add method
        outer.remove(inner)
        self.assertEqual(outer, Set())   # Verify that remove worked
        outer.discard(inner)    # Absence of KeyError indicates working fine

#============================================================================== 
Example #26
Source File: test_sets.py    From BinderFilter with MIT License 5 votes vote down vote up
def setUp(self):
        self.set   = Set((1, 2, 3))
        self.other = [Set('ab'), ImmutableSet('cd')]
        self.otherIsIterable = True

#============================================================================== 
Example #27
Source File: pkg_resources.py    From oss-ftp with MIT License 5 votes vote down vote up
def _compute_dependencies(self):
        """Recompute this distribution's dependencies."""
        from pip._vendor._markerlib import compile as compile_marker
        dm = self.__dep_map = {None: []}

        reqs = []
        # Including any condition expressions
        for req in self._parsed_pkg_info.get_all('Requires-Dist') or []:
            distvers, mark = self._preparse_requirement(req)
            parsed = next(parse_requirements(distvers))
            parsed.marker_fn = compile_marker(mark)
            reqs.append(parsed)

        def reqs_for_extra(extra):
            for req in reqs:
                if req.marker_fn(override={'extra':extra}):
                    yield req

        common = frozenset(reqs_for_extra(None))
        dm[None].extend(common)

        for extra in self._parsed_pkg_info.get_all('Provides-Extra') or []:
            extra = safe_extra(extra.strip())
            dm[extra] = list(frozenset(reqs_for_extra(extra)) - common)

        return dm 
Example #28
Source File: pkg_resources.py    From oss-ftp with MIT License 5 votes vote down vote up
def __init__(self, project_name, specs, extras):
        """DO NOT CALL THIS UNDOCUMENTED METHOD; use Requirement.parse()!"""
        self.unsafe_name, project_name = project_name, safe_name(project_name)
        self.project_name, self.key = project_name, project_name.lower()
        index = [(parse_version(v),state_machine[op],op,v) for op,v in specs]
        index.sort()
        self.specs = [(op,ver) for parsed,trans,op,ver in index]
        self.index, self.extras = index, tuple(map(safe_extra,extras))
        self.hashCmp = (
            self.key, tuple([(op,parsed) for parsed,trans,op,ver in index]),
            frozenset(self.extras)
        )
        self.__hash = hash(self.hashCmp) 
Example #29
Source File: test_sets.py    From oss-ftp with MIT License 5 votes vote down vote up
def test_constructor(self):
        inner = Set([1])
        outer = Set([inner])
        element = outer.pop()
        self.assertEqual(type(element), ImmutableSet)
        outer.add(inner)        # Rebuild set of sets with .add method
        outer.remove(inner)
        self.assertEqual(outer, Set())   # Verify that remove worked
        outer.discard(inner)    # Absence of KeyError indicates working fine

#============================================================================== 
Example #30
Source File: test_sets.py    From oss-ftp with MIT License 5 votes vote down vote up
def setUp(self):
        self.set   = Set((1, 2, 3))
        self.other = [Set('ab'), ImmutableSet('cd')]
        self.otherIsIterable = True

#==============================================================================