Skip to content

Commit 511b0e3

Browse files
author
Mike Solomon
committed
Initial commit
0 parents  commit 511b0e3

File tree

8 files changed

+326
-0
lines changed

8 files changed

+326
-0
lines changed

.gitignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/bower_components/
2+
/node_modules/
3+
/.pulp-cache/
4+
/output/
5+
/generated-docs/
6+
/.psc-package/
7+
/.psc*
8+
/.purs*
9+
/.psa*
10+
/.spago
11+
/.venv
12+
/.vscode
13+
14+
purescript_aff
15+
16+
# purescript-python
17+
.pure-py/
18+
19+
# purescript-python
20+
.pure-py/

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# purescript-aff.py
2+
3+
This is an initial implementation of Effect.Aff that copies the JavaScript implementation more or less verbatim.
4+
5+
There is still much to do:
6+
7+
- general bug fixing, as there are some subtle bugs due to copy and paste errors
8+
- making the code more pythonic
9+
- correctly guarding code with threading.Lock
10+
11+
The repo is in _alpha_ development. The code is not fit for anything other than experimental usage. It needs additional development and testing before being able to be incorporated into the official package-set for purescript.python.

packages.dhall

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
{-
2+
Welcome to your new Dhall package-set!
3+
4+
Below are instructions for how to edit this file for most use
5+
cases, so that you don't need to know Dhall to use it.
6+
7+
## Warning: Don't Move This Top-Level Comment!
8+
9+
Due to how `dhall format` currently works, this comment's
10+
instructions cannot appear near corresponding sections below
11+
because `dhall format` will delete the comment. However,
12+
it will not delete a top-level comment like this one.
13+
14+
## Use Cases
15+
16+
Most will want to do one or both of these options:
17+
1. Override/Patch a package's dependency
18+
2. Add a package not already in the default package set
19+
20+
This file will continue to work whether you use one or both options.
21+
Instructions for each option are explained below.
22+
23+
### Overriding/Patching a package
24+
25+
Purpose:
26+
- Change a package's dependency to a newer/older release than the
27+
default package set's release
28+
- Use your own modified version of some dependency that may
29+
include new API, changed API, removed API by
30+
using your custom git repo of the library rather than
31+
the package set's repo
32+
33+
Syntax:
34+
Replace the overrides' "{=}" (an empty record) with the following idea
35+
The "//" or "⫽" means "merge these two records and
36+
when they have the same value, use the one on the right:"
37+
-------------------------------
38+
let overrides =
39+
{ packageName =
40+
upstream.packageName // { updateEntity1 = "new value", updateEntity2 = "new value" }
41+
, packageName =
42+
upstream.packageName // { version = "v4.0.0" }
43+
, packageName =
44+
upstream.packageName // { repo = "https://www.example.com/path/to/new/repo.git" }
45+
}
46+
-------------------------------
47+
48+
Example:
49+
-------------------------------
50+
let overrides =
51+
{ halogen =
52+
upstream.halogen // { version = "master" }
53+
, halogen-vdom =
54+
upstream.halogen-vdom // { version = "v4.0.0" }
55+
}
56+
-------------------------------
57+
58+
### Additions
59+
60+
Purpose:
61+
- Add packages that aren't already included in the default package set
62+
63+
Syntax:
64+
Replace the additions' "{=}" (an empty record) with the following idea:
65+
-------------------------------
66+
let additions =
67+
{ package-name =
68+
{ dependencies =
69+
[ "dependency1"
70+
, "dependency2"
71+
]
72+
, repo =
73+
"https://example.com/path/to/git/repo.git"
74+
, version =
75+
"tag ('v4.0.0') or branch ('master')"
76+
}
77+
, package-name =
78+
{ dependencies =
79+
[ "dependency1"
80+
, "dependency2"
81+
]
82+
, repo =
83+
"https://example.com/path/to/git/repo.git"
84+
, version =
85+
"tag ('v4.0.0') or branch ('master')"
86+
}
87+
, etc.
88+
}
89+
-------------------------------
90+
91+
Example:
92+
-------------------------------
93+
let additions =
94+
{ benchotron =
95+
{ dependencies =
96+
[ "arrays"
97+
, "exists"
98+
, "profunctor"
99+
, "strings"
100+
, "quickcheck"
101+
, "lcg"
102+
, "transformers"
103+
, "foldable-traversable"
104+
, "exceptions"
105+
, "node-fs"
106+
, "node-buffer"
107+
, "node-readline"
108+
, "datetime"
109+
, "now"
110+
]
111+
, repo =
112+
"https://github.com/hdgarrood/purescript-benchotron.git"
113+
, version =
114+
"v7.0.0"
115+
}
116+
}
117+
-------------------------------
118+
-}
119+
120+
121+
let upstream =
122+
https://github.com/purescript/package-sets/releases/download/psc-0.13.8/packages.dhall sha256:0e95ec11604dc8afc1b129c4d405dcc17290ce56d7d0665a0ff15617e32bbf03
123+
124+
let overrides = {=}
125+
126+
let additions = {=}
127+
128+
in upstream // overrides // additions

pure-py.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"corefn-dir": "output",
3+
"data-format": "Compressed",
4+
"entry-module": "Main",
5+
"index-mirror": "affexpr",
6+
"pspy-blueprint": "pspy-blueprint"
7+
}

python-ffi/Affjax.py

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
"""
2+
var platformSpecific = { };
3+
if (typeof module !== "undefined" && module.require && !(typeof process !== "undefined" && process.versions["electron"])) {
4+
// We are on node.js
5+
platformSpecific.newXHR = function () {
6+
var XHR = module.require("xhr2");
7+
return new XHR();
8+
};
9+
10+
platformSpecific.fixupUrl = function (url, xhr) {
11+
if (xhr.nodejsBaseUrl === null) {
12+
var urllib = module.require("url");
13+
var u = urllib.parse(url);
14+
u.protocol = u.protocol || "http:";
15+
u.hostname = u.hostname || "localhost";
16+
return urllib.format(u);
17+
} else {
18+
return url || "/";
19+
}
20+
};
21+
22+
platformSpecific.getResponse = function (xhr) {
23+
return xhr.response;
24+
};
25+
} else {
26+
// We are in the browser
27+
platformSpecific.newXHR = function () {
28+
return new XMLHttpRequest();
29+
};
30+
31+
platformSpecific.fixupUrl = function (url) {
32+
return url || "/";
33+
};
34+
35+
platformSpecific.getResponse = function (xhr) {
36+
return xhr.response;
37+
};
38+
}
39+
"""
40+
import http.client
41+
from urllib.parse import urlparse
42+
from base64 import b64encode
43+
import threading
44+
45+
# todo - is there an analog for withCredentials here?
46+
def _ajax(mkHeader, options):
47+
def _1(errback, callback):
48+
if options["responseType"] in ["arraybuffer", "blob", "document"]:
49+
errback(
50+
Exception(
51+
"Affjax python does not support arraybuffer, blob, or document responses yet"
52+
)
53+
)
54+
return
55+
56+
def _toThreading():
57+
parsedUrl = urlparse(options["url"])
58+
conn = (
59+
http.client.HTTPConnection(parsedUrl.netloc)
60+
if parsedUrl.scheme == "http"
61+
else http.client.HTTPSConnection(parsedUrl.netloc)
62+
)
63+
headers = {}
64+
if options.username and options.password:
65+
userAndPass = b64encode(b"username:password").decode("ascii")
66+
headers["Authorization"] = "Basic %s" % userAndPass
67+
if options["headers"]:
68+
for header in headers:
69+
headers[header["field"]] = header["value"]
70+
try:
71+
conn.request(
72+
options["method"] if options["method"] else "GET",
73+
parsedUrl.path,
74+
body=options["content"],
75+
headers=headers,
76+
)
77+
r1 = conn.getresponse()
78+
callback(
79+
{
80+
"status": r1.status,
81+
"statusText": r1.reason,
82+
"headers": tuple([mkHeader(k)(v) for k, v in r1.getheaders]),
83+
"body": r1.read().decode("utf-8"),
84+
}
85+
)
86+
87+
except Exception as e:
88+
errback(e)
89+
return
90+
91+
t = threading.Thread(target=_toThreading)
92+
t.start()
93+
94+
def _toRet(error, cancelErrback, cancelCallback):
95+
try:
96+
t.cancel()
97+
except Exception as e:
98+
return cancelErrback(e)
99+
return cancelCallback()
100+
101+
return _toRet
102+
103+
return _1

requirements.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
appdirs==1.4.4
2+
astroid==2.4.2
3+
attrs==19.3.0
4+
black==19.10b0
5+
bytecode==0.11.0
6+
certifi==2020.6.20
7+
chardet==3.0.4
8+
click==7.1.2
9+
gitdb==4.0.5
10+
GitPython==3.1.3
11+
idna==2.10
12+
isort==4.3.21
13+
lazy-object-proxy==1.4.3
14+
mccabe==0.6.1
15+
painless-import-extension==0.2.2
16+
pathspec==0.8.0
17+
pspy-executable==0.8.8
18+
purescripto==0.8.8
19+
pylint==2.5.3
20+
pysexpr==0.6
21+
regex==2020.6.8
22+
requests==2.24.0
23+
six==1.15.0
24+
smmap==3.0.4
25+
toml==0.10.1
26+
typed-ast==1.4.1
27+
urllib3==1.25.9
28+
wisepy2==1.1.1
29+
wrapt==1.12.1

spago.dhall

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{-
2+
Welcome to a Spago project!
3+
You can edit this file as you like.
4+
-}
5+
{ name = "purescript-aff"
6+
, dependencies = [ "aff", "console", "effect", "psci-support", "affjax" ]
7+
, packages = ./packages.dhall
8+
, sources = [ "src/**/*.purs"]
9+
, backend = "pspy"
10+
}

src/Main.purs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module Main where
2+
3+
import Prelude
4+
import Affjax as AX
5+
import Affjax.ResponseFormat as ResponseFormat
6+
import Data.Argonaut.Core as J
7+
import Data.Either (Either(..))
8+
import Data.HTTP.Method (Method(..))
9+
import Effect.Aff (launchAff)
10+
import Effect.Class.Console (log)
11+
12+
main =
13+
void $ launchAff
14+
$ do
15+
result <- AX.request (AX.defaultRequest { url = "/api", method = Left GET, responseFormat = ResponseFormat.json })
16+
case result of
17+
Left err -> log $ "GET /api response failed to decode: " <> AX.printError err
18+
Right response -> log $ "GET /api response: " <> J.stringify response.body

0 commit comments

Comments
 (0)