old_contents: #!/usr/bin/env python3
  
  __author__ = 'Adaephon'
  
  import socket
  import struct
  import subprocess
  
  msgTypes = [
      'command',
      'get_workspaces',
      'subscribe',
      'get_outputs',
      'get_tree',
      'get_marks',
      'get_bar_config',
      'get_version',
  ]
  msgTypesMap = {msgTypes[i]: i for i in range(len(msgTypes))}
  
  eventTypes = [
      'workspace',
      'output',
      'mode',
      'window',
      'barconfig_update',
  ]
  eventTypesMap = {eventTypes[i]: i for i in range(len(eventTypes))}
  
  
  def get_socketpath():
      sp = subprocess.check_output(['i3', '--get-socketpath']).rstrip()
      return sp
  
  
  class Socket:
      magicString = b'i3-ipc'
      headerPacking = bytes('={}sLL'.format(len(magicString)), 'utf-8')
      headerLen = struct.calcsize(headerPacking)
  
  
      def __init__(self, socketPath):
          self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
          self.socket.settimeout(1)
          self.socket.connect(socketPath)
  
      def _send(self, msgType, msg):
          message = (struct.pack(self.headerPacking, self.magicString,
                                 len(msg), msgType) + msg)
          self.socket.sendall(message)
  
      def _receive(self):
          header = self.socket.recv(self.headerLen)
          _, msgSize, msgType = struct.unpack(self.headerPacking, header)
          data = self.socket.recv(msgSize)
          return msgType, data
  
      def __getattr__(self, attr):
          if attr in msgTypes:
              def func(self, msg):
                  self._send(attr, msg)
                  return self._receive()
              return func
          else:
              raise AttributeError("'{}' object has no attribute '{}'".format(
                  self.__class__.__name__, attr))
  
  
  
new_contents: #!/usr/bin/env python3
  
  __author__ = 'Adaephon'
  
  import socket
  import struct
  import subprocess
  
  msgTypes = [
      'command',
      'get_workspaces',
      'subscribe',
      'get_outputs',
      'get_tree',
      'get_marks',
      'get_bar_config',
      'get_version',
  ]
  msgTypesMap = {msgTypes[i]: i for i in range(len(msgTypes))}
  
  eventTypes = [
      'workspace',
      'output',
      'mode',
      'window',
      'barconfig_update',
  ]
  eventTypesMap = {eventTypes[i]: i for i in range(len(eventTypes))}
  
  
  def get_socketpath():
      sp = subprocess.check_output(['i3', '--get-socketpath']).rstrip()
      return sp
  
  
  class Socket:
      magicString = b'i3-ipc'
      headerPacking = bytes('={}sLL'.format(len(magicString)), 'utf-8')
      headerLen = struct.calcsize(headerPacking)
  
  
      def __init__(self, socketPath):
          self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
          self.socket.settimeout(1)
          self.socket.connect(socketPath)
  
      def _send(self, msgType, msg):
          message = (struct.pack(self.headerPacking, self.magicString,
                                 len(msg), msgType) + msg)
          self.socket.sendall(message)
  
      def _receive(self):
          header = self.socket.recv(self.headerLen)
          _, msgSize, msgType = struct.unpack(self.headerPacking, header)
          data = self.socket.recv(msgSize)
          return msgType, data
  
      def __getattr__(self, attr):
          if attr in msgTypes:
              def func(msg):
                  self._send(msgTypesMap[attr], msg)
                  return self._receive()
              return func
          else:
              raise AttributeError("'{}' object has no attribute '{}'".format(
                  self.__class__.__name__, attr))
  
  
  
subject: fix __getattr__