proxy.common.backports module#

⚡⚡⚡ Fast, Lightweight, Pluggable, TLS interception capable proxy server focused on Network monitoring, controls & Application development, testing, debugging.

  1. 2013-present by Abhinav Singh and contributors.


BSD, see LICENSE for more details.

class proxy.common.backports.NonBlockingQueue[source]#

Bases: object

Simple, unbounded, non-blocking FIFO queue.

Supports only a single consumer.

NOTE: This is available in Python since 3.7 as SimpleQueue. Here because still supports 3.6

empty() bool[source]#

Return True if the queue is empty, False otherwise (not reliable!).

get() Any[source]#

Remove and return an item from the queue.

put(item: Any) None[source]#

Put the item on the queue.

qsize() int[source]#

Return the approximate size of the queue (not reliable!).

class proxy.common.backports.cached_property(ttl: float = 0)[source]#

Bases: object

Decorator for read-only properties evaluated only once within TTL period. It can be used to create a cached property like this:

import random

# the class containing the property must be a new-style class
class MyClass:
    # create property whose value is cached for ten minutes
    def randint(self):
        # will only be evaluated every 10 min. at maximum.
        return random.randint(0, 100)

The value is cached in the ‘_cached_properties’ attribute of the object instance that has the property getter method wrapped by this decorator. The ‘_cached_properties’ attribute value is a dictionary which has a key for every property of the object which is wrapped by this decorator. Each entry in the cache is created only when the property is accessed for the first time and is a two-element tuple with the last computed property value and the last time it was updated in seconds since the epoch.

The default time-to-live (TTL) is 0 seconds i.e. cached value will never expire.

To expire a cached property value manually just do::

del instance._cached_properties[<property name>]

Adopted from © 2011 Christopher Arndt, MIT License.

NOTE: We need this function only because Python in-built are only available for 3.8+. Hence, we must get rid of this function once no longer support version older than 3.8.