Skip to content

Commit 975f7e8

Browse files
committed
Added get_atom alias that uses the internal cache when safe to do
1 parent 765ca4a commit 975f7e8

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

Xlib/display.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: display.py,v 1.20 2005-11-16 15:50:47 petli Exp $
1+
# $Id: display.py,v 1.21 2007-03-17 22:14:06 mggrant Exp $
22
#
33
# Xlib.display -- high level display object
44
#
@@ -438,10 +438,22 @@ def intern_atom(self, name, only_if_exists = 0):
438438
"""Intern the string name, returning its atom number. If
439439
only_if_exists is true and the atom does not already exist, it
440440
will not be created and X.NONE is returned."""
441-
r = request.InternAtom(display = self.display,
442-
name = name,
443-
only_if_exists = only_if_exists)
444-
return r.atom
441+
r = request.InternAtom(display = self.display,
442+
name = name,
443+
only_if_exists = only_if_exists)
444+
return r.atom
445+
446+
def get_atom(self, atom, only_if_exists = 0):
447+
"""Alias for intern_atom, using internal cache if safe to do"""
448+
if only_if_exists == 0:
449+
# cache lookup will create the atom, as the user wishes
450+
# safe to use the cache
451+
return self.display.get_atom(atom)
452+
else:
453+
# the user doesn't want the atom created if it doesn't
454+
# exist, so use intern_atom to avoid the cache creating it
455+
return self.intern_atom(atom, only_if_exists)
456+
445457

446458
def get_atom_name(self, atom):
447459
"""Look up the name of atom, returning it as a string. Will raise

0 commit comments

Comments
 (0)