
import requests

from promgen.version import __version__


def post(url, *args, **kwargs):
    '''Wraps requests.post with our user-agent'''
    if 'headers' not in kwargs:
        kwargs['headers'] = {}
    kwargs['headers']['user-agent'] = 'promgen/{}'.format(__version__)

    return requests.post(url, *args, **kwargs)


def get(url, *args, **kwargs):
    '''Wraps requests.post with our user-agent'''
    if 'headers' not in kwargs:
        kwargs['headers'] = {}
    kwargs['headers']['user-agent'] = 'promgen/{}'.format(__version__)

    return requests.get(url, *args, **kwargs)


import requests.sessions

from promgen.version import __version__


def post(url, **kwargs):
    with requests.sessions.Session() as session:
        session.headers['User-Agent'] = 'promgen/{}'.format(__version__)
        return session.post(url, **kwargs)


def get(url, **kwargs):
    with requests.sessions.Session() as session:
        session.headers['User-Agent'] = 'promgen/{}'.format(__version__)
        return session.get(url, **kwargs)

Copy the pattern from requests.api to use a slightly more stable API
Copy the pattern from requests.api to use a slightly more stable API

  
- import requests
+ import requests.sessions
  
  from promgen.version import __version__
  
  
- def post(url, *args, **kwargs):
+ def post(url, **kwargs):
+     with requests.sessions.Session() as session:
-     '''Wraps requests.post with our user-agent'''
-     if 'headers' not in kwargs:
-         kwargs['headers'] = {}
-     kwargs['headers']['user-agent'] = 'promgen/{}'.format(__version__)
+         session.headers['User-Agent'] = 'promgen/{}'.format(__version__)
- 
-     return requests.post(url, *args, **kwargs)
+         return session.post(url, **kwargs)
  
  
- def get(url, *args, **kwargs):
+ def get(url, **kwargs):
+     with requests.sessions.Session() as session:
-     '''Wraps requests.post with our user-agent'''
-     if 'headers' not in kwargs:
-         kwargs['headers'] = {}
-     kwargs['headers']['user-agent'] = 'promgen/{}'.format(__version__)
+         session.headers['User-Agent'] = 'promgen/{}'.format(__version__)
+         return session.get(url, **kwargs)
  
-     return requests.get(url, *args, **kwargs)
- 
Copy the pattern from requests.api to use a slightly more stable API
## Code Before:

import requests

from promgen.version import __version__


def post(url, *args, **kwargs):
    '''Wraps requests.post with our user-agent'''
    if 'headers' not in kwargs:
        kwargs['headers'] = {}
    kwargs['headers']['user-agent'] = 'promgen/{}'.format(__version__)

    return requests.post(url, *args, **kwargs)


def get(url, *args, **kwargs):
    '''Wraps requests.post with our user-agent'''
    if 'headers' not in kwargs:
        kwargs['headers'] = {}
    kwargs['headers']['user-agent'] = 'promgen/{}'.format(__version__)

    return requests.get(url, *args, **kwargs)

## Instruction:
Copy the pattern from requests.api to use a slightly more stable API
## Code After:

import requests.sessions

from promgen.version import __version__


def post(url, **kwargs):
    with requests.sessions.Session() as session:
        session.headers['User-Agent'] = 'promgen/{}'.format(__version__)
        return session.post(url, **kwargs)


def get(url, **kwargs):
    with requests.sessions.Session() as session:
        session.headers['User-Agent'] = 'promgen/{}'.format(__version__)
        return session.get(url, **kwargs)
