[PATCH evemu 02/16] python: prefix event map names with underscores

Peter Hutterer peter.hutterer at who-t.net
Mon Aug 11 18:34:36 PDT 2014


Closest thing that python has to "private". These are generated and we reserve
the right to modify the generation in the future, so make sure they're private
by default.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 python/evemu/__init__.py         |  4 ++--
 python/evemu/make-event-names.py | 20 ++++++++++----------
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/python/evemu/__init__.py b/python/evemu/__init__.py
index 1393ca9..c7c30f3 100644
--- a/python/evemu/__init__.py
+++ b/python/evemu/__init__.py
@@ -39,7 +39,7 @@ def event_get_value(event_type, event_code = None):
     If an event code is passed, the event type may be given as integer or
     string.
     """
-    return evemu.event_names.event_get_value(event_type, event_code)
+    return evemu.event_names._event_get_value(event_type, event_code)
 
 def event_get_name(event_type, event_code = None):
     """
@@ -49,7 +49,7 @@ def event_get_name(event_type, event_code = None):
     If an event code is passed, the event type may be given as integer or
     string.
     """
-    return evemu.event_names.event_get_name(event_type, event_code)
+    return evemu.event_names._event_get_name(event_type, event_code)
 
 class InputEvent(object):
     __slots__ = 'sec', 'usec', 'type', 'code', 'value'
diff --git a/python/evemu/make-event-names.py b/python/evemu/make-event-names.py
index e1a4f3d..4938215 100755
--- a/python/evemu/make-event-names.py
+++ b/python/evemu/make-event-names.py
@@ -56,7 +56,7 @@ def print_python_bits(bits, prefix):
 	if  not hasattr(bits, prefix):
 		return
 
-	print("%s_map = {" % (prefix))
+	print("_%s_map = {" % (prefix))
 	for val, name in getattr(bits, prefix).items():
 		if val in oneway:
 			print("	\"%s\" : %d," % (val, name))
@@ -77,14 +77,14 @@ def print_python_bits(bits, prefix):
 	print("")
 
 def print_python_map(bits):
-	print("map = {")
+	print("_map = {")
 
 	for val, name in getattr(bits, "ev").items():
 		name = name[3:]
 		if name == "REP" or name == "PWR"  or name == "FF_STATUS"  or name == "MAX":
 			continue
-		print("	%d : %s_map," % (val, name.lower()))
-		print("	\"EV_%s\" : %s_map," % (name, name.lower()))
+		print("	%d : _%s_map," % (val, name.lower()))
+		print("	\"EV_%s\" : _%s_map," % (name, name.lower()))
 
 	print("}")
 	print("")
@@ -101,33 +101,33 @@ def print_python_mapping_table(bits):
 	print_python_map(bits)
 
 	p("""
-	def event_get_name(event_type, event_code = None):
+	def _event_get_name(event_type, event_code = None):
 		'''
 		Returns the event type or code name.
 		'''
 		if event_code == None:
 			if type(event_type) != int:
 				raise TypeError("expected an int")
-			return ev_map[event_type]
+			return _ev_map[event_type]
 
 		if type(event_code) != int:
 			raise TypeError("expected an int")
 
-		return map[event_type][event_code]
+		return _map[event_type][event_code]
 
-	def event_get_value(event_type, event_code = None):
+	def _event_get_value(event_type, event_code = None):
 		'''
 		Returns the event type or code value.
 		'''
 		if event_code == None:
 			if type(event_type) != str:
 				raise TypeError("expected a string")
-			return ev_map[event_type]
+			return _ev_map[event_type]
 
 		if type(event_code) != str:
 			raise TypeError("expected a string")
 
-		return map[event_type][event_code]
+		return _map[event_type][event_code]
 	""")
 
 def parse_define(bits, line):
-- 
1.9.3



More information about the Input-tools mailing list