sys.intern - python examples

Here are the examples of the python api sys.intern taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

53 Examples 7

5 View Complete Implementation : training_data.py
Copyright Apache License 2.0
Author : allenai
    def finalize_chunk(self, x: FilteredData):
        if self.intern:
            question_map = {}
            for q in x.data:
                q.question_id = sys.intern(q.question_id)
                if q.question_id in question_map:
                    q.question = question_map[q.question_id]
                else:
                    q.question = tuple(sys.intern(w) for w in q.question)
                    question_map[q.question_id] = q.question
                q.doc_id = sys.intern(q.doc_id)
                q.context = [sys.intern(w) for w in q.context]

5 View Complete Implementation : training_data.py
Copyright Apache License 2.0
Author : allenai
def intern_mutli_question(questions):
    for q in questions:
        q.question = [sys.intern(x) for x in q.question]
        for para in q.paragraphs:
            para.doc_id = sys.intern(para.doc_id)
            para.text = [sys.intern(x) for x in para.text]

5 View Complete Implementation : test_sys.py
Copyright MIT License
Author : emilyemorehouse
    def test_intern(self):
        global numruns
        numruns += 1
        self.astertRaises(TypeError, sys.intern)
        s = 'never interned before' + str(numruns)
        self.astertTrue(sys.intern(s) is s)
        s2 = s.swapcase().swapcase()
        self.astertTrue(sys.intern(s2) is s)


        clast S(str):

            def __hash__(self):
                return 123
        self.astertRaises(TypeError, sys.intern, S('abc'))

5 View Complete Implementation : cfg.py
Copyright GNU Lesser General Public License v3.0
Author : neg-serg
    def dict_apply(self, field_conv: Callable, subtag_conv: Callable) -> None:
        """ Convert list attributes to set for the better performance.

            Args:
                field_conv (Callable): function to convert dict field.
                subtag_conv (Callable): function to convert subtag inside dict.
        """
        for string in self.cfg.values():
            for key in string:
                if key in self.win_all_props():
                    string[sys.intern(key)] = field_conv(
                        string[sys.intern(key)]
                    )
                elif key == "subtag":
                    subtag_conv(string[sys.intern(key)])

5 View Complete Implementation : matcher.py
Copyright GNU Lesser General Public License v3.0
Author : neg-serg
    def __init__(self):
        self.matched_list = []

        self.match_dict = {
            sys.intern("clast"): lambda: self.win.window_clast in self.matched_list,
            sys.intern("instance"): lambda: self.win.window_instance in self.matched_list,
            sys.intern("role"): lambda: self.win.window_role in self.matched_list,
            sys.intern("clast_r"): self.clast_r,
            sys.intern("instance_r"): self.instance_r,
            sys.intern("role_r"): self.role_r,
            sys.intern("name_r"): self.name_r,
            sys.intern("match_all"): Matcher.match_all
        }

3 View Complete Implementation : Util.py
Copyright Apache License 2.0
Author : Autodesk
def silent_intern(x):
    """
    Perform sys.intern() on the pasted argument and return the result.
    If the input is ineligible (e.g. a unicode string) the original argument is
    returned and no exception is thrown.
    """
    try:
        return sys.intern(x)
    except TypeError:
        return x

3 View Complete Implementation : teacher.py
Copyright Apache License 2.0
Author : deepmipt
    def __init__(self, opt, data_loader=None, cands=None, shared=None, **kwargs):
        # self.data is a list of episodes
        # each episode is a tuple of entries
        # each entry is a tuple of values for the action/observation table
        if shared:
            self.image_loader = shared.get('image_loader', None)
            self.data = shared.get('data', [])
            self.cands = shared.get('cands', None)
        else:
            self.image_loader = ImageLoader(opt)
            self.data = []
            self._load(data_loader, opt['datafile'])
            self.cands = None if cands == None else set(sys.intern(c) for c in cands)
        self.addedCands = []
        self.copied_cands = False

3 View Complete Implementation : test_marshal.py
Copyright MIT License
Author : emilyemorehouse
    def testIntern(self):
        s = marshal.loads(marshal.dumps(self.strobj))
        self.astertEqual(s, self.strobj)
        self.astertEqual(id(s), id(self.strobj))
        s2 = sys.intern(s)
        self.astertEqual(id(s2), id(s))

3 View Complete Implementation : test_marshal.py
Copyright MIT License
Author : emilyemorehouse
    def testNoIntern(self):
        s = marshal.loads(marshal.dumps(self.strobj, 2))
        self.astertEqual(s, self.strobj)
        self.astertNotEqual(id(s), id(self.strobj))
        s2 = sys.intern(s)
        self.astertNotEqual(id(s2), id(s))

3 View Complete Implementation : teachers.py
Copyright Apache License 2.0
Author : ethanjperez
    def __init__(self, opt, data_loader=None, cands=None, shared=None, **kwargs):
        # self.data is a list of episodes
        # each episode is a tuple of entries
        # each entry is a tuple of values for the action/observation table
        if shared:
            self.image_loader = shared.get('image_loader', None)
            self.data = shared.get('data', [])
            self.cands = shared.get('cands', None)
        else:
            self.image_loader = ImageLoader(opt)
            self.data = []
            self._load(data_loader, opt['datafile'])
            self.cands = None if cands is None else set(sys.intern(c) for c in cands)
        self.addedCands = []
        self.copied_cands = False