Skip to content

Commit

Permalink
Address review comments (EOFError,logging,.__getitem__,camel/kebab)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikappaki committed Dec 17, 2023
1 parent 28b0afe commit aaff114
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
10 changes: 4 additions & 6 deletions src/basilisp/contrib/bencode.lpy
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@

(defn- index-of [s c]
(let [i (.index s c)]
(if (< i 0) (throw (python/Exception "out of input")) i)))
(if (< i 0) (throw (python/EOFError "out of input")) i)))

(defn- slice
([buffer start]
(if (< (len buffer) start)
(throw (python/Exception "out of input"))
(throw (python/EOFError "out of input"))
(.__getitem__ buffer (python/slice start nil))))
([buffer start end]
(if (> end (len buffer))
(throw (python/Exception "out of input"))
(throw (python/EOFError "out of input"))
(.__getitem__ buffer (python/slice start end)))))

(defn- decode-recur [data opts]
Expand Down Expand Up @@ -73,9 +73,7 @@
while incomplete* is the rest of the ``data`` string that could not
be decoded.
``opts`` is a map with the following keys
see ply:fn:`decode`."
``opts`` is a map supporting the same keys as lpy:fn:`decode`."
([data]
(decode-all data {}))
([data opts]
Expand Down
28 changes: 13 additions & 15 deletions src/basilisp/contrib/nrepl_server.lpy
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,26 @@
(:require [basilisp.contrib.bencode :as bc]
[basilisp.string :as str])
(:import [basilisp.__version__ :as ver]
logging
[basilisp.lang.runtime :as rt]
socketserver
sys
traceback
uuid))

(def ^:private log-levels
"A compile time set used to determine which log levels should be
included in the output."
#{:warn})
(def ^:private logger
"The logger for this namespace."
(logging/getLogger (namespace ::)))

;; helper compile time macros to log ``values`` according to the level
;; as filtered by `log-levels`.
(defmacro ^:private debug [& values]
(when (some #{:debug} log-levels)
`(.write sys/stdout (str ~(keyword (str *ns*) "debug") " " (str/join " " [~@values]) \newline))))
(when (.isEnabledFor logger logging/DEBUG)
`(.debug logger (str/join " " [~@values]))))
(defmacro ^:private info [& values]
(when (some #{:info} log-levels)
`(.write sys/stdout (str ~(keyword (str *ns*) "info") " " (str/join " " [~@values]) \newline))))
(when (.isEnabledFor logger logging/INFO)
`(.info logger (str/join " " [~@values]))))
(defmacro ^:private warn [& values]
(when (some #{:warn} log-levels)
`(.write sys/stdout (str ~(keyword (str *ns*) "warn") " " (str/join " " [~@values]) \newline))))
(when (.isEnabledFor logger logging/WARNING))
`(.warning logger (str/join " " [~@values])))
(defmacro ^:private error [& values]
;; we want error to always output to `sys/stderr` unfiltered.
`(.write sys/stderr (str ~(keyword (str *ns*) "error") " " (str/join " " [~@values]) \newline)))
Expand Down Expand Up @@ -75,7 +73,7 @@
(assoc (zipmap ["major" "minor" "incremental"]
version)
"version-string" (str/join "." version)))
"python" (let [version (.__getitem__ (.split sys/version " ") 0)]
"python" (let [version (get (.split sys/version " ") 0)]
(assoc (zipmap ["major" "minor" "incremental"]
(py->lisp (.split version ".")))
"version-string" (py->lisp sys/version)))}
Expand Down Expand Up @@ -103,7 +101,7 @@
message (or (:message data) (str e))]
(swap! client* assoc :*e e)
(send-fn request {"err" (str message)})
(send-fn request {"ex" (traceback/format_exc)
(send-fn request {"ex" (traceback/format-exc)
"status" ["eval-error"]
"ns" ns})))

Expand Down Expand Up @@ -154,7 +152,7 @@
(do-handle-eval request send-fn))

(defn- handle-clone [request send-fn]
(send-fn request {"new-session" (str (uuid/uuid4))
(send-fn request {"new-session" (str (random-uuid))
"status" ["done"]}))

(defn handle-close [request send-fn]
Expand Down

0 comments on commit aaff114

Please sign in to comment.