semvec/pypi-packages huggingface dataset:
safeint 0.0.4
Create an integer within a range.
License: MIT
Keywords: int development security

Safe Int
=======================

Construct integer within a given range to prevent DoS attacks.

Pulling data from the Internet and feeding it to Python's builtin int function exposes you to a potential DoS attack. Python supports arbitrary precision integers. Unlike other languages like C++, Java or even Javascript which will eventually overflow, Python can represent any number you have the memory to store. For instance, in the following code::

    s = '9' * 1000000  # Generate a string with one million 9s
    i = int(s)

Python keeps on going and will stuff 10^1000000 - 1 into i after 7 seconds of CPU work and 400kb of RAM. 7 seconds during which your gevent based web server cannot perform a context switch and service other requests. A single machine running a few hundred greenlets on a cable modem would be enough to cripple a web server with APIs that accepts integers.

safeint.int is a drop-in replacement for int to help parse untrusted data coming from the Internet. You use it like this::

    import safeint


    def my_controller():
        foo = safeint.int(bottle.request.query.foo) 


By default safeint.int will raise a ValueError if your input string is too long.  The default is 10 digits, but you can raise or lower that as your application requires with the keyword parameter digits. So for example, safeint.int(foo, digits=2) limits you to numbers in the range -9 to 99 inclusive.  

safeint.int also supports a few extra parameters and features beyond what int normally supports. If you pass it None or an empty string it returns None, saving you from the hassle of writing code that looks like this:: 

    if bottle.request.query.foo is None:
        foo = None
    else:
        foo = int(bottle.request.query.foo)

Instead you can write this::

    import safeint


    foo = safe.int(bottle.request.query.foo) 

safe.int also has some syntactic sugar to save time when enforcing bounds.   Instead of writing this::

    import safeint


    foo = safeint.int(bottle.request.query.foo)
    if foo > high:
        raise ValueError(...) 
    elif foo < low:
        raise ValueError(...) 


you can just write this::

    import safeint


    foo = safeint.int(bottle.request.query.foo, low=low, high=high)


Development
-----------

Bug reports and pull requests welcome!


Acknowledgments
---------------

Peloton_ for supporting open source!

.. _Peloton: https://www.pelotoncycle.com/

Dan Sokolsky and Adam DePrince for implementing this solution!
scsprox 0.1.0a2
Fast proximal operators from CVXPY problems with CySCS
License: MIT
Keywords: scs cvxpy convex optimization proximal operators ADMM

Converts a CVXPY problem and a dict of CVXPY variables to a fast proximal operator object, which uses CySCS to provide fast evaluation, via one-time matrix stuffing, CySCS factorization caching, and automatic warm-starting of variables.
swaggergenerator 0.0.5
Automatically generate swagger/OAS schemas from example api interactions.
License: MIT

swaggergenerator
=================

Creating swagger/OAS specs for an existing api by hand is tedious and error-prone.
swaggergenerator fixes this by creating schemas from example interactions:

Generation is a three step process.
Here's an example using `httpbin <https://httpbin.org/get>`__:

.. code-block:: python

    import requests
    from swaggergenerator import Generator, get_yaml

    # 1: Create a Generator.
    generator = Generator()

    # 2: Provide one or more examples. They can be for different paths and verbs.
    response = requests.get('https://httpbin.org/get')
    generator.provide_example(response.request, response)

    # 3: Generate a schema (specifically, a Swagger Paths Object).
    print get_yaml(generator.generate_paths())

.. code-block:: yaml

  /get:
    get:
      description: TODO
      parameters: []
      responses:
        '200':
          description: TODO
          schema:
            additionalProperties: false
            properties:
              args:
                additionalProperties: false
                properties: {}
                type: object
              headers:
                additionalProperties: false
                properties:
                  Accept:
                    type: string
                  Accept-Encoding:
                    type: string
                  Connection:
                    type: string
                  Content-Length:
                    type: string
                  Host:
                    type: string
                  User-Agent:
                    type: string
                type: object
              origin:
                type: string
              url:
                type: string
            type: object

You can install it with ``$ pip install swaggergenerator``.


Generation details
---------------------

Generally, the generated schemas err on the side of being too strict.
For example, additionalProperties is always set to False and parameters are always required.
The recommended workflow is to generate schemas, validate them against all interactions in your test suite, and iterate until tests pass.

Here are the swagger features you can expect to be generated:

- path objects for arbitrary verb/path combinations
- all-digit path parameters
- complex path parameters (when given alongside an all-digit example)
- request schemas for 2xx responses
- response schemas for 2xx responses
- references to existing definitions

Here are some swagger features that won't be generated.
If your api uses any of these, you'll need to fix up your output manually:

- nullable/polymorphic types
- heterogeneous arrays
- optional properties
- additionalProperties != False


Contributing
------------

Inside your vitualenv:

.. code-block:: bash

    $ cd swaggergenerator
    $ pip install -e .
    $ pip install -r requirements.txt


To run the tests:

.. code-block:: bash

    $ py.test tests/