erewok / servant-py Goto Github PK
View Code? Open in Web Editor NEWServant client generators for the Python language
License: BSD 3-Clause "New" or "Revised" License
Servant client generators for the Python language
License: BSD 3-Clause "New" or "Revised" License
With the new Async stuff in Python, we should be able to emit client code in servant-py that will utilize httpx
and asyncio. We can add it here as a different generator.
to track releases and such
Default is to call it on all captured args:
https://github.com/pellagic-puffbomb/servant-py/blob/master/src/Servant/PY/Internal.hs#L260
Figure out how not to do that for integers or make sure that are all captures passed are strings.
So, I have been thinking about this library and I think I'd like to make the output functions a little more usable. I had the following ideas:
class SomeRoute:
def __init__(self):
self.url = "some/url/{param1}/etc"
pass
def get(self, param1):
return requests.get(self.url.format(param1=param1))
def post(self, param1, payload):
etc.
import some_url_client
some_url_client.get()
The default way of naming functions creates really long functions, so we need something consistent that also creates an API that's not ultimately painful to use.
I'll experiment and try to see what'll work best.
requests is great for synchronous http
treq is great for asynchronous http
Part of the test suite which is commented out fails now if tweaked slightly to fix a type error:
it "should build urls properly with / separator" $ do
let pyUrl = makePyUrl customOptions (UnTypedPythonRequest req) " "
pyUrl `shouldBe` "\"urlForRequesting:9000/login-with-path-var-and-header/{id}/{Name}/{hungrig}\""
<> withFormattedCaptures " " pathParts
Failures:
test/Servant/PY/InternalSpec.hs:131:7:
1) Servant.PY.Internal.Servant.PY.Internal.Internal, functions that operate on Req objects, should build urls properly with / separator
expected: "\"urlForRequesting:9000/login-with-path-var-and-header/{id}/{Name}/{hungrig}\".format(\n id=parse.quote(str(id)),\n Name=parse.quote(str(Name)),\n hungrig=parse.quote(str(hungrig)))"
but got: "\"urlForRequesting:9000/login-with-path-var-and-header/{id}/{Name}/{hungrig}\".format(\n id=parse.quote(str(id)),\n Name=parse.quote(str(Name)),\n hungrig=parse.quote(str(hungrig)))\""
This library contains a confusingly named withTypes
Python generator options, but we're not using Python3 type annotations, when it seems like we should be.
Add a new style of generating Python output using Python3 type annotations.
once the tests are great.
Docstring now doesn't contain a returns:
section, which would make it a little more official.
Ideally, we'd include more information about the types of things that go into the functions as arguments, including the data payload, etc. That may involve more knowledge about Python than this library currently pretends to.
In addition, we should be able to include some information in the returns
section about the kind of object likely to get returned.
We have a capture in one of our test API endpoints where the variable is named id
. This is created as a function parameter and passed into the client function.
Ideally, we wouldn't overload any Python keywords, such as id
, because it's gross and poor form.
Possibly check for membership in a list of keywords and rename if so.
They are sorely needed.
It should be fun to do.
This library has fallen pretty far behind Servant versions, so we should build against a more recent version and also fix our dependencies to be better defined.
It'll build a dict like this:
test :: [Text] -> Text
test = ["one", "two", "three"]
let result = toPyDict test
result
\"{\"one\":one\"two\":two\"three\":three\"}
We forgot to build a complete structure out of it. Probably pass an offset
parameter to fix this so it nicely indents members of the resulting dict.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.