 "))
 
 (defconst ej-push-py (concat ej-header-py "
-file = sys.argv[1]
-
 m = hashlib.sha1()
 body = sys.stdin.read()
 m.update(body)
 
 request = {
-    'Hash': base64.b64encode(m.digest()),
-    'Data': body
+    'Key': file,
+    'Updated': {
+        'Hash': base64.b64encode(m.digest()),
+        'Data': body
+    }
 }
 
-requests.post(SERVER+\"/push\", data=json.dumps(request))
+print \"Push Response:\", requests.post(SERVER+\"/push\", data=json.dumps(request)).text
 "))
 
 (defvar ej-timer nil)

(defvar ej-locked-buffers nil)
(defvar ej-active-buffers nil)

(defun ej-invoke-py (code)
  "Invoke the given CODE in the python interpreter."
  (start-process "python" "*ej-log*" "python" "-c" code (buffer-file-name)))

(defun ej-mode-after-save ()
  "Unlock the file, and send the current contents to the server."
  (let ((proc (ej-invoke-py ej-unlock-py)))
    (process-send-region proc (point-min) (point-max))
    (process-send-eof proc)
    (setq ej-locked-buffers (remove (current-buffer) ej-locked-buffers))))

(defun ej-sync ()
  "Ej Sync."
  ; Deal with any changed buffers
  (dolist (buff ej-changed-list)
    (add-to-list 'ej-locked-buffers buff)
    (with-current-buffer buff
      (let ((proc (ej-invoke-py ej-push-py)))
        (process-send-region proc (point-min) (point-max))
        (process-send-eof proc))))

  ; Sync other buffers
  (dolist (buff ej-active-buffers)
    (unless (member buff ej-locked-buffers)
      (with-current-buffer buff
        (let ((proc (start-process "python" (concat "*" (buffer-name buff) "-swap*") "python"
                                   "-c" ej-watch-py
                                   (buffer-file-name))))
          (process-send-region proc (point-min) (point-max))
          (process-send-eof proc)
          (when (accept-process-output proc 0.5)
            (save-excursion
              (erase-buffer)
              (with-current-buffer (concat "*" (buffer-name buff) "-swap*")
                (goto-char (point-min))
                (if (looking-at "RO\n") ; Read only!
                    (progn (append-to-buffer buff (+ 3 (point-min)) (point-max))
                           (unless buffer-read-only (read-only-mode)))
                  (progn (when buffer-read-only (read-only-mode)))))))))))

  (setq ej-changed-list nil))


import sys

SERVER = \"http://localhost:8000\"
file = sys.argv[1]
")

(defconst ej-unlock-py (concat ej-header-py "
request = {
    'Key': file
}

# Make a request to the unlock server, sending the key to unlock
print \"Unlock Response:\", requests.post(SERVER+\"/unlock\", data=json.dumps(request)).text
"))

(defconst ej-watch-py (concat ej-header-py "
# Compute the hash
m = hashlib.sha1()
body = sys.stdin.read()
m.update(body)
hash = base64.b64encode(m.digest())

request = {
    'Key': file,
    'Target': { 'Hash': hash }
}

res = json.loads(requests.post(SERVER+\"/watch\", data=json.dumps(request)).text)
if res['Locked']:
