Instruction stringlengths 362 7.83k | output_code stringlengths 1 945 |
|---|---|
Predict the next line for this snippet: <|code_start|> response = self._request_get("channel")
return Channel.construct_from(response)
def get_by_id(self, channel_id):
response = self._request_get("channels/{}".format(channel_id))
return Channel.construct_from(response)
@oauth_required
def update(
self, channel_id, status=None, game=None, delay=None, channel_feed_enabled=None
):
data = {}
if status is not None:
data["status"] = status
if game is not None:
data["game"] = game
if delay is not None:
data["delay"] = delay
if channel_feed_enabled is not None:
data["channel_feed_enabled"] = channel_feed_enabled
post_data = {"channel": data}
response = self._request_put("channels/{}".format(channel_id), post_data)
return Channel.construct_from(response)
@oauth_required
def get_editors(self, channel_id):
response = self._request_get("channels/{}/editors".format(channel_id))
return [User.construct_from(x) for x in response["users"]]
<|code_end|>
with the help of current file imports:
from twitch.api.base import TwitchAPI
from twitch.constants import (
BROADCAST_TYPE_HIGHLIGHT,
BROADCAST_TYPES,
DIRECTION_ASC,
DIRECTION_DESC,
DIRECTIONS,
VIDEO_SORT_TIME,
VIDEO_SORTS,
)
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Channel, Community, Follow, Subscription, Team, User, Video
and context from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/constants.py
# BROADCAST_TYPE_HIGHLIGHT = "highlight"
#
# BROADCAST_TYPES = [
# BROADCAST_TYPE_ARCHIVE,
# BROADCAST_TYPE_HIGHLIGHT,
# BROADCAST_TYPE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_HIGHLIGHT,
# BROADCAST_TYPE_HIGHLIGHT_UPLOAD,
# BROADCAST_TYPE_ALL,
# ]
#
# DIRECTION_ASC = "asc"
#
# DIRECTION_DESC = "desc"
#
# DIRECTIONS = [DIRECTION_ASC, DIRECTION_DESC]
#
# VIDEO_SORT_TIME = "time"
#
# VIDEO_SORTS = [VIDEO_SORT_TIME, VIDEO_SORT_TRENDING, VIDEO_SORT_VIEWS]
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Community(TwitchObject):
# pass
#
# class Follow(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class Team(TwitchObject):
# pass
#
# class User(TwitchObject):
# pass
#
# class Video(TwitchObject):
# pass
, which may contain function names, class names, or code. Output only the next line. | def get_followers( |
Predict the next line for this snippet: <|code_start|> "channels/{}/subscriptions/{}".format(channel_id, user_id)
)
return Subscription.construct_from(response)
def get_videos(
self,
channel_id,
limit=10,
offset=0,
broadcast_type=BROADCAST_TYPE_HIGHLIGHT,
language=None,
sort=VIDEO_SORT_TIME,
):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
)
if broadcast_type not in BROADCAST_TYPES:
raise TwitchAttributeException(
"Broadcast type is not valid. Valid values are {}".format(
BROADCAST_TYPES
)
)
if sort not in VIDEO_SORTS:
raise TwitchAttributeException(
"Sort is not valid. Valid values are {}".format(VIDEO_SORTS)
)
<|code_end|>
with the help of current file imports:
from twitch.api.base import TwitchAPI
from twitch.constants import (
BROADCAST_TYPE_HIGHLIGHT,
BROADCAST_TYPES,
DIRECTION_ASC,
DIRECTION_DESC,
DIRECTIONS,
VIDEO_SORT_TIME,
VIDEO_SORTS,
)
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Channel, Community, Follow, Subscription, Team, User, Video
and context from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/constants.py
# BROADCAST_TYPE_HIGHLIGHT = "highlight"
#
# BROADCAST_TYPES = [
# BROADCAST_TYPE_ARCHIVE,
# BROADCAST_TYPE_HIGHLIGHT,
# BROADCAST_TYPE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_HIGHLIGHT,
# BROADCAST_TYPE_HIGHLIGHT_UPLOAD,
# BROADCAST_TYPE_ALL,
# ]
#
# DIRECTION_ASC = "asc"
#
# DIRECTION_DESC = "desc"
#
# DIRECTIONS = [DIRECTION_ASC, DIRECTION_DESC]
#
# VIDEO_SORT_TIME = "time"
#
# VIDEO_SORTS = [VIDEO_SORT_TIME, VIDEO_SORT_TRENDING, VIDEO_SORT_VIEWS]
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Community(TwitchObject):
# pass
#
# class Follow(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class Team(TwitchObject):
# pass
#
# class User(TwitchObject):
# pass
#
# class Video(TwitchObject):
# pass
, which may contain function names, class names, or code. Output only the next line. | params = { |
Given snippet: <|code_start|>
@oauth_required
def get_subscribers(self, channel_id, limit=25, offset=0, direction=DIRECTION_ASC):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
)
if direction not in DIRECTIONS:
raise TwitchAttributeException(
"Direction is not valid. Valid values are {}".format(DIRECTIONS)
)
params = {"limit": limit, "offset": offset, "direction": direction}
response = self._request_get(
"channels/{}/subscriptions".format(channel_id), params=params
)
return [Subscription.construct_from(x) for x in response["subscriptions"]]
def check_subscription_by_user(self, channel_id, user_id):
response = self._request_get(
"channels/{}/subscriptions/{}".format(channel_id, user_id)
)
return Subscription.construct_from(response)
def get_videos(
self,
channel_id,
limit=10,
offset=0,
broadcast_type=BROADCAST_TYPE_HIGHLIGHT,
<|code_end|>
, continue by predicting the next line. Consider current file imports:
from twitch.api.base import TwitchAPI
from twitch.constants import (
BROADCAST_TYPE_HIGHLIGHT,
BROADCAST_TYPES,
DIRECTION_ASC,
DIRECTION_DESC,
DIRECTIONS,
VIDEO_SORT_TIME,
VIDEO_SORTS,
)
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Channel, Community, Follow, Subscription, Team, User, Video
and context:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/constants.py
# BROADCAST_TYPE_HIGHLIGHT = "highlight"
#
# BROADCAST_TYPES = [
# BROADCAST_TYPE_ARCHIVE,
# BROADCAST_TYPE_HIGHLIGHT,
# BROADCAST_TYPE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_HIGHLIGHT,
# BROADCAST_TYPE_HIGHLIGHT_UPLOAD,
# BROADCAST_TYPE_ALL,
# ]
#
# DIRECTION_ASC = "asc"
#
# DIRECTION_DESC = "desc"
#
# DIRECTIONS = [DIRECTION_ASC, DIRECTION_DESC]
#
# VIDEO_SORT_TIME = "time"
#
# VIDEO_SORTS = [VIDEO_SORT_TIME, VIDEO_SORT_TRENDING, VIDEO_SORT_VIEWS]
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Community(TwitchObject):
# pass
#
# class Follow(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class Team(TwitchObject):
# pass
#
# class User(TwitchObject):
# pass
#
# class Video(TwitchObject):
# pass
which might include code, classes, or functions. Output only the next line. | language=None, |
Predict the next line after this snippet: <|code_start|> "Sort is not valid. Valid values are {}".format(VIDEO_SORTS)
)
params = {
"limit": limit,
"offset": offset,
"broadcast_type": broadcast_type,
"sort": sort,
}
if language is not None:
params["language"] = language
response = self._request_get(
"channels/{}/videos".format(channel_id), params=params
)
return [Video.construct_from(x) for x in response["videos"]]
@oauth_required
def start_commercial(self, channel_id, duration=30):
data = {"duration": duration}
response = self._request_post(
"channels/{}/commercial".format(channel_id), data=data
)
return response
@oauth_required
def reset_stream_key(self, channel_id):
response = self._request_delete("channels/{}/stream_key".format(channel_id))
return Channel.construct_from(response)
def get_community(self, channel_id):
<|code_end|>
using the current file's imports:
from twitch.api.base import TwitchAPI
from twitch.constants import (
BROADCAST_TYPE_HIGHLIGHT,
BROADCAST_TYPES,
DIRECTION_ASC,
DIRECTION_DESC,
DIRECTIONS,
VIDEO_SORT_TIME,
VIDEO_SORTS,
)
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Channel, Community, Follow, Subscription, Team, User, Video
and any relevant context from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/constants.py
# BROADCAST_TYPE_HIGHLIGHT = "highlight"
#
# BROADCAST_TYPES = [
# BROADCAST_TYPE_ARCHIVE,
# BROADCAST_TYPE_HIGHLIGHT,
# BROADCAST_TYPE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_HIGHLIGHT,
# BROADCAST_TYPE_HIGHLIGHT_UPLOAD,
# BROADCAST_TYPE_ALL,
# ]
#
# DIRECTION_ASC = "asc"
#
# DIRECTION_DESC = "desc"
#
# DIRECTIONS = [DIRECTION_ASC, DIRECTION_DESC]
#
# VIDEO_SORT_TIME = "time"
#
# VIDEO_SORTS = [VIDEO_SORT_TIME, VIDEO_SORT_TRENDING, VIDEO_SORT_VIEWS]
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Community(TwitchObject):
# pass
#
# class Follow(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class Team(TwitchObject):
# pass
#
# class User(TwitchObject):
# pass
#
# class Video(TwitchObject):
# pass
. Output only the next line. | response = self._request_get("channels/{}/community".format(channel_id)) |
Given snippet: <|code_start|> return [User.construct_from(x) for x in response["users"]]
def get_followers(
self, channel_id, limit=25, offset=0, cursor=None, direction=DIRECTION_DESC
):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
)
if direction not in DIRECTIONS:
raise TwitchAttributeException(
"Direction is not valid. Valid values are {}".format(DIRECTIONS)
)
params = {"limit": limit, "offset": offset, "direction": direction}
if cursor is not None:
params["cursor"] = cursor
response = self._request_get(
"channels/{}/follows".format(channel_id), params=params
)
return [Follow.construct_from(x) for x in response["follows"]]
def get_teams(self, channel_id):
response = self._request_get("channels/{}/teams".format(channel_id))
return [Team.construct_from(x) for x in response["teams"]]
@oauth_required
def get_subscribers(self, channel_id, limit=25, offset=0, direction=DIRECTION_ASC):
if limit > 100:
raise TwitchAttributeException(
<|code_end|>
, continue by predicting the next line. Consider current file imports:
from twitch.api.base import TwitchAPI
from twitch.constants import (
BROADCAST_TYPE_HIGHLIGHT,
BROADCAST_TYPES,
DIRECTION_ASC,
DIRECTION_DESC,
DIRECTIONS,
VIDEO_SORT_TIME,
VIDEO_SORTS,
)
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Channel, Community, Follow, Subscription, Team, User, Video
and context:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/constants.py
# BROADCAST_TYPE_HIGHLIGHT = "highlight"
#
# BROADCAST_TYPES = [
# BROADCAST_TYPE_ARCHIVE,
# BROADCAST_TYPE_HIGHLIGHT,
# BROADCAST_TYPE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_HIGHLIGHT,
# BROADCAST_TYPE_HIGHLIGHT_UPLOAD,
# BROADCAST_TYPE_ALL,
# ]
#
# DIRECTION_ASC = "asc"
#
# DIRECTION_DESC = "desc"
#
# DIRECTIONS = [DIRECTION_ASC, DIRECTION_DESC]
#
# VIDEO_SORT_TIME = "time"
#
# VIDEO_SORTS = [VIDEO_SORT_TIME, VIDEO_SORT_TRENDING, VIDEO_SORT_VIEWS]
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Community(TwitchObject):
# pass
#
# class Follow(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class Team(TwitchObject):
# pass
#
# class User(TwitchObject):
# pass
#
# class Video(TwitchObject):
# pass
which might include code, classes, or functions. Output only the next line. | "Maximum number of objects returned in one request is 100" |
Based on the snippet: <|code_start|> )
if broadcast_type not in BROADCAST_TYPES:
raise TwitchAttributeException(
"Broadcast type is not valid. Valid values are {}".format(
BROADCAST_TYPES
)
)
if sort not in VIDEO_SORTS:
raise TwitchAttributeException(
"Sort is not valid. Valid values are {}".format(VIDEO_SORTS)
)
params = {
"limit": limit,
"offset": offset,
"broadcast_type": broadcast_type,
"sort": sort,
}
if language is not None:
params["language"] = language
response = self._request_get(
"channels/{}/videos".format(channel_id), params=params
)
return [Video.construct_from(x) for x in response["videos"]]
@oauth_required
def start_commercial(self, channel_id, duration=30):
data = {"duration": duration}
<|code_end|>
, predict the immediate next line with the help of imports:
from twitch.api.base import TwitchAPI
from twitch.constants import (
BROADCAST_TYPE_HIGHLIGHT,
BROADCAST_TYPES,
DIRECTION_ASC,
DIRECTION_DESC,
DIRECTIONS,
VIDEO_SORT_TIME,
VIDEO_SORTS,
)
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Channel, Community, Follow, Subscription, Team, User, Video
and context (classes, functions, sometimes code) from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/constants.py
# BROADCAST_TYPE_HIGHLIGHT = "highlight"
#
# BROADCAST_TYPES = [
# BROADCAST_TYPE_ARCHIVE,
# BROADCAST_TYPE_HIGHLIGHT,
# BROADCAST_TYPE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_HIGHLIGHT,
# BROADCAST_TYPE_HIGHLIGHT_UPLOAD,
# BROADCAST_TYPE_ALL,
# ]
#
# DIRECTION_ASC = "asc"
#
# DIRECTION_DESC = "desc"
#
# DIRECTIONS = [DIRECTION_ASC, DIRECTION_DESC]
#
# VIDEO_SORT_TIME = "time"
#
# VIDEO_SORTS = [VIDEO_SORT_TIME, VIDEO_SORT_TRENDING, VIDEO_SORT_VIEWS]
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Community(TwitchObject):
# pass
#
# class Follow(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class Team(TwitchObject):
# pass
#
# class User(TwitchObject):
# pass
#
# class Video(TwitchObject):
# pass
. Output only the next line. | response = self._request_post( |
Given snippet: <|code_start|>
class Channels(TwitchAPI):
@oauth_required
def get(self):
response = self._request_get("channel")
return Channel.construct_from(response)
def get_by_id(self, channel_id):
response = self._request_get("channels/{}".format(channel_id))
return Channel.construct_from(response)
@oauth_required
def update(
self, channel_id, status=None, game=None, delay=None, channel_feed_enabled=None
):
data = {}
if status is not None:
data["status"] = status
if game is not None:
<|code_end|>
, continue by predicting the next line. Consider current file imports:
from twitch.api.base import TwitchAPI
from twitch.constants import (
BROADCAST_TYPE_HIGHLIGHT,
BROADCAST_TYPES,
DIRECTION_ASC,
DIRECTION_DESC,
DIRECTIONS,
VIDEO_SORT_TIME,
VIDEO_SORTS,
)
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Channel, Community, Follow, Subscription, Team, User, Video
and context:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/constants.py
# BROADCAST_TYPE_HIGHLIGHT = "highlight"
#
# BROADCAST_TYPES = [
# BROADCAST_TYPE_ARCHIVE,
# BROADCAST_TYPE_HIGHLIGHT,
# BROADCAST_TYPE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_HIGHLIGHT,
# BROADCAST_TYPE_HIGHLIGHT_UPLOAD,
# BROADCAST_TYPE_ALL,
# ]
#
# DIRECTION_ASC = "asc"
#
# DIRECTION_DESC = "desc"
#
# DIRECTIONS = [DIRECTION_ASC, DIRECTION_DESC]
#
# VIDEO_SORT_TIME = "time"
#
# VIDEO_SORTS = [VIDEO_SORT_TIME, VIDEO_SORT_TRENDING, VIDEO_SORT_VIEWS]
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Community(TwitchObject):
# pass
#
# class Follow(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class Team(TwitchObject):
# pass
#
# class User(TwitchObject):
# pass
#
# class Video(TwitchObject):
# pass
which might include code, classes, or functions. Output only the next line. | data["game"] = game |
Continue the code snippet: <|code_start|> return Subscription.construct_from(response)
def get_videos(
self,
channel_id,
limit=10,
offset=0,
broadcast_type=BROADCAST_TYPE_HIGHLIGHT,
language=None,
sort=VIDEO_SORT_TIME,
):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
)
if broadcast_type not in BROADCAST_TYPES:
raise TwitchAttributeException(
"Broadcast type is not valid. Valid values are {}".format(
BROADCAST_TYPES
)
)
if sort not in VIDEO_SORTS:
raise TwitchAttributeException(
"Sort is not valid. Valid values are {}".format(VIDEO_SORTS)
)
params = {
"limit": limit,
<|code_end|>
. Use current file imports:
from twitch.api.base import TwitchAPI
from twitch.constants import (
BROADCAST_TYPE_HIGHLIGHT,
BROADCAST_TYPES,
DIRECTION_ASC,
DIRECTION_DESC,
DIRECTIONS,
VIDEO_SORT_TIME,
VIDEO_SORTS,
)
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Channel, Community, Follow, Subscription, Team, User, Video
and context (classes, functions, or code) from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/constants.py
# BROADCAST_TYPE_HIGHLIGHT = "highlight"
#
# BROADCAST_TYPES = [
# BROADCAST_TYPE_ARCHIVE,
# BROADCAST_TYPE_HIGHLIGHT,
# BROADCAST_TYPE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_HIGHLIGHT,
# BROADCAST_TYPE_HIGHLIGHT_UPLOAD,
# BROADCAST_TYPE_ALL,
# ]
#
# DIRECTION_ASC = "asc"
#
# DIRECTION_DESC = "desc"
#
# DIRECTIONS = [DIRECTION_ASC, DIRECTION_DESC]
#
# VIDEO_SORT_TIME = "time"
#
# VIDEO_SORTS = [VIDEO_SORT_TIME, VIDEO_SORT_TRENDING, VIDEO_SORT_VIEWS]
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Community(TwitchObject):
# pass
#
# class Follow(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class Team(TwitchObject):
# pass
#
# class User(TwitchObject):
# pass
#
# class Video(TwitchObject):
# pass
. Output only the next line. | "offset": offset, |
Given snippet: <|code_start|> raise TwitchAttributeException(
"Broadcast type is not valid. Valid values are {}".format(
BROADCAST_TYPES
)
)
if sort not in VIDEO_SORTS:
raise TwitchAttributeException(
"Sort is not valid. Valid values are {}".format(VIDEO_SORTS)
)
params = {
"limit": limit,
"offset": offset,
"broadcast_type": broadcast_type,
"sort": sort,
}
if language is not None:
params["language"] = language
response = self._request_get(
"channels/{}/videos".format(channel_id), params=params
)
return [Video.construct_from(x) for x in response["videos"]]
@oauth_required
def start_commercial(self, channel_id, duration=30):
data = {"duration": duration}
response = self._request_post(
"channels/{}/commercial".format(channel_id), data=data
)
<|code_end|>
, continue by predicting the next line. Consider current file imports:
from twitch.api.base import TwitchAPI
from twitch.constants import (
BROADCAST_TYPE_HIGHLIGHT,
BROADCAST_TYPES,
DIRECTION_ASC,
DIRECTION_DESC,
DIRECTIONS,
VIDEO_SORT_TIME,
VIDEO_SORTS,
)
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Channel, Community, Follow, Subscription, Team, User, Video
and context:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/constants.py
# BROADCAST_TYPE_HIGHLIGHT = "highlight"
#
# BROADCAST_TYPES = [
# BROADCAST_TYPE_ARCHIVE,
# BROADCAST_TYPE_HIGHLIGHT,
# BROADCAST_TYPE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_HIGHLIGHT,
# BROADCAST_TYPE_HIGHLIGHT_UPLOAD,
# BROADCAST_TYPE_ALL,
# ]
#
# DIRECTION_ASC = "asc"
#
# DIRECTION_DESC = "desc"
#
# DIRECTIONS = [DIRECTION_ASC, DIRECTION_DESC]
#
# VIDEO_SORT_TIME = "time"
#
# VIDEO_SORTS = [VIDEO_SORT_TIME, VIDEO_SORT_TRENDING, VIDEO_SORT_VIEWS]
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Community(TwitchObject):
# pass
#
# class Follow(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class Team(TwitchObject):
# pass
#
# class User(TwitchObject):
# pass
#
# class Video(TwitchObject):
# pass
which might include code, classes, or functions. Output only the next line. | return response |
Given the following code snippet before the placeholder: <|code_start|>
class Channels(TwitchAPI):
@oauth_required
def get(self):
response = self._request_get("channel")
return Channel.construct_from(response)
def get_by_id(self, channel_id):
response = self._request_get("channels/{}".format(channel_id))
return Channel.construct_from(response)
@oauth_required
def update(
self, channel_id, status=None, game=None, delay=None, channel_feed_enabled=None
):
data = {}
if status is not None:
data["status"] = status
if game is not None:
data["game"] = game
if delay is not None:
data["delay"] = delay
if channel_feed_enabled is not None:
<|code_end|>
, predict the next line using imports from the current file:
from twitch.api.base import TwitchAPI
from twitch.constants import (
BROADCAST_TYPE_HIGHLIGHT,
BROADCAST_TYPES,
DIRECTION_ASC,
DIRECTION_DESC,
DIRECTIONS,
VIDEO_SORT_TIME,
VIDEO_SORTS,
)
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Channel, Community, Follow, Subscription, Team, User, Video
and context including class names, function names, and sometimes code from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/constants.py
# BROADCAST_TYPE_HIGHLIGHT = "highlight"
#
# BROADCAST_TYPES = [
# BROADCAST_TYPE_ARCHIVE,
# BROADCAST_TYPE_HIGHLIGHT,
# BROADCAST_TYPE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_HIGHLIGHT,
# BROADCAST_TYPE_HIGHLIGHT_UPLOAD,
# BROADCAST_TYPE_ALL,
# ]
#
# DIRECTION_ASC = "asc"
#
# DIRECTION_DESC = "desc"
#
# DIRECTIONS = [DIRECTION_ASC, DIRECTION_DESC]
#
# VIDEO_SORT_TIME = "time"
#
# VIDEO_SORTS = [VIDEO_SORT_TIME, VIDEO_SORT_TRENDING, VIDEO_SORT_VIEWS]
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Community(TwitchObject):
# pass
#
# class Follow(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class Team(TwitchObject):
# pass
#
# class User(TwitchObject):
# pass
#
# class Video(TwitchObject):
# pass
. Output only the next line. | data["channel_feed_enabled"] = channel_feed_enabled |
Given snippet: <|code_start|>
def get_videos(
self,
channel_id,
limit=10,
offset=0,
broadcast_type=BROADCAST_TYPE_HIGHLIGHT,
language=None,
sort=VIDEO_SORT_TIME,
):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
)
if broadcast_type not in BROADCAST_TYPES:
raise TwitchAttributeException(
"Broadcast type is not valid. Valid values are {}".format(
BROADCAST_TYPES
)
)
if sort not in VIDEO_SORTS:
raise TwitchAttributeException(
"Sort is not valid. Valid values are {}".format(VIDEO_SORTS)
)
params = {
"limit": limit,
"offset": offset,
<|code_end|>
, continue by predicting the next line. Consider current file imports:
from twitch.api.base import TwitchAPI
from twitch.constants import (
BROADCAST_TYPE_HIGHLIGHT,
BROADCAST_TYPES,
DIRECTION_ASC,
DIRECTION_DESC,
DIRECTIONS,
VIDEO_SORT_TIME,
VIDEO_SORTS,
)
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Channel, Community, Follow, Subscription, Team, User, Video
and context:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/constants.py
# BROADCAST_TYPE_HIGHLIGHT = "highlight"
#
# BROADCAST_TYPES = [
# BROADCAST_TYPE_ARCHIVE,
# BROADCAST_TYPE_HIGHLIGHT,
# BROADCAST_TYPE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_HIGHLIGHT,
# BROADCAST_TYPE_HIGHLIGHT_UPLOAD,
# BROADCAST_TYPE_ALL,
# ]
#
# DIRECTION_ASC = "asc"
#
# DIRECTION_DESC = "desc"
#
# DIRECTIONS = [DIRECTION_ASC, DIRECTION_DESC]
#
# VIDEO_SORT_TIME = "time"
#
# VIDEO_SORTS = [VIDEO_SORT_TIME, VIDEO_SORT_TRENDING, VIDEO_SORT_VIEWS]
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Community(TwitchObject):
# pass
#
# class Follow(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class Team(TwitchObject):
# pass
#
# class User(TwitchObject):
# pass
#
# class Video(TwitchObject):
# pass
which might include code, classes, or functions. Output only the next line. | "broadcast_type": broadcast_type, |
Using the snippet: <|code_start|> client = TwitchClient("client id")
videos = client.videos.get_top()
assert len(responses.calls) == 1
assert len(videos) == 1
assert isinstance(videos[0], Video)
video = videos[0]
assert isinstance(video, Video)
assert video.id == example_video_response["_id"]
assert video.description == example_video_response["description"]
assert video.fps["1080p"] == example_video_response["fps"]["1080p"]
@responses.activate
@pytest.mark.parametrize(
"param,value", [("limit", 101), ("period", "abcd"), ("broadcast_type", "abcd")]
)
def test_get_top_raises_if_wrong_params_are_passed_in(param, value):
client = TwitchClient("client id")
kwargs = {param: value}
with pytest.raises(TwitchAttributeException):
client.videos.get_top(**kwargs)
@responses.activate
def test_get_followed_videos():
responses.add(
responses.GET,
"{}videos/followed".format(BASE_URL),
<|code_end|>
, determine the next line of code. You have imports:
import json
import pytest
import responses
from twitch.client import TwitchClient
from twitch.constants import BASE_URL, VOD_FETCH_URL
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Video
and context (class names, function names, or code) available:
# Path: twitch/client.py
# class TwitchClient(object):
# """
# Twitch API v5 [kraken]
# """
#
# def __init__(self, client_id=None, oauth_token=None):
# self._client_id = client_id
# self._oauth_token = oauth_token
#
# if not client_id:
# self._client_id, self._oauth_token = credentials_from_config_file()
#
# self._clips = None
# self._channel_feed = None
# self._channels = None
# self._chat = None
# self._collections = None
# self._communities = None
# self._games = None
# self._ingests = None
# self._search = None
# self._streams = None
# self._teams = None
# self._users = None
# self._videos = None
#
# @property
# def channel_feed(self):
# if not self._channel_feed:
# self._channel_feed = ChannelFeed(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channel_feed
#
# @property
# def clips(self):
# if not self._clips:
# self._clips = Clips(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._clips
#
# @property
# def channels(self):
# if not self._channels:
# self._channels = Channels(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channels
#
# @property
# def chat(self):
# if not self._chat:
# self._chat = Chat(client_id=self._client_id, oauth_token=self._oauth_token)
# return self._chat
#
# @property
# def collections(self):
# if not self._collections:
# self._collections = Collections(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._collections
#
# @property
# def communities(self):
# if not self._communities:
# self._communities = Communities(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._communities
#
# @property
# def games(self):
# if not self._games:
# self._games = Games(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._games
#
# @property
# def ingests(self):
# if not self._ingests:
# self._ingests = Ingests(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._ingests
#
# @property
# def search(self):
# if not self._search:
# self._search = Search(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._search
#
# @property
# def streams(self):
# if not self._streams:
# self._streams = Streams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._streams
#
# @property
# def teams(self):
# if not self._teams:
# self._teams = Teams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._teams
#
# @property
# def users(self):
# if not self._users:
# self._users = Users(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._users
#
# @property
# def videos(self):
# if not self._videos:
# self._videos = Videos(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._videos
#
# Path: twitch/constants.py
# BASE_URL = "https://api.twitch.tv/kraken/"
#
# VOD_FETCH_URL = "https://usher.ttvnw.net/"
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Video(TwitchObject):
# pass
. Output only the next line. | body=json.dumps(example_followed_response), |
Given the code snippet: <|code_start|>
example_video_response = {
"_id": "v106400740",
"description": "Protect your chat with AutoMod!",
"fps": {"1080p": 23.9767661758746},
}
<|code_end|>
, generate the next line using the imports in this file:
import json
import pytest
import responses
from twitch.client import TwitchClient
from twitch.constants import BASE_URL, VOD_FETCH_URL
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Video
and context (functions, classes, or occasionally code) from other files:
# Path: twitch/client.py
# class TwitchClient(object):
# """
# Twitch API v5 [kraken]
# """
#
# def __init__(self, client_id=None, oauth_token=None):
# self._client_id = client_id
# self._oauth_token = oauth_token
#
# if not client_id:
# self._client_id, self._oauth_token = credentials_from_config_file()
#
# self._clips = None
# self._channel_feed = None
# self._channels = None
# self._chat = None
# self._collections = None
# self._communities = None
# self._games = None
# self._ingests = None
# self._search = None
# self._streams = None
# self._teams = None
# self._users = None
# self._videos = None
#
# @property
# def channel_feed(self):
# if not self._channel_feed:
# self._channel_feed = ChannelFeed(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channel_feed
#
# @property
# def clips(self):
# if not self._clips:
# self._clips = Clips(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._clips
#
# @property
# def channels(self):
# if not self._channels:
# self._channels = Channels(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channels
#
# @property
# def chat(self):
# if not self._chat:
# self._chat = Chat(client_id=self._client_id, oauth_token=self._oauth_token)
# return self._chat
#
# @property
# def collections(self):
# if not self._collections:
# self._collections = Collections(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._collections
#
# @property
# def communities(self):
# if not self._communities:
# self._communities = Communities(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._communities
#
# @property
# def games(self):
# if not self._games:
# self._games = Games(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._games
#
# @property
# def ingests(self):
# if not self._ingests:
# self._ingests = Ingests(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._ingests
#
# @property
# def search(self):
# if not self._search:
# self._search = Search(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._search
#
# @property
# def streams(self):
# if not self._streams:
# self._streams = Streams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._streams
#
# @property
# def teams(self):
# if not self._teams:
# self._teams = Teams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._teams
#
# @property
# def users(self):
# if not self._users:
# self._users = Users(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._users
#
# @property
# def videos(self):
# if not self._videos:
# self._videos = Videos(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._videos
#
# Path: twitch/constants.py
# BASE_URL = "https://api.twitch.tv/kraken/"
#
# VOD_FETCH_URL = "https://usher.ttvnw.net/"
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Video(TwitchObject):
# pass
. Output only the next line. | example_top_response = {"vods": [example_video_response]} |
Predict the next line after this snippet: <|code_start|> content_type="application/json",
)
client = TwitchClient("client id", "oauth token")
videos = client.videos.get_followed_videos()
assert len(responses.calls) == 1
assert len(videos) == 1
assert isinstance(videos[0], Video)
video = videos[0]
assert isinstance(video, Video)
assert video.id == example_video_response["_id"]
assert video.description == example_video_response["description"]
assert video.fps["1080p"] == example_video_response["fps"]["1080p"]
@responses.activate
@pytest.mark.parametrize("param,value", [("limit", 101), ("broadcast_type", "abcd")])
def test_get_followed_videos_raises_if_wrong_params_are_passed_in(param, value):
client = TwitchClient("client id", "oauth token")
kwargs = {param: value}
with pytest.raises(TwitchAttributeException):
client.videos.get_followed_videos(**kwargs)
@responses.activate
def test_download_vod():
video_id = "v106400740"
vod_id = "106400740"
<|code_end|>
using the current file's imports:
import json
import pytest
import responses
from twitch.client import TwitchClient
from twitch.constants import BASE_URL, VOD_FETCH_URL
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Video
and any relevant context from other files:
# Path: twitch/client.py
# class TwitchClient(object):
# """
# Twitch API v5 [kraken]
# """
#
# def __init__(self, client_id=None, oauth_token=None):
# self._client_id = client_id
# self._oauth_token = oauth_token
#
# if not client_id:
# self._client_id, self._oauth_token = credentials_from_config_file()
#
# self._clips = None
# self._channel_feed = None
# self._channels = None
# self._chat = None
# self._collections = None
# self._communities = None
# self._games = None
# self._ingests = None
# self._search = None
# self._streams = None
# self._teams = None
# self._users = None
# self._videos = None
#
# @property
# def channel_feed(self):
# if not self._channel_feed:
# self._channel_feed = ChannelFeed(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channel_feed
#
# @property
# def clips(self):
# if not self._clips:
# self._clips = Clips(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._clips
#
# @property
# def channels(self):
# if not self._channels:
# self._channels = Channels(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channels
#
# @property
# def chat(self):
# if not self._chat:
# self._chat = Chat(client_id=self._client_id, oauth_token=self._oauth_token)
# return self._chat
#
# @property
# def collections(self):
# if not self._collections:
# self._collections = Collections(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._collections
#
# @property
# def communities(self):
# if not self._communities:
# self._communities = Communities(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._communities
#
# @property
# def games(self):
# if not self._games:
# self._games = Games(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._games
#
# @property
# def ingests(self):
# if not self._ingests:
# self._ingests = Ingests(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._ingests
#
# @property
# def search(self):
# if not self._search:
# self._search = Search(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._search
#
# @property
# def streams(self):
# if not self._streams:
# self._streams = Streams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._streams
#
# @property
# def teams(self):
# if not self._teams:
# self._teams = Teams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._teams
#
# @property
# def users(self):
# if not self._users:
# self._users = Users(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._users
#
# @property
# def videos(self):
# if not self._videos:
# self._videos = Videos(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._videos
#
# Path: twitch/constants.py
# BASE_URL = "https://api.twitch.tv/kraken/"
#
# VOD_FETCH_URL = "https://usher.ttvnw.net/"
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Video(TwitchObject):
# pass
. Output only the next line. | responses.add( |
Predict the next line after this snippet: <|code_start|>example_top_response = {"vods": [example_video_response]}
example_followed_response = {"videos": [example_video_response]}
example_download_vod_token_response = {"sig": "sig", "token": "token"}
@responses.activate
def test_get_by_id():
video_id = "v106400740"
responses.add(
responses.GET,
"{}videos/{}".format(BASE_URL, video_id),
body=json.dumps(example_video_response),
status=200,
content_type="application/json",
)
client = TwitchClient("client id")
video = client.videos.get_by_id(video_id)
assert len(responses.calls) == 1
assert isinstance(video, Video)
assert video.id == example_video_response["_id"]
assert video.description == example_video_response["description"]
assert video.fps["1080p"] == example_video_response["fps"]["1080p"]
@responses.activate
<|code_end|>
using the current file's imports:
import json
import pytest
import responses
from twitch.client import TwitchClient
from twitch.constants import BASE_URL, VOD_FETCH_URL
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Video
and any relevant context from other files:
# Path: twitch/client.py
# class TwitchClient(object):
# """
# Twitch API v5 [kraken]
# """
#
# def __init__(self, client_id=None, oauth_token=None):
# self._client_id = client_id
# self._oauth_token = oauth_token
#
# if not client_id:
# self._client_id, self._oauth_token = credentials_from_config_file()
#
# self._clips = None
# self._channel_feed = None
# self._channels = None
# self._chat = None
# self._collections = None
# self._communities = None
# self._games = None
# self._ingests = None
# self._search = None
# self._streams = None
# self._teams = None
# self._users = None
# self._videos = None
#
# @property
# def channel_feed(self):
# if not self._channel_feed:
# self._channel_feed = ChannelFeed(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channel_feed
#
# @property
# def clips(self):
# if not self._clips:
# self._clips = Clips(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._clips
#
# @property
# def channels(self):
# if not self._channels:
# self._channels = Channels(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channels
#
# @property
# def chat(self):
# if not self._chat:
# self._chat = Chat(client_id=self._client_id, oauth_token=self._oauth_token)
# return self._chat
#
# @property
# def collections(self):
# if not self._collections:
# self._collections = Collections(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._collections
#
# @property
# def communities(self):
# if not self._communities:
# self._communities = Communities(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._communities
#
# @property
# def games(self):
# if not self._games:
# self._games = Games(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._games
#
# @property
# def ingests(self):
# if not self._ingests:
# self._ingests = Ingests(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._ingests
#
# @property
# def search(self):
# if not self._search:
# self._search = Search(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._search
#
# @property
# def streams(self):
# if not self._streams:
# self._streams = Streams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._streams
#
# @property
# def teams(self):
# if not self._teams:
# self._teams = Teams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._teams
#
# @property
# def users(self):
# if not self._users:
# self._users = Users(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._users
#
# @property
# def videos(self):
# if not self._videos:
# self._videos = Videos(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._videos
#
# Path: twitch/constants.py
# BASE_URL = "https://api.twitch.tv/kraken/"
#
# VOD_FETCH_URL = "https://usher.ttvnw.net/"
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Video(TwitchObject):
# pass
. Output only the next line. | def test_get_top(): |
Given snippet: <|code_start|> "description": "Protect your chat with AutoMod!",
"fps": {"1080p": 23.9767661758746},
}
example_top_response = {"vods": [example_video_response]}
example_followed_response = {"videos": [example_video_response]}
example_download_vod_token_response = {"sig": "sig", "token": "token"}
@responses.activate
def test_get_by_id():
video_id = "v106400740"
responses.add(
responses.GET,
"{}videos/{}".format(BASE_URL, video_id),
body=json.dumps(example_video_response),
status=200,
content_type="application/json",
)
client = TwitchClient("client id")
video = client.videos.get_by_id(video_id)
assert len(responses.calls) == 1
assert isinstance(video, Video)
assert video.id == example_video_response["_id"]
assert video.description == example_video_response["description"]
<|code_end|>
, continue by predicting the next line. Consider current file imports:
import json
import pytest
import responses
from twitch.client import TwitchClient
from twitch.constants import BASE_URL, VOD_FETCH_URL
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Video
and context:
# Path: twitch/client.py
# class TwitchClient(object):
# """
# Twitch API v5 [kraken]
# """
#
# def __init__(self, client_id=None, oauth_token=None):
# self._client_id = client_id
# self._oauth_token = oauth_token
#
# if not client_id:
# self._client_id, self._oauth_token = credentials_from_config_file()
#
# self._clips = None
# self._channel_feed = None
# self._channels = None
# self._chat = None
# self._collections = None
# self._communities = None
# self._games = None
# self._ingests = None
# self._search = None
# self._streams = None
# self._teams = None
# self._users = None
# self._videos = None
#
# @property
# def channel_feed(self):
# if not self._channel_feed:
# self._channel_feed = ChannelFeed(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channel_feed
#
# @property
# def clips(self):
# if not self._clips:
# self._clips = Clips(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._clips
#
# @property
# def channels(self):
# if not self._channels:
# self._channels = Channels(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channels
#
# @property
# def chat(self):
# if not self._chat:
# self._chat = Chat(client_id=self._client_id, oauth_token=self._oauth_token)
# return self._chat
#
# @property
# def collections(self):
# if not self._collections:
# self._collections = Collections(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._collections
#
# @property
# def communities(self):
# if not self._communities:
# self._communities = Communities(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._communities
#
# @property
# def games(self):
# if not self._games:
# self._games = Games(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._games
#
# @property
# def ingests(self):
# if not self._ingests:
# self._ingests = Ingests(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._ingests
#
# @property
# def search(self):
# if not self._search:
# self._search = Search(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._search
#
# @property
# def streams(self):
# if not self._streams:
# self._streams = Streams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._streams
#
# @property
# def teams(self):
# if not self._teams:
# self._teams = Teams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._teams
#
# @property
# def users(self):
# if not self._users:
# self._users = Users(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._users
#
# @property
# def videos(self):
# if not self._videos:
# self._videos = Videos(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._videos
#
# Path: twitch/constants.py
# BASE_URL = "https://api.twitch.tv/kraken/"
#
# VOD_FETCH_URL = "https://usher.ttvnw.net/"
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Video(TwitchObject):
# pass
which might include code, classes, or functions. Output only the next line. | assert video.fps["1080p"] == example_video_response["fps"]["1080p"] |
Given snippet: <|code_start|>
class Teams(TwitchAPI):
def get(self, team_name):
response = self._request_get("teams/{}".format(team_name))
return Team.construct_from(response)
def get_all(self, limit=10, offset=0):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
<|code_end|>
, continue by predicting the next line. Consider current file imports:
from twitch.api.base import TwitchAPI
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Team
and context:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Team(TwitchObject):
# pass
which might include code, classes, or functions. Output only the next line. | ) |
Here is a snippet: <|code_start|>
class Teams(TwitchAPI):
def get(self, team_name):
response = self._request_get("teams/{}".format(team_name))
return Team.construct_from(response)
def get_all(self, limit=10, offset=0):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
<|code_end|>
. Write the next line using the current file imports:
from twitch.api.base import TwitchAPI
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Team
and context from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Team(TwitchObject):
# pass
, which may include functions, classes, or code. Output only the next line. | ) |
Given snippet: <|code_start|>
class Teams(TwitchAPI):
def get(self, team_name):
response = self._request_get("teams/{}".format(team_name))
return Team.construct_from(response)
def get_all(self, limit=10, offset=0):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
)
params = {"limit": limit, "offset": offset}
<|code_end|>
, continue by predicting the next line. Consider current file imports:
from twitch.api.base import TwitchAPI
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Team
and context:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Team(TwitchObject):
# pass
which might include code, classes, or functions. Output only the next line. | response = self._request_get("teams", params=params) |
Predict the next line for this snippet: <|code_start|> )
params = {"limit": limit, "cursor": cursor}
response = self._request_get(
"communities/{}/bans".format(community_id), params=params
)
return [User.construct_from(x) for x in response["banned_users"]]
@oauth_required
def ban_user(self, community_id, user_id):
self._request_put("communities/{}/bans/{}".format(community_id, user_id))
@oauth_required
def unban_user(self, community_id, user_id):
self._request_delete("communities/{}/bans/{}".format(community_id, user_id))
@oauth_required
def create_avatar_image(self, community_id, avatar_image):
data = {
"avatar_image": avatar_image,
}
self._request_post(
"communities/{}/images/avatar".format(community_id), data=data
)
@oauth_required
def delete_avatar_image(self, community_id):
self._request_delete("communities/{}/images/avatar".format(community_id))
@oauth_required
<|code_end|>
with the help of current file imports:
from twitch.api.base import TwitchAPI
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Community, User
and context from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Community(TwitchObject):
# pass
#
# class User(TwitchObject):
# pass
, which may contain function names, class names, or code. Output only the next line. | def create_cover_image(self, community_id, cover_image): |
Based on the snippet: <|code_start|> "cover_image": cover_image,
}
self._request_post(
"communities/{}/images/cover".format(community_id), data=data
)
@oauth_required
def delete_cover_image(self, community_id):
self._request_delete("communities/{}/images/cover".format(community_id))
def get_moderators(self, community_id):
response = self._request_get("communities/{}/moderators".format(community_id))
return [User.construct_from(x) for x in response["moderators"]]
@oauth_required
def add_moderator(self, community_id, user_id):
self._request_put("communities/{}/moderators/{}".format(community_id, user_id))
@oauth_required
def delete_moderator(self, community_id, user_id):
self._request_delete(
"communities/{}/moderators/{}".format(community_id, user_id)
)
@oauth_required
def get_permissions(self, community_id):
response = self._request_get("communities/{}/permissions".format(community_id))
return response
@oauth_required
<|code_end|>
, predict the immediate next line with the help of imports:
from twitch.api.base import TwitchAPI
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Community, User
and context (classes, functions, sometimes code) from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Community(TwitchObject):
# pass
#
# class User(TwitchObject):
# pass
. Output only the next line. | def report_violation(self, community_id, channel_id): |
Given snippet: <|code_start|>
def get_by_id(self, community_id):
response = self._request_get("communities/{}".format(community_id))
return Community.construct_from(response)
def update(
self, community_id, summary=None, description=None, rules=None, email=None
):
data = {
"summary": summary,
"description": description,
"rules": rules,
"email": email,
}
self._request_put("communities/{}".format(community_id), data=data)
def get_top(self, limit=10, cursor=None):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
)
params = {"limit": limit, "cursor": cursor}
response = self._request_get("communities/top", params=params)
return [Community.construct_from(x) for x in response["communities"]]
@oauth_required
def get_banned_users(self, community_id, limit=10, cursor=None):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
<|code_end|>
, continue by predicting the next line. Consider current file imports:
from twitch.api.base import TwitchAPI
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Community, User
and context:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Community(TwitchObject):
# pass
#
# class User(TwitchObject):
# pass
which might include code, classes, or functions. Output only the next line. | ) |
Given snippet: <|code_start|> def get_moderators(self, community_id):
response = self._request_get("communities/{}/moderators".format(community_id))
return [User.construct_from(x) for x in response["moderators"]]
@oauth_required
def add_moderator(self, community_id, user_id):
self._request_put("communities/{}/moderators/{}".format(community_id, user_id))
@oauth_required
def delete_moderator(self, community_id, user_id):
self._request_delete(
"communities/{}/moderators/{}".format(community_id, user_id)
)
@oauth_required
def get_permissions(self, community_id):
response = self._request_get("communities/{}/permissions".format(community_id))
return response
@oauth_required
def report_violation(self, community_id, channel_id):
data = {
"channel_id": channel_id,
}
self._request_post(
"communities/{}/report_channel".format(community_id), data=data
)
@oauth_required
def get_timed_out_users(self, community_id, limit=10, cursor=None):
<|code_end|>
, continue by predicting the next line. Consider current file imports:
from twitch.api.base import TwitchAPI
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Community, User
and context:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Community(TwitchObject):
# pass
#
# class User(TwitchObject):
# pass
which might include code, classes, or functions. Output only the next line. | if limit > 100: |
Given the following code snippet before the placeholder: <|code_start|> self._request_put("communities/{}".format(community_id), data=data)
def get_top(self, limit=10, cursor=None):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
)
params = {"limit": limit, "cursor": cursor}
response = self._request_get("communities/top", params=params)
return [Community.construct_from(x) for x in response["communities"]]
@oauth_required
def get_banned_users(self, community_id, limit=10, cursor=None):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
)
params = {"limit": limit, "cursor": cursor}
response = self._request_get(
"communities/{}/bans".format(community_id), params=params
)
return [User.construct_from(x) for x in response["banned_users"]]
@oauth_required
def ban_user(self, community_id, user_id):
self._request_put("communities/{}/bans/{}".format(community_id, user_id))
@oauth_required
def unban_user(self, community_id, user_id):
<|code_end|>
, predict the next line using imports from the current file:
from twitch.api.base import TwitchAPI
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Community, User
and context including class names, function names, and sometimes code from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Community(TwitchObject):
# pass
#
# class User(TwitchObject):
# pass
. Output only the next line. | self._request_delete("communities/{}/bans/{}".format(community_id, user_id)) |
Given the following code snippet before the placeholder: <|code_start|>
class Games(TwitchAPI):
def get_top(self, limit=10, offset=0):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
<|code_end|>
, predict the next line using imports from the current file:
from twitch.api.base import TwitchAPI
from twitch.exceptions import TwitchAttributeException
from twitch.resources import TopGame
and context including class names, function names, and sometimes code from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class TopGame(TwitchObject):
# pass
. Output only the next line. | ) |
Predict the next line after this snippet: <|code_start|>
class Games(TwitchAPI):
def get_top(self, limit=10, offset=0):
if limit > 100:
raise TwitchAttributeException(
<|code_end|>
using the current file's imports:
from twitch.api.base import TwitchAPI
from twitch.exceptions import TwitchAttributeException
from twitch.resources import TopGame
and any relevant context from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class TopGame(TwitchObject):
# pass
. Output only the next line. | "Maximum number of objects returned in one request is 100" |
Based on the snippet: <|code_start|>
class Games(TwitchAPI):
def get_top(self, limit=10, offset=0):
if limit > 100:
raise TwitchAttributeException(
<|code_end|>
, predict the immediate next line with the help of imports:
from twitch.api.base import TwitchAPI
from twitch.exceptions import TwitchAttributeException
from twitch.resources import TopGame
and context (classes, functions, sometimes code) from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class TopGame(TwitchObject):
# pass
. Output only the next line. | "Maximum number of objects returned in one request is 100" |
Given the following code snippet before the placeholder: <|code_start|>
class Search(TwitchAPI):
def channels(self, query, limit=25, offset=0):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
)
params = {"query": query, "limit": limit, "offset": offset}
response = self._request_get("search/channels", params=params)
return [Channel.construct_from(x) for x in response["channels"] or []]
def games(self, query, live=False):
<|code_end|>
, predict the next line using imports from the current file:
from twitch.api.base import TwitchAPI
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Channel, Game, Stream
and context including class names, function names, and sometimes code from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Game(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
. Output only the next line. | params = { |
Here is a snippet: <|code_start|>
class Search(TwitchAPI):
def channels(self, query, limit=25, offset=0):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
<|code_end|>
. Write the next line using the current file imports:
from twitch.api.base import TwitchAPI
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Channel, Game, Stream
and context from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Game(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
, which may include functions, classes, or code. Output only the next line. | ) |
Given the code snippet: <|code_start|>
class Search(TwitchAPI):
def channels(self, query, limit=25, offset=0):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
)
params = {"query": query, "limit": limit, "offset": offset}
response = self._request_get("search/channels", params=params)
return [Channel.construct_from(x) for x in response["channels"] or []]
def games(self, query, live=False):
params = {
"query": query,
"live": live,
}
response = self._request_get("search/games", params=params)
return [Game.construct_from(x) for x in response["games"] or []]
def streams(self, query, limit=25, offset=0, hls=None):
<|code_end|>
, generate the next line using the imports in this file:
from twitch.api.base import TwitchAPI
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Channel, Game, Stream
and context (functions, classes, or occasionally code) from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Game(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
. Output only the next line. | if limit > 100: |
Given snippet: <|code_start|>
class Search(TwitchAPI):
def channels(self, query, limit=25, offset=0):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
)
params = {"query": query, "limit": limit, "offset": offset}
response = self._request_get("search/channels", params=params)
return [Channel.construct_from(x) for x in response["channels"] or []]
def games(self, query, live=False):
params = {
"query": query,
<|code_end|>
, continue by predicting the next line. Consider current file imports:
from twitch.api.base import TwitchAPI
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Channel, Game, Stream
and context:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Game(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
which might include code, classes, or functions. Output only the next line. | "live": live, |
Using the snippet: <|code_start|>
class Search(TwitchAPI):
def channels(self, query, limit=25, offset=0):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
)
params = {"query": query, "limit": limit, "offset": offset}
response = self._request_get("search/channels", params=params)
return [Channel.construct_from(x) for x in response["channels"] or []]
def games(self, query, live=False):
params = {
"query": query,
<|code_end|>
, determine the next line of code. You have imports:
from twitch.api.base import TwitchAPI
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Channel, Game, Stream
and context (class names, function names, or code) available:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Game(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
. Output only the next line. | "live": live, |
Based on the snippet: <|code_start|>}
example_block = {
"_id": 34105660,
"updated_at": "2016-12-15T18:58:11Z",
"user": example_user,
}
@responses.activate
def test_get():
responses.add(
responses.GET,
"{}user".format(BASE_URL),
body=json.dumps(example_user),
status=200,
content_type="application/json",
)
client = TwitchClient("client id", "oauth token")
user = client.users.get()
assert len(responses.calls) == 1
assert isinstance(user, User)
assert user.id == example_user["_id"]
assert user.name == example_user["name"]
@responses.activate
<|code_end|>
, predict the immediate next line with the help of imports:
import json
import pytest
import responses
from twitch.client import TwitchClient
from twitch.constants import BASE_URL
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Channel, Follow, Subscription, User, UserBlock
and context (classes, functions, sometimes code) from other files:
# Path: twitch/client.py
# class TwitchClient(object):
# """
# Twitch API v5 [kraken]
# """
#
# def __init__(self, client_id=None, oauth_token=None):
# self._client_id = client_id
# self._oauth_token = oauth_token
#
# if not client_id:
# self._client_id, self._oauth_token = credentials_from_config_file()
#
# self._clips = None
# self._channel_feed = None
# self._channels = None
# self._chat = None
# self._collections = None
# self._communities = None
# self._games = None
# self._ingests = None
# self._search = None
# self._streams = None
# self._teams = None
# self._users = None
# self._videos = None
#
# @property
# def channel_feed(self):
# if not self._channel_feed:
# self._channel_feed = ChannelFeed(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channel_feed
#
# @property
# def clips(self):
# if not self._clips:
# self._clips = Clips(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._clips
#
# @property
# def channels(self):
# if not self._channels:
# self._channels = Channels(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channels
#
# @property
# def chat(self):
# if not self._chat:
# self._chat = Chat(client_id=self._client_id, oauth_token=self._oauth_token)
# return self._chat
#
# @property
# def collections(self):
# if not self._collections:
# self._collections = Collections(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._collections
#
# @property
# def communities(self):
# if not self._communities:
# self._communities = Communities(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._communities
#
# @property
# def games(self):
# if not self._games:
# self._games = Games(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._games
#
# @property
# def ingests(self):
# if not self._ingests:
# self._ingests = Ingests(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._ingests
#
# @property
# def search(self):
# if not self._search:
# self._search = Search(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._search
#
# @property
# def streams(self):
# if not self._streams:
# self._streams = Streams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._streams
#
# @property
# def teams(self):
# if not self._teams:
# self._teams = Teams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._teams
#
# @property
# def users(self):
# if not self._users:
# self._users = Users(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._users
#
# @property
# def videos(self):
# if not self._videos:
# self._videos = Videos(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._videos
#
# Path: twitch/constants.py
# BASE_URL = "https://api.twitch.tv/kraken/"
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Follow(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class User(TwitchObject):
# pass
#
# class UserBlock(TwitchObject):
# pass
. Output only the next line. | def test_get_by_id(): |
Using the snippet: <|code_start|>def test_get_by_id():
user_id = 1234
responses.add(
responses.GET,
"{}users/{}".format(BASE_URL, user_id),
body=json.dumps(example_user),
status=200,
content_type="application/json",
)
client = TwitchClient("client id")
user = client.users.get_by_id(user_id)
assert len(responses.calls) == 1
assert isinstance(user, User)
assert user.id == example_user["_id"]
assert user.name == example_user["name"]
@responses.activate
def test_get_emotes():
user_id = 1234
response = {"emoticon_sets": {"17937": [{"code": "Kappa", "id": 25}]}}
responses.add(
responses.GET,
"{}users/{}/emotes".format(BASE_URL, user_id),
body=json.dumps(response),
status=200,
content_type="application/json",
<|code_end|>
, determine the next line of code. You have imports:
import json
import pytest
import responses
from twitch.client import TwitchClient
from twitch.constants import BASE_URL
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Channel, Follow, Subscription, User, UserBlock
and context (class names, function names, or code) available:
# Path: twitch/client.py
# class TwitchClient(object):
# """
# Twitch API v5 [kraken]
# """
#
# def __init__(self, client_id=None, oauth_token=None):
# self._client_id = client_id
# self._oauth_token = oauth_token
#
# if not client_id:
# self._client_id, self._oauth_token = credentials_from_config_file()
#
# self._clips = None
# self._channel_feed = None
# self._channels = None
# self._chat = None
# self._collections = None
# self._communities = None
# self._games = None
# self._ingests = None
# self._search = None
# self._streams = None
# self._teams = None
# self._users = None
# self._videos = None
#
# @property
# def channel_feed(self):
# if not self._channel_feed:
# self._channel_feed = ChannelFeed(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channel_feed
#
# @property
# def clips(self):
# if not self._clips:
# self._clips = Clips(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._clips
#
# @property
# def channels(self):
# if not self._channels:
# self._channels = Channels(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channels
#
# @property
# def chat(self):
# if not self._chat:
# self._chat = Chat(client_id=self._client_id, oauth_token=self._oauth_token)
# return self._chat
#
# @property
# def collections(self):
# if not self._collections:
# self._collections = Collections(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._collections
#
# @property
# def communities(self):
# if not self._communities:
# self._communities = Communities(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._communities
#
# @property
# def games(self):
# if not self._games:
# self._games = Games(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._games
#
# @property
# def ingests(self):
# if not self._ingests:
# self._ingests = Ingests(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._ingests
#
# @property
# def search(self):
# if not self._search:
# self._search = Search(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._search
#
# @property
# def streams(self):
# if not self._streams:
# self._streams = Streams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._streams
#
# @property
# def teams(self):
# if not self._teams:
# self._teams = Teams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._teams
#
# @property
# def users(self):
# if not self._users:
# self._users = Users(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._users
#
# @property
# def videos(self):
# if not self._videos:
# self._videos = Videos(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._videos
#
# Path: twitch/constants.py
# BASE_URL = "https://api.twitch.tv/kraken/"
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Follow(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class User(TwitchObject):
# pass
#
# class UserBlock(TwitchObject):
# pass
. Output only the next line. | ) |
Continue the code snippet: <|code_start|> client = TwitchClient("client id")
follows = client.users.get_all_follows(
user_id, direction="desc", sort_by="last_broadcast"
)
assert len(responses.calls) == 2
assert len(follows) == 2
follow = follows[0]
assert isinstance(follow, Follow)
assert follow.notifications == example_follow["notifications"]
assert isinstance(follow.channel, Channel)
assert follow.channel.id == example_channel["_id"]
assert follow.channel.name == example_channel["name"]
@responses.activate
@pytest.mark.parametrize("param,value", [("direction", "abcd"), ("sort_by", "abcd")])
def test_get_all_follows_raises_if_wrong_params_are_passed_in(param, value):
client = TwitchClient("client id")
kwargs = {param: value}
with pytest.raises(TwitchAttributeException):
client.users.get_all_follows("1234", **kwargs)
@responses.activate
def test_check_follows_channel():
user_id = 1234
channel_id = 12345
responses.add(
<|code_end|>
. Use current file imports:
import json
import pytest
import responses
from twitch.client import TwitchClient
from twitch.constants import BASE_URL
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Channel, Follow, Subscription, User, UserBlock
and context (classes, functions, or code) from other files:
# Path: twitch/client.py
# class TwitchClient(object):
# """
# Twitch API v5 [kraken]
# """
#
# def __init__(self, client_id=None, oauth_token=None):
# self._client_id = client_id
# self._oauth_token = oauth_token
#
# if not client_id:
# self._client_id, self._oauth_token = credentials_from_config_file()
#
# self._clips = None
# self._channel_feed = None
# self._channels = None
# self._chat = None
# self._collections = None
# self._communities = None
# self._games = None
# self._ingests = None
# self._search = None
# self._streams = None
# self._teams = None
# self._users = None
# self._videos = None
#
# @property
# def channel_feed(self):
# if not self._channel_feed:
# self._channel_feed = ChannelFeed(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channel_feed
#
# @property
# def clips(self):
# if not self._clips:
# self._clips = Clips(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._clips
#
# @property
# def channels(self):
# if not self._channels:
# self._channels = Channels(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channels
#
# @property
# def chat(self):
# if not self._chat:
# self._chat = Chat(client_id=self._client_id, oauth_token=self._oauth_token)
# return self._chat
#
# @property
# def collections(self):
# if not self._collections:
# self._collections = Collections(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._collections
#
# @property
# def communities(self):
# if not self._communities:
# self._communities = Communities(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._communities
#
# @property
# def games(self):
# if not self._games:
# self._games = Games(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._games
#
# @property
# def ingests(self):
# if not self._ingests:
# self._ingests = Ingests(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._ingests
#
# @property
# def search(self):
# if not self._search:
# self._search = Search(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._search
#
# @property
# def streams(self):
# if not self._streams:
# self._streams = Streams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._streams
#
# @property
# def teams(self):
# if not self._teams:
# self._teams = Teams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._teams
#
# @property
# def users(self):
# if not self._users:
# self._users = Users(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._users
#
# @property
# def videos(self):
# if not self._videos:
# self._videos = Videos(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._videos
#
# Path: twitch/constants.py
# BASE_URL = "https://api.twitch.tv/kraken/"
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Follow(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class User(TwitchObject):
# pass
#
# class UserBlock(TwitchObject):
# pass
. Output only the next line. | responses.GET, |
Predict the next line after this snippet: <|code_start|>
example_user = {
"_id": "44322889",
"name": "dallas",
}
example_channel = {
"_id": 121059319,
"name": "moonmoon_ow",
}
example_follow = {
"created_at": "2016-09-16T20:37:39Z",
"notifications": False,
"channel": example_channel,
}
example_block = {
"_id": 34105660,
"updated_at": "2016-12-15T18:58:11Z",
"user": example_user,
}
<|code_end|>
using the current file's imports:
import json
import pytest
import responses
from twitch.client import TwitchClient
from twitch.constants import BASE_URL
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Channel, Follow, Subscription, User, UserBlock
and any relevant context from other files:
# Path: twitch/client.py
# class TwitchClient(object):
# """
# Twitch API v5 [kraken]
# """
#
# def __init__(self, client_id=None, oauth_token=None):
# self._client_id = client_id
# self._oauth_token = oauth_token
#
# if not client_id:
# self._client_id, self._oauth_token = credentials_from_config_file()
#
# self._clips = None
# self._channel_feed = None
# self._channels = None
# self._chat = None
# self._collections = None
# self._communities = None
# self._games = None
# self._ingests = None
# self._search = None
# self._streams = None
# self._teams = None
# self._users = None
# self._videos = None
#
# @property
# def channel_feed(self):
# if not self._channel_feed:
# self._channel_feed = ChannelFeed(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channel_feed
#
# @property
# def clips(self):
# if not self._clips:
# self._clips = Clips(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._clips
#
# @property
# def channels(self):
# if not self._channels:
# self._channels = Channels(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channels
#
# @property
# def chat(self):
# if not self._chat:
# self._chat = Chat(client_id=self._client_id, oauth_token=self._oauth_token)
# return self._chat
#
# @property
# def collections(self):
# if not self._collections:
# self._collections = Collections(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._collections
#
# @property
# def communities(self):
# if not self._communities:
# self._communities = Communities(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._communities
#
# @property
# def games(self):
# if not self._games:
# self._games = Games(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._games
#
# @property
# def ingests(self):
# if not self._ingests:
# self._ingests = Ingests(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._ingests
#
# @property
# def search(self):
# if not self._search:
# self._search = Search(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._search
#
# @property
# def streams(self):
# if not self._streams:
# self._streams = Streams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._streams
#
# @property
# def teams(self):
# if not self._teams:
# self._teams = Teams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._teams
#
# @property
# def users(self):
# if not self._users:
# self._users = Users(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._users
#
# @property
# def videos(self):
# if not self._videos:
# self._videos = Videos(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._videos
#
# Path: twitch/constants.py
# BASE_URL = "https://api.twitch.tv/kraken/"
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Follow(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class User(TwitchObject):
# pass
#
# class UserBlock(TwitchObject):
# pass
. Output only the next line. | @responses.activate |
Continue the code snippet: <|code_start|> channel_id = 12345
response = {
"_id": "c660cb408bc3b542f5bdbba52f3e638e652756b4",
"created_at": "2016-12-12T15:52:52Z",
"channel": example_channel,
}
responses.add(
responses.GET,
"{}users/{}/subscriptions/{}".format(BASE_URL, user_id, channel_id),
body=json.dumps(response),
status=200,
content_type="application/json",
)
client = TwitchClient("client id", "oauth token")
subscription = client.users.check_subscribed_to_channel(user_id, channel_id)
assert len(responses.calls) == 1
assert isinstance(subscription, Subscription)
assert subscription.id == response["_id"]
assert isinstance(subscription.channel, Channel)
assert subscription.channel.id == example_channel["_id"]
assert subscription.channel.name == example_channel["name"]
@responses.activate
def test_get_follows():
user_id = 1234
response = {"_total": 27, "follows": [example_follow]}
<|code_end|>
. Use current file imports:
import json
import pytest
import responses
from twitch.client import TwitchClient
from twitch.constants import BASE_URL
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Channel, Follow, Subscription, User, UserBlock
and context (classes, functions, or code) from other files:
# Path: twitch/client.py
# class TwitchClient(object):
# """
# Twitch API v5 [kraken]
# """
#
# def __init__(self, client_id=None, oauth_token=None):
# self._client_id = client_id
# self._oauth_token = oauth_token
#
# if not client_id:
# self._client_id, self._oauth_token = credentials_from_config_file()
#
# self._clips = None
# self._channel_feed = None
# self._channels = None
# self._chat = None
# self._collections = None
# self._communities = None
# self._games = None
# self._ingests = None
# self._search = None
# self._streams = None
# self._teams = None
# self._users = None
# self._videos = None
#
# @property
# def channel_feed(self):
# if not self._channel_feed:
# self._channel_feed = ChannelFeed(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channel_feed
#
# @property
# def clips(self):
# if not self._clips:
# self._clips = Clips(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._clips
#
# @property
# def channels(self):
# if not self._channels:
# self._channels = Channels(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channels
#
# @property
# def chat(self):
# if not self._chat:
# self._chat = Chat(client_id=self._client_id, oauth_token=self._oauth_token)
# return self._chat
#
# @property
# def collections(self):
# if not self._collections:
# self._collections = Collections(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._collections
#
# @property
# def communities(self):
# if not self._communities:
# self._communities = Communities(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._communities
#
# @property
# def games(self):
# if not self._games:
# self._games = Games(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._games
#
# @property
# def ingests(self):
# if not self._ingests:
# self._ingests = Ingests(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._ingests
#
# @property
# def search(self):
# if not self._search:
# self._search = Search(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._search
#
# @property
# def streams(self):
# if not self._streams:
# self._streams = Streams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._streams
#
# @property
# def teams(self):
# if not self._teams:
# self._teams = Teams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._teams
#
# @property
# def users(self):
# if not self._users:
# self._users = Users(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._users
#
# @property
# def videos(self):
# if not self._videos:
# self._videos = Videos(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._videos
#
# Path: twitch/constants.py
# BASE_URL = "https://api.twitch.tv/kraken/"
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Follow(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class User(TwitchObject):
# pass
#
# class UserBlock(TwitchObject):
# pass
. Output only the next line. | responses.add( |
Continue the code snippet: <|code_start|> assert len(responses.calls) == 1
assert isinstance(follow, Follow)
assert follow.notifications == example_follow["notifications"]
assert isinstance(follow.channel, Channel)
assert follow.channel.id == example_channel["_id"]
assert follow.channel.name == example_channel["name"]
@responses.activate
def test_unfollow_channel():
user_id = 1234
channel_id = 12345
responses.add(
responses.DELETE,
"{}users/{}/follows/channels/{}".format(BASE_URL, user_id, channel_id),
status=204,
content_type="application/json",
)
client = TwitchClient("client id", "oauth token")
client.users.unfollow_channel(user_id, channel_id)
assert len(responses.calls) == 1
@responses.activate
def test_get_user_block_list():
user_id = 1234
response = {"_total": 4, "blocks": [example_block]}
<|code_end|>
. Use current file imports:
import json
import pytest
import responses
from twitch.client import TwitchClient
from twitch.constants import BASE_URL
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Channel, Follow, Subscription, User, UserBlock
and context (classes, functions, or code) from other files:
# Path: twitch/client.py
# class TwitchClient(object):
# """
# Twitch API v5 [kraken]
# """
#
# def __init__(self, client_id=None, oauth_token=None):
# self._client_id = client_id
# self._oauth_token = oauth_token
#
# if not client_id:
# self._client_id, self._oauth_token = credentials_from_config_file()
#
# self._clips = None
# self._channel_feed = None
# self._channels = None
# self._chat = None
# self._collections = None
# self._communities = None
# self._games = None
# self._ingests = None
# self._search = None
# self._streams = None
# self._teams = None
# self._users = None
# self._videos = None
#
# @property
# def channel_feed(self):
# if not self._channel_feed:
# self._channel_feed = ChannelFeed(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channel_feed
#
# @property
# def clips(self):
# if not self._clips:
# self._clips = Clips(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._clips
#
# @property
# def channels(self):
# if not self._channels:
# self._channels = Channels(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channels
#
# @property
# def chat(self):
# if not self._chat:
# self._chat = Chat(client_id=self._client_id, oauth_token=self._oauth_token)
# return self._chat
#
# @property
# def collections(self):
# if not self._collections:
# self._collections = Collections(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._collections
#
# @property
# def communities(self):
# if not self._communities:
# self._communities = Communities(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._communities
#
# @property
# def games(self):
# if not self._games:
# self._games = Games(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._games
#
# @property
# def ingests(self):
# if not self._ingests:
# self._ingests = Ingests(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._ingests
#
# @property
# def search(self):
# if not self._search:
# self._search = Search(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._search
#
# @property
# def streams(self):
# if not self._streams:
# self._streams = Streams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._streams
#
# @property
# def teams(self):
# if not self._teams:
# self._teams = Teams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._teams
#
# @property
# def users(self):
# if not self._users:
# self._users = Users(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._users
#
# @property
# def videos(self):
# if not self._videos:
# self._videos = Videos(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._videos
#
# Path: twitch/constants.py
# BASE_URL = "https://api.twitch.tv/kraken/"
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Follow(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class User(TwitchObject):
# pass
#
# class UserBlock(TwitchObject):
# pass
. Output only the next line. | responses.add( |
Predict the next line after this snippet: <|code_start|> assert len(responses.calls) == 1
assert len(follows) == 1
follow = follows[0]
assert isinstance(follow, Follow)
assert follow.notifications == example_follow["notifications"]
assert isinstance(follow.channel, Channel)
assert follow.channel.id == example_channel["_id"]
assert follow.channel.name == example_channel["name"]
@responses.activate
@pytest.mark.parametrize(
"param,value", [("limit", 101), ("direction", "abcd"), ("sort_by", "abcd")]
)
def test_get_follows_raises_if_wrong_params_are_passed_in(param, value):
client = TwitchClient("client id")
kwargs = {param: value}
with pytest.raises(TwitchAttributeException):
client.users.get_follows("1234", **kwargs)
@responses.activate
def test_get_all_follows():
user_id = 1234
response_with_offset = {"_total": 27, "_offset": 1234, "follows": [example_follow]}
response_without_offset = {"_total": 27, "follows": [example_follow]}
responses.add(
responses.GET,
"{}users/{}/follows/channels".format(BASE_URL, user_id),
body=json.dumps(response_with_offset),
<|code_end|>
using the current file's imports:
import json
import pytest
import responses
from twitch.client import TwitchClient
from twitch.constants import BASE_URL
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Channel, Follow, Subscription, User, UserBlock
and any relevant context from other files:
# Path: twitch/client.py
# class TwitchClient(object):
# """
# Twitch API v5 [kraken]
# """
#
# def __init__(self, client_id=None, oauth_token=None):
# self._client_id = client_id
# self._oauth_token = oauth_token
#
# if not client_id:
# self._client_id, self._oauth_token = credentials_from_config_file()
#
# self._clips = None
# self._channel_feed = None
# self._channels = None
# self._chat = None
# self._collections = None
# self._communities = None
# self._games = None
# self._ingests = None
# self._search = None
# self._streams = None
# self._teams = None
# self._users = None
# self._videos = None
#
# @property
# def channel_feed(self):
# if not self._channel_feed:
# self._channel_feed = ChannelFeed(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channel_feed
#
# @property
# def clips(self):
# if not self._clips:
# self._clips = Clips(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._clips
#
# @property
# def channels(self):
# if not self._channels:
# self._channels = Channels(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channels
#
# @property
# def chat(self):
# if not self._chat:
# self._chat = Chat(client_id=self._client_id, oauth_token=self._oauth_token)
# return self._chat
#
# @property
# def collections(self):
# if not self._collections:
# self._collections = Collections(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._collections
#
# @property
# def communities(self):
# if not self._communities:
# self._communities = Communities(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._communities
#
# @property
# def games(self):
# if not self._games:
# self._games = Games(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._games
#
# @property
# def ingests(self):
# if not self._ingests:
# self._ingests = Ingests(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._ingests
#
# @property
# def search(self):
# if not self._search:
# self._search = Search(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._search
#
# @property
# def streams(self):
# if not self._streams:
# self._streams = Streams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._streams
#
# @property
# def teams(self):
# if not self._teams:
# self._teams = Teams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._teams
#
# @property
# def users(self):
# if not self._users:
# self._users = Users(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._users
#
# @property
# def videos(self):
# if not self._videos:
# self._videos = Videos(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._videos
#
# Path: twitch/constants.py
# BASE_URL = "https://api.twitch.tv/kraken/"
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Follow(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class User(TwitchObject):
# pass
#
# class UserBlock(TwitchObject):
# pass
. Output only the next line. | status=200, |
Predict the next line for this snippet: <|code_start|> assert subscription.channel.name == example_channel["name"]
@responses.activate
def test_get_follows():
user_id = 1234
response = {"_total": 27, "follows": [example_follow]}
responses.add(
responses.GET,
"{}users/{}/follows/channels".format(BASE_URL, user_id),
body=json.dumps(response),
status=200,
content_type="application/json",
)
client = TwitchClient("client id")
follows = client.users.get_follows(user_id)
assert len(responses.calls) == 1
assert len(follows) == 1
follow = follows[0]
assert isinstance(follow, Follow)
assert follow.notifications == example_follow["notifications"]
assert isinstance(follow.channel, Channel)
assert follow.channel.id == example_channel["_id"]
assert follow.channel.name == example_channel["name"]
@responses.activate
<|code_end|>
with the help of current file imports:
import json
import pytest
import responses
from twitch.client import TwitchClient
from twitch.constants import BASE_URL
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Channel, Follow, Subscription, User, UserBlock
and context from other files:
# Path: twitch/client.py
# class TwitchClient(object):
# """
# Twitch API v5 [kraken]
# """
#
# def __init__(self, client_id=None, oauth_token=None):
# self._client_id = client_id
# self._oauth_token = oauth_token
#
# if not client_id:
# self._client_id, self._oauth_token = credentials_from_config_file()
#
# self._clips = None
# self._channel_feed = None
# self._channels = None
# self._chat = None
# self._collections = None
# self._communities = None
# self._games = None
# self._ingests = None
# self._search = None
# self._streams = None
# self._teams = None
# self._users = None
# self._videos = None
#
# @property
# def channel_feed(self):
# if not self._channel_feed:
# self._channel_feed = ChannelFeed(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channel_feed
#
# @property
# def clips(self):
# if not self._clips:
# self._clips = Clips(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._clips
#
# @property
# def channels(self):
# if not self._channels:
# self._channels = Channels(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channels
#
# @property
# def chat(self):
# if not self._chat:
# self._chat = Chat(client_id=self._client_id, oauth_token=self._oauth_token)
# return self._chat
#
# @property
# def collections(self):
# if not self._collections:
# self._collections = Collections(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._collections
#
# @property
# def communities(self):
# if not self._communities:
# self._communities = Communities(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._communities
#
# @property
# def games(self):
# if not self._games:
# self._games = Games(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._games
#
# @property
# def ingests(self):
# if not self._ingests:
# self._ingests = Ingests(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._ingests
#
# @property
# def search(self):
# if not self._search:
# self._search = Search(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._search
#
# @property
# def streams(self):
# if not self._streams:
# self._streams = Streams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._streams
#
# @property
# def teams(self):
# if not self._teams:
# self._teams = Teams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._teams
#
# @property
# def users(self):
# if not self._users:
# self._users = Users(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._users
#
# @property
# def videos(self):
# if not self._videos:
# self._videos = Videos(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._videos
#
# Path: twitch/constants.py
# BASE_URL = "https://api.twitch.tv/kraken/"
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Follow(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class User(TwitchObject):
# pass
#
# class UserBlock(TwitchObject):
# pass
, which may contain function names, class names, or code. Output only the next line. | @pytest.mark.parametrize( |
Next line prediction: <|code_start|>
class Collections(TwitchAPI):
def get_metadata(self, collection_id):
response = self._request_get("collections/{}".format(collection_id))
return Collection.construct_from(response)
<|code_end|>
. Use current file imports:
(from twitch.api.base import TwitchAPI
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Collection, Item)
and context including class names, function names, or small code snippets from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Collection(TwitchObject):
# pass
#
# class Item(TwitchObject):
# pass
. Output only the next line. | def get(self, collection_id, include_all_items=False): |
Predict the next line for this snippet: <|code_start|>
class Collections(TwitchAPI):
def get_metadata(self, collection_id):
response = self._request_get("collections/{}".format(collection_id))
return Collection.construct_from(response)
def get(self, collection_id, include_all_items=False):
params = {"include_all_items": include_all_items}
response = self._request_get(
"collections/{}/items".format(collection_id), params=params
)
return [Item.construct_from(x) for x in response["items"]]
def get_by_channel(self, channel_id, limit=10, cursor=None, containing_item=None):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
)
params = {
"limit": limit,
"cursor": cursor,
}
if containing_item:
<|code_end|>
with the help of current file imports:
from twitch.api.base import TwitchAPI
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Collection, Item
and context from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Collection(TwitchObject):
# pass
#
# class Item(TwitchObject):
# pass
, which may contain function names, class names, or code. Output only the next line. | params["containing_item"] = containing_item |
Based on the snippet: <|code_start|> return [Item.construct_from(x) for x in response["items"]]
def get_by_channel(self, channel_id, limit=10, cursor=None, containing_item=None):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
)
params = {
"limit": limit,
"cursor": cursor,
}
if containing_item:
params["containing_item"] = containing_item
response = self._request_get("channels/{}/collections".format(channel_id))
return [Collection.construct_from(x) for x in response["collections"]]
@oauth_required
def create(self, channel_id, title):
data = {
"title": title,
}
response = self._request_post(
"channels/{}/collections".format(channel_id), data=data
)
return Collection.construct_from(response)
@oauth_required
def update(self, collection_id, title):
data = {
"title": title,
<|code_end|>
, predict the immediate next line with the help of imports:
from twitch.api.base import TwitchAPI
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Collection, Item
and context (classes, functions, sometimes code) from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Collection(TwitchObject):
# pass
#
# class Item(TwitchObject):
# pass
. Output only the next line. | } |
Predict the next line after this snippet: <|code_start|>
class Collections(TwitchAPI):
def get_metadata(self, collection_id):
response = self._request_get("collections/{}".format(collection_id))
return Collection.construct_from(response)
def get(self, collection_id, include_all_items=False):
params = {"include_all_items": include_all_items}
response = self._request_get(
"collections/{}/items".format(collection_id), params=params
)
return [Item.construct_from(x) for x in response["items"]]
def get_by_channel(self, channel_id, limit=10, cursor=None, containing_item=None):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
)
params = {
"limit": limit,
"cursor": cursor,
}
if containing_item:
params["containing_item"] = containing_item
<|code_end|>
using the current file's imports:
from twitch.api.base import TwitchAPI
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Collection, Item
and any relevant context from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Collection(TwitchObject):
# pass
#
# class Item(TwitchObject):
# pass
. Output only the next line. | response = self._request_get("channels/{}/collections".format(channel_id)) |
Given the code snippet: <|code_start|>
class Collections(TwitchAPI):
def get_metadata(self, collection_id):
response = self._request_get("collections/{}".format(collection_id))
return Collection.construct_from(response)
def get(self, collection_id, include_all_items=False):
params = {"include_all_items": include_all_items}
response = self._request_get(
"collections/{}/items".format(collection_id), params=params
)
return [Item.construct_from(x) for x in response["items"]]
def get_by_channel(self, channel_id, limit=10, cursor=None, containing_item=None):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
)
params = {
"limit": limit,
<|code_end|>
, generate the next line using the imports in this file:
from twitch.api.base import TwitchAPI
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Collection, Item
and context (functions, classes, or occasionally code) from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Collection(TwitchObject):
# pass
#
# class Item(TwitchObject):
# pass
. Output only the next line. | "cursor": cursor, |
Given the following code snippet before the placeholder: <|code_start|>
class Chat(TwitchAPI):
def get_badges_by_channel(self, channel_id):
response = self._request_get("chat/{}/badges".format(channel_id))
return response
def get_emoticons_by_set(self, emotesets=None):
params = {
<|code_end|>
, predict the next line using imports from the current file:
from twitch.api.base import TwitchAPI
and context including class names, function names, and sometimes code from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
. Output only the next line. | "emotesets": emotesets, |
Continue the code snippet: <|code_start|> trending=False,
):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
)
if period not in PERIODS:
raise TwitchAttributeException(
"Period is not valid. Valid values are {}".format(PERIODS)
)
params = {
"channel": channel,
"cursor": cursor,
"game": game,
"language": language,
"limit": limit,
"period": period,
"trending": str(trending).lower(),
}
response = self._request_get("clips/top", params=params)
return [Clip.construct_from(x) for x in response["clips"]]
@oauth_required
def followed(self, limit=10, cursor=None, trending=False):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
<|code_end|>
. Use current file imports:
from twitch.api.base import TwitchAPI
from twitch.constants import PERIODS
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Clip
and context (classes, functions, or code) from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/constants.py
# PERIODS = [PERIOD_DAY, PERIOD_WEEK, PERIOD_MONTH, PERIOD_ALL]
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Clip(TwitchObject):
# pass
. Output only the next line. | ) |
Given the following code snippet before the placeholder: <|code_start|> game=None,
language=None,
limit=10,
period="week",
trending=False,
):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
)
if period not in PERIODS:
raise TwitchAttributeException(
"Period is not valid. Valid values are {}".format(PERIODS)
)
params = {
"channel": channel,
"cursor": cursor,
"game": game,
"language": language,
"limit": limit,
"period": period,
"trending": str(trending).lower(),
}
response = self._request_get("clips/top", params=params)
return [Clip.construct_from(x) for x in response["clips"]]
@oauth_required
<|code_end|>
, predict the next line using imports from the current file:
from twitch.api.base import TwitchAPI
from twitch.constants import PERIODS
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Clip
and context including class names, function names, and sometimes code from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/constants.py
# PERIODS = [PERIOD_DAY, PERIOD_WEEK, PERIOD_MONTH, PERIOD_ALL]
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Clip(TwitchObject):
# pass
. Output only the next line. | def followed(self, limit=10, cursor=None, trending=False): |
Next line prediction: <|code_start|> def get_by_slug(self, slug):
response = self._request_get("clips/{}".format(slug))
return Clip.construct_from(response)
def get_top(
self,
channel=None,
cursor=None,
game=None,
language=None,
limit=10,
period="week",
trending=False,
):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
)
if period not in PERIODS:
raise TwitchAttributeException(
"Period is not valid. Valid values are {}".format(PERIODS)
)
params = {
"channel": channel,
"cursor": cursor,
"game": game,
"language": language,
"limit": limit,
<|code_end|>
. Use current file imports:
(from twitch.api.base import TwitchAPI
from twitch.constants import PERIODS
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Clip)
and context including class names, function names, or small code snippets from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/constants.py
# PERIODS = [PERIOD_DAY, PERIOD_WEEK, PERIOD_MONTH, PERIOD_ALL]
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Clip(TwitchObject):
# pass
. Output only the next line. | "period": period, |
Here is a snippet: <|code_start|> if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
)
if period not in PERIODS:
raise TwitchAttributeException(
"Period is not valid. Valid values are {}".format(PERIODS)
)
params = {
"channel": channel,
"cursor": cursor,
"game": game,
"language": language,
"limit": limit,
"period": period,
"trending": str(trending).lower(),
}
response = self._request_get("clips/top", params=params)
return [Clip.construct_from(x) for x in response["clips"]]
@oauth_required
def followed(self, limit=10, cursor=None, trending=False):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
)
<|code_end|>
. Write the next line using the current file imports:
from twitch.api.base import TwitchAPI
from twitch.constants import PERIODS
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Clip
and context from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/constants.py
# PERIODS = [PERIOD_DAY, PERIOD_WEEK, PERIOD_MONTH, PERIOD_ALL]
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Clip(TwitchObject):
# pass
, which may include functions, classes, or code. Output only the next line. | params = {"limit": limit, "cursor": cursor, "trending": trending} |
Given the code snippet: <|code_start|> if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
)
if period not in PERIODS:
raise TwitchAttributeException(
"Period is not valid. Valid values are {}".format(PERIODS)
)
params = {
"channel": channel,
"cursor": cursor,
"game": game,
"language": language,
"limit": limit,
"period": period,
"trending": str(trending).lower(),
}
response = self._request_get("clips/top", params=params)
return [Clip.construct_from(x) for x in response["clips"]]
@oauth_required
def followed(self, limit=10, cursor=None, trending=False):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
)
<|code_end|>
, generate the next line using the imports in this file:
from twitch.api.base import TwitchAPI
from twitch.constants import PERIODS
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Clip
and context (functions, classes, or occasionally code) from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/constants.py
# PERIODS = [PERIOD_DAY, PERIOD_WEEK, PERIOD_MONTH, PERIOD_ALL]
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Clip(TwitchObject):
# pass
. Output only the next line. | params = {"limit": limit, "cursor": cursor, "trending": trending} |
Given the code snippet: <|code_start|>def test_convert_to_twitch_object_output_returns_list_for_list_input():
data = ["squarepants", "patrick", "star"]
result = convert_to_twitch_object("spongebob", data)
assert isinstance(result, list)
def test_convert_to_twitch_object_output_returns_list_of_objects_for_list_of_objects_input():
data = [{"spongebob": "squarepants"}, {"patrick": "star"}]
result = convert_to_twitch_object("channel", data)
assert isinstance(result, list)
assert isinstance(result[0], Channel)
assert result[0] == data[0]
@pytest.mark.parametrize(
"name,data,expected_type",
[
("channel", {"spongebob": "squarepants"}, Channel),
("videos", {"spongebob": "squarepants"}, Video),
("user", {"spongebob": "squarepants"}, User),
("game", {"spongebob": "squarepants"}, Game),
("stream", {"spongebob": "squarepants"}, Stream),
("comments", {"spongebob": "squarepants"}, Comment),
("owner", {"spongebob": "squarepants"}, User),
],
)
def test_convert_to_twitch_object_output_returns_correct_object(
name, data, expected_type
):
result = convert_to_twitch_object(name, data)
<|code_end|>
, generate the next line using the imports in this file:
from datetime import datetime
from twitch.resources import (
Channel,
Comment,
Community,
Featured,
Follow,
Game,
Ingest,
Stream,
StreamMetadata,
Subscription,
Team,
TopGame,
TwitchObject,
User,
UserBlock,
Video,
convert_to_twitch_object,
)
import pytest
and context (functions, classes, or occasionally code) from other files:
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Comment(TwitchObject):
# pass
#
# class Community(TwitchObject):
# pass
#
# class Featured(TwitchObject):
# pass
#
# class Follow(TwitchObject):
# pass
#
# class Game(TwitchObject):
# pass
#
# class Ingest(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
#
# class StreamMetadata(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class Team(TwitchObject):
# pass
#
# class TopGame(TwitchObject):
# pass
#
# class TwitchObject(dict):
# def __setattr__(self, name, value):
# if name[0] == "_" or name in self.__dict__:
# return super(TwitchObject, self).__setattr__(name, value)
#
# self[name] = value
#
# def __getattr__(self, name):
# return self[name]
#
# def __delattr__(self, name):
# if name[0] == "_":
# return super(TwitchObject, self).__delattr__(name)
#
# del self[name]
#
# def __setitem__(self, key, value):
# key = key.lstrip("_")
# super(TwitchObject, self).__setitem__(key, value)
#
# @classmethod
# def construct_from(cls, values):
# instance = cls()
# instance.refresh_from(values)
# return instance
#
# def refresh_from(self, values):
# for key, value in values.copy().items():
# self.__setitem__(key, convert_to_twitch_object(key, value))
#
# class User(TwitchObject):
# pass
#
# class UserBlock(TwitchObject):
# pass
#
# class Video(TwitchObject):
# pass
#
# def convert_to_twitch_object(name, data):
# types = {
# "channel": Channel,
# "videos": Video,
# "user": User,
# "game": Game,
# "stream": Stream,
# "comments": Comment,
# "owner": User,
# }
#
# special_types = {
# "created_at": _DateTime,
# "updated_at": _DateTime,
# "published_at": _DateTime,
# "started_at": _DateTime,
# "followed_at": _DateTime,
# }
#
# if isinstance(data, list):
# return [convert_to_twitch_object(name, x) for x in data]
#
# if name in special_types:
# obj = special_types.get(name)
# return obj.construct_from(data)
#
# if isinstance(data, dict) and name in types:
# obj = types.get(name)
# return obj.construct_from(data)
#
# return data
. Output only the next line. | assert isinstance(result, expected_type) |
Given the code snippet: <|code_start|> assert obj.spongebob == value
del obj.spongebob
assert "spongebob" not in obj
assert "spongebob" not in obj.__dict__
def test_prefixed_attributes_are_stored_on_the_object(self):
obj = TwitchObject()
value = "spongebob"
obj._spongebob = value
obj._spongebob
getattr(obj, "_spongebob")
assert "spongebob" not in obj
assert "_spongebob" not in obj
assert "_spongebob" in obj.__dict__
assert obj._spongebob == value
del obj._spongebob
assert "spongebob" not in obj
assert "spongebob" not in obj.__dict__
def test_setitem_sets_item_to_dict(self):
obj = TwitchObject()
value = "squarepants"
obj["spongebob"] = value
assert obj["spongebob"] == value
<|code_end|>
, generate the next line using the imports in this file:
from datetime import datetime
from twitch.resources import (
Channel,
Comment,
Community,
Featured,
Follow,
Game,
Ingest,
Stream,
StreamMetadata,
Subscription,
Team,
TopGame,
TwitchObject,
User,
UserBlock,
Video,
convert_to_twitch_object,
)
import pytest
and context (functions, classes, or occasionally code) from other files:
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Comment(TwitchObject):
# pass
#
# class Community(TwitchObject):
# pass
#
# class Featured(TwitchObject):
# pass
#
# class Follow(TwitchObject):
# pass
#
# class Game(TwitchObject):
# pass
#
# class Ingest(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
#
# class StreamMetadata(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class Team(TwitchObject):
# pass
#
# class TopGame(TwitchObject):
# pass
#
# class TwitchObject(dict):
# def __setattr__(self, name, value):
# if name[0] == "_" or name in self.__dict__:
# return super(TwitchObject, self).__setattr__(name, value)
#
# self[name] = value
#
# def __getattr__(self, name):
# return self[name]
#
# def __delattr__(self, name):
# if name[0] == "_":
# return super(TwitchObject, self).__delattr__(name)
#
# del self[name]
#
# def __setitem__(self, key, value):
# key = key.lstrip("_")
# super(TwitchObject, self).__setitem__(key, value)
#
# @classmethod
# def construct_from(cls, values):
# instance = cls()
# instance.refresh_from(values)
# return instance
#
# def refresh_from(self, values):
# for key, value in values.copy().items():
# self.__setitem__(key, convert_to_twitch_object(key, value))
#
# class User(TwitchObject):
# pass
#
# class UserBlock(TwitchObject):
# pass
#
# class Video(TwitchObject):
# pass
#
# def convert_to_twitch_object(name, data):
# types = {
# "channel": Channel,
# "videos": Video,
# "user": User,
# "game": Game,
# "stream": Stream,
# "comments": Comment,
# "owner": User,
# }
#
# special_types = {
# "created_at": _DateTime,
# "updated_at": _DateTime,
# "published_at": _DateTime,
# "started_at": _DateTime,
# "followed_at": _DateTime,
# }
#
# if isinstance(data, list):
# return [convert_to_twitch_object(name, x) for x in data]
#
# if name in special_types:
# obj = special_types.get(name)
# return obj.construct_from(data)
#
# if isinstance(data, dict) and name in types:
# obj = types.get(name)
# return obj.construct_from(data)
#
# return data
. Output only the next line. | def test_setitem_removes_underscore_prefix(self): |
Using the snippet: <|code_start|> assert "_spongebob" not in obj
assert "_spongebob" in obj.__dict__
assert obj._spongebob == value
del obj._spongebob
assert "spongebob" not in obj
assert "spongebob" not in obj.__dict__
def test_setitem_sets_item_to_dict(self):
obj = TwitchObject()
value = "squarepants"
obj["spongebob"] = value
assert obj["spongebob"] == value
def test_setitem_removes_underscore_prefix(self):
obj = TwitchObject()
value = "squarepants"
obj["_spongebob"] = value
assert obj["spongebob"] == value
assert "_spongebob" not in obj
assert "_spongebob" not in obj.__dict__
def test_construct_form_returns_class_with_set_values(self):
obj = TwitchObject.construct_from({"spongebob": "squarepants"})
assert isinstance(obj, TwitchObject)
assert obj.spongebob == "squarepants"
def test_refresh_from_sets_all_values_to_object(self):
obj = TwitchObject()
<|code_end|>
, determine the next line of code. You have imports:
from datetime import datetime
from twitch.resources import (
Channel,
Comment,
Community,
Featured,
Follow,
Game,
Ingest,
Stream,
StreamMetadata,
Subscription,
Team,
TopGame,
TwitchObject,
User,
UserBlock,
Video,
convert_to_twitch_object,
)
import pytest
and context (class names, function names, or code) available:
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Comment(TwitchObject):
# pass
#
# class Community(TwitchObject):
# pass
#
# class Featured(TwitchObject):
# pass
#
# class Follow(TwitchObject):
# pass
#
# class Game(TwitchObject):
# pass
#
# class Ingest(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
#
# class StreamMetadata(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class Team(TwitchObject):
# pass
#
# class TopGame(TwitchObject):
# pass
#
# class TwitchObject(dict):
# def __setattr__(self, name, value):
# if name[0] == "_" or name in self.__dict__:
# return super(TwitchObject, self).__setattr__(name, value)
#
# self[name] = value
#
# def __getattr__(self, name):
# return self[name]
#
# def __delattr__(self, name):
# if name[0] == "_":
# return super(TwitchObject, self).__delattr__(name)
#
# del self[name]
#
# def __setitem__(self, key, value):
# key = key.lstrip("_")
# super(TwitchObject, self).__setitem__(key, value)
#
# @classmethod
# def construct_from(cls, values):
# instance = cls()
# instance.refresh_from(values)
# return instance
#
# def refresh_from(self, values):
# for key, value in values.copy().items():
# self.__setitem__(key, convert_to_twitch_object(key, value))
#
# class User(TwitchObject):
# pass
#
# class UserBlock(TwitchObject):
# pass
#
# class Video(TwitchObject):
# pass
#
# def convert_to_twitch_object(name, data):
# types = {
# "channel": Channel,
# "videos": Video,
# "user": User,
# "game": Game,
# "stream": Stream,
# "comments": Comment,
# "owner": User,
# }
#
# special_types = {
# "created_at": _DateTime,
# "updated_at": _DateTime,
# "published_at": _DateTime,
# "started_at": _DateTime,
# "followed_at": _DateTime,
# }
#
# if isinstance(data, list):
# return [convert_to_twitch_object(name, x) for x in data]
#
# if name in special_types:
# obj = special_types.get(name)
# return obj.construct_from(data)
#
# if isinstance(data, dict) and name in types:
# obj = types.get(name)
# return obj.construct_from(data)
#
# return data
. Output only the next line. | obj.refresh_from({"spongebob": "squarepants", "patrick": "star", "_id": 1234}) |
Based on the snippet: <|code_start|>
del obj._spongebob
assert "spongebob" not in obj
assert "spongebob" not in obj.__dict__
def test_setitem_sets_item_to_dict(self):
obj = TwitchObject()
value = "squarepants"
obj["spongebob"] = value
assert obj["spongebob"] == value
def test_setitem_removes_underscore_prefix(self):
obj = TwitchObject()
value = "squarepants"
obj["_spongebob"] = value
assert obj["spongebob"] == value
assert "_spongebob" not in obj
assert "_spongebob" not in obj.__dict__
def test_construct_form_returns_class_with_set_values(self):
obj = TwitchObject.construct_from({"spongebob": "squarepants"})
assert isinstance(obj, TwitchObject)
assert obj.spongebob == "squarepants"
def test_refresh_from_sets_all_values_to_object(self):
obj = TwitchObject()
obj.refresh_from({"spongebob": "squarepants", "patrick": "star", "_id": 1234})
assert obj.spongebob == "squarepants"
<|code_end|>
, predict the immediate next line with the help of imports:
from datetime import datetime
from twitch.resources import (
Channel,
Comment,
Community,
Featured,
Follow,
Game,
Ingest,
Stream,
StreamMetadata,
Subscription,
Team,
TopGame,
TwitchObject,
User,
UserBlock,
Video,
convert_to_twitch_object,
)
import pytest
and context (classes, functions, sometimes code) from other files:
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Comment(TwitchObject):
# pass
#
# class Community(TwitchObject):
# pass
#
# class Featured(TwitchObject):
# pass
#
# class Follow(TwitchObject):
# pass
#
# class Game(TwitchObject):
# pass
#
# class Ingest(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
#
# class StreamMetadata(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class Team(TwitchObject):
# pass
#
# class TopGame(TwitchObject):
# pass
#
# class TwitchObject(dict):
# def __setattr__(self, name, value):
# if name[0] == "_" or name in self.__dict__:
# return super(TwitchObject, self).__setattr__(name, value)
#
# self[name] = value
#
# def __getattr__(self, name):
# return self[name]
#
# def __delattr__(self, name):
# if name[0] == "_":
# return super(TwitchObject, self).__delattr__(name)
#
# del self[name]
#
# def __setitem__(self, key, value):
# key = key.lstrip("_")
# super(TwitchObject, self).__setitem__(key, value)
#
# @classmethod
# def construct_from(cls, values):
# instance = cls()
# instance.refresh_from(values)
# return instance
#
# def refresh_from(self, values):
# for key, value in values.copy().items():
# self.__setitem__(key, convert_to_twitch_object(key, value))
#
# class User(TwitchObject):
# pass
#
# class UserBlock(TwitchObject):
# pass
#
# class Video(TwitchObject):
# pass
#
# def convert_to_twitch_object(name, data):
# types = {
# "channel": Channel,
# "videos": Video,
# "user": User,
# "game": Game,
# "stream": Stream,
# "comments": Comment,
# "owner": User,
# }
#
# special_types = {
# "created_at": _DateTime,
# "updated_at": _DateTime,
# "published_at": _DateTime,
# "started_at": _DateTime,
# "followed_at": _DateTime,
# }
#
# if isinstance(data, list):
# return [convert_to_twitch_object(name, x) for x in data]
#
# if name in special_types:
# obj = special_types.get(name)
# return obj.construct_from(data)
#
# if isinstance(data, dict) and name in types:
# obj = types.get(name)
# return obj.construct_from(data)
#
# return data
. Output only the next line. | assert obj["patrick"] == "star" |
Next line prediction: <|code_start|>def test_convert_to_twitch_object_output_returns_string_for_string_input():
data = "squarepants"
result = convert_to_twitch_object("spongebob", data)
assert result == data
def test_convert_to_twitch_object_output_returns_list_for_list_input():
data = ["squarepants", "patrick", "star"]
result = convert_to_twitch_object("spongebob", data)
assert isinstance(result, list)
def test_convert_to_twitch_object_output_returns_list_of_objects_for_list_of_objects_input():
data = [{"spongebob": "squarepants"}, {"patrick": "star"}]
result = convert_to_twitch_object("channel", data)
assert isinstance(result, list)
assert isinstance(result[0], Channel)
assert result[0] == data[0]
@pytest.mark.parametrize(
"name,data,expected_type",
[
("channel", {"spongebob": "squarepants"}, Channel),
("videos", {"spongebob": "squarepants"}, Video),
("user", {"spongebob": "squarepants"}, User),
("game", {"spongebob": "squarepants"}, Game),
("stream", {"spongebob": "squarepants"}, Stream),
("comments", {"spongebob": "squarepants"}, Comment),
("owner", {"spongebob": "squarepants"}, User),
<|code_end|>
. Use current file imports:
(from datetime import datetime
from twitch.resources import (
Channel,
Comment,
Community,
Featured,
Follow,
Game,
Ingest,
Stream,
StreamMetadata,
Subscription,
Team,
TopGame,
TwitchObject,
User,
UserBlock,
Video,
convert_to_twitch_object,
)
import pytest)
and context including class names, function names, or small code snippets from other files:
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Comment(TwitchObject):
# pass
#
# class Community(TwitchObject):
# pass
#
# class Featured(TwitchObject):
# pass
#
# class Follow(TwitchObject):
# pass
#
# class Game(TwitchObject):
# pass
#
# class Ingest(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
#
# class StreamMetadata(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class Team(TwitchObject):
# pass
#
# class TopGame(TwitchObject):
# pass
#
# class TwitchObject(dict):
# def __setattr__(self, name, value):
# if name[0] == "_" or name in self.__dict__:
# return super(TwitchObject, self).__setattr__(name, value)
#
# self[name] = value
#
# def __getattr__(self, name):
# return self[name]
#
# def __delattr__(self, name):
# if name[0] == "_":
# return super(TwitchObject, self).__delattr__(name)
#
# del self[name]
#
# def __setitem__(self, key, value):
# key = key.lstrip("_")
# super(TwitchObject, self).__setitem__(key, value)
#
# @classmethod
# def construct_from(cls, values):
# instance = cls()
# instance.refresh_from(values)
# return instance
#
# def refresh_from(self, values):
# for key, value in values.copy().items():
# self.__setitem__(key, convert_to_twitch_object(key, value))
#
# class User(TwitchObject):
# pass
#
# class UserBlock(TwitchObject):
# pass
#
# class Video(TwitchObject):
# pass
#
# def convert_to_twitch_object(name, data):
# types = {
# "channel": Channel,
# "videos": Video,
# "user": User,
# "game": Game,
# "stream": Stream,
# "comments": Comment,
# "owner": User,
# }
#
# special_types = {
# "created_at": _DateTime,
# "updated_at": _DateTime,
# "published_at": _DateTime,
# "started_at": _DateTime,
# "followed_at": _DateTime,
# }
#
# if isinstance(data, list):
# return [convert_to_twitch_object(name, x) for x in data]
#
# if name in special_types:
# obj = special_types.get(name)
# return obj.construct_from(data)
#
# if isinstance(data, dict) and name in types:
# obj = types.get(name)
# return obj.construct_from(data)
#
# return data
. Output only the next line. | ], |
Given snippet: <|code_start|> assert "spongebob" not in obj.__dict__
def test_prefixed_attributes_are_stored_on_the_object(self):
obj = TwitchObject()
value = "spongebob"
obj._spongebob = value
obj._spongebob
getattr(obj, "_spongebob")
assert "spongebob" not in obj
assert "_spongebob" not in obj
assert "_spongebob" in obj.__dict__
assert obj._spongebob == value
del obj._spongebob
assert "spongebob" not in obj
assert "spongebob" not in obj.__dict__
def test_setitem_sets_item_to_dict(self):
obj = TwitchObject()
value = "squarepants"
obj["spongebob"] = value
assert obj["spongebob"] == value
def test_setitem_removes_underscore_prefix(self):
obj = TwitchObject()
value = "squarepants"
obj["_spongebob"] = value
assert obj["spongebob"] == value
<|code_end|>
, continue by predicting the next line. Consider current file imports:
from datetime import datetime
from twitch.resources import (
Channel,
Comment,
Community,
Featured,
Follow,
Game,
Ingest,
Stream,
StreamMetadata,
Subscription,
Team,
TopGame,
TwitchObject,
User,
UserBlock,
Video,
convert_to_twitch_object,
)
import pytest
and context:
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Comment(TwitchObject):
# pass
#
# class Community(TwitchObject):
# pass
#
# class Featured(TwitchObject):
# pass
#
# class Follow(TwitchObject):
# pass
#
# class Game(TwitchObject):
# pass
#
# class Ingest(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
#
# class StreamMetadata(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class Team(TwitchObject):
# pass
#
# class TopGame(TwitchObject):
# pass
#
# class TwitchObject(dict):
# def __setattr__(self, name, value):
# if name[0] == "_" or name in self.__dict__:
# return super(TwitchObject, self).__setattr__(name, value)
#
# self[name] = value
#
# def __getattr__(self, name):
# return self[name]
#
# def __delattr__(self, name):
# if name[0] == "_":
# return super(TwitchObject, self).__delattr__(name)
#
# del self[name]
#
# def __setitem__(self, key, value):
# key = key.lstrip("_")
# super(TwitchObject, self).__setitem__(key, value)
#
# @classmethod
# def construct_from(cls, values):
# instance = cls()
# instance.refresh_from(values)
# return instance
#
# def refresh_from(self, values):
# for key, value in values.copy().items():
# self.__setitem__(key, convert_to_twitch_object(key, value))
#
# class User(TwitchObject):
# pass
#
# class UserBlock(TwitchObject):
# pass
#
# class Video(TwitchObject):
# pass
#
# def convert_to_twitch_object(name, data):
# types = {
# "channel": Channel,
# "videos": Video,
# "user": User,
# "game": Game,
# "stream": Stream,
# "comments": Comment,
# "owner": User,
# }
#
# special_types = {
# "created_at": _DateTime,
# "updated_at": _DateTime,
# "published_at": _DateTime,
# "started_at": _DateTime,
# "followed_at": _DateTime,
# }
#
# if isinstance(data, list):
# return [convert_to_twitch_object(name, x) for x in data]
#
# if name in special_types:
# obj = special_types.get(name)
# return obj.construct_from(data)
#
# if isinstance(data, dict) and name in types:
# obj = types.get(name)
# return obj.construct_from(data)
#
# return data
which might include code, classes, or functions. Output only the next line. | assert "_spongebob" not in obj |
Given the following code snippet before the placeholder: <|code_start|> "name,data,expected_type",
[
("channel", {"spongebob": "squarepants"}, Channel),
("videos", {"spongebob": "squarepants"}, Video),
("user", {"spongebob": "squarepants"}, User),
("game", {"spongebob": "squarepants"}, Game),
("stream", {"spongebob": "squarepants"}, Stream),
("comments", {"spongebob": "squarepants"}, Comment),
("owner", {"spongebob": "squarepants"}, User),
],
)
def test_convert_to_twitch_object_output_returns_correct_object(
name, data, expected_type
):
result = convert_to_twitch_object(name, data)
assert isinstance(result, expected_type)
assert result == data
@pytest.mark.parametrize(
"name,data,expected",
[
("created_at", "2016-11-29T15:52:27Z", datetime(2016, 11, 29, 15, 52, 27)),
(
"updated_at",
"2017-03-06T18:40:51.855Z",
datetime(2017, 3, 6, 18, 40, 51, 855000),
),
("published_at", "2017-02-14T22:27:54Z", datetime(2017, 2, 14, 22, 27, 54)),
("published_at", None, None),
<|code_end|>
, predict the next line using imports from the current file:
from datetime import datetime
from twitch.resources import (
Channel,
Comment,
Community,
Featured,
Follow,
Game,
Ingest,
Stream,
StreamMetadata,
Subscription,
Team,
TopGame,
TwitchObject,
User,
UserBlock,
Video,
convert_to_twitch_object,
)
import pytest
and context including class names, function names, and sometimes code from other files:
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Comment(TwitchObject):
# pass
#
# class Community(TwitchObject):
# pass
#
# class Featured(TwitchObject):
# pass
#
# class Follow(TwitchObject):
# pass
#
# class Game(TwitchObject):
# pass
#
# class Ingest(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
#
# class StreamMetadata(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class Team(TwitchObject):
# pass
#
# class TopGame(TwitchObject):
# pass
#
# class TwitchObject(dict):
# def __setattr__(self, name, value):
# if name[0] == "_" or name in self.__dict__:
# return super(TwitchObject, self).__setattr__(name, value)
#
# self[name] = value
#
# def __getattr__(self, name):
# return self[name]
#
# def __delattr__(self, name):
# if name[0] == "_":
# return super(TwitchObject, self).__delattr__(name)
#
# del self[name]
#
# def __setitem__(self, key, value):
# key = key.lstrip("_")
# super(TwitchObject, self).__setitem__(key, value)
#
# @classmethod
# def construct_from(cls, values):
# instance = cls()
# instance.refresh_from(values)
# return instance
#
# def refresh_from(self, values):
# for key, value in values.copy().items():
# self.__setitem__(key, convert_to_twitch_object(key, value))
#
# class User(TwitchObject):
# pass
#
# class UserBlock(TwitchObject):
# pass
#
# class Video(TwitchObject):
# pass
#
# def convert_to_twitch_object(name, data):
# types = {
# "channel": Channel,
# "videos": Video,
# "user": User,
# "game": Game,
# "stream": Stream,
# "comments": Comment,
# "owner": User,
# }
#
# special_types = {
# "created_at": _DateTime,
# "updated_at": _DateTime,
# "published_at": _DateTime,
# "started_at": _DateTime,
# "followed_at": _DateTime,
# }
#
# if isinstance(data, list):
# return [convert_to_twitch_object(name, x) for x in data]
#
# if name in special_types:
# obj = special_types.get(name)
# return obj.construct_from(data)
#
# if isinstance(data, dict) and name in types:
# obj = types.get(name)
# return obj.construct_from(data)
#
# return data
. Output only the next line. | ], |
Predict the next line after this snippet: <|code_start|> name, data, expected_type
):
result = convert_to_twitch_object(name, data)
assert isinstance(result, expected_type)
assert result == data
@pytest.mark.parametrize(
"name,data,expected",
[
("created_at", "2016-11-29T15:52:27Z", datetime(2016, 11, 29, 15, 52, 27)),
(
"updated_at",
"2017-03-06T18:40:51.855Z",
datetime(2017, 3, 6, 18, 40, 51, 855000),
),
("published_at", "2017-02-14T22:27:54Z", datetime(2017, 2, 14, 22, 27, 54)),
("published_at", None, None),
],
)
def test_datetimes_are_converted_correctly_to_datetime_objects(name, data, expected):
result = convert_to_twitch_object(name, data)
if result is not None:
assert isinstance(result, datetime)
assert result == expected
class TestTwitchObject(object):
def test_attributes_are_stored_and_fetched_from_dict(self):
obj = TwitchObject()
<|code_end|>
using the current file's imports:
from datetime import datetime
from twitch.resources import (
Channel,
Comment,
Community,
Featured,
Follow,
Game,
Ingest,
Stream,
StreamMetadata,
Subscription,
Team,
TopGame,
TwitchObject,
User,
UserBlock,
Video,
convert_to_twitch_object,
)
import pytest
and any relevant context from other files:
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Comment(TwitchObject):
# pass
#
# class Community(TwitchObject):
# pass
#
# class Featured(TwitchObject):
# pass
#
# class Follow(TwitchObject):
# pass
#
# class Game(TwitchObject):
# pass
#
# class Ingest(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
#
# class StreamMetadata(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class Team(TwitchObject):
# pass
#
# class TopGame(TwitchObject):
# pass
#
# class TwitchObject(dict):
# def __setattr__(self, name, value):
# if name[0] == "_" or name in self.__dict__:
# return super(TwitchObject, self).__setattr__(name, value)
#
# self[name] = value
#
# def __getattr__(self, name):
# return self[name]
#
# def __delattr__(self, name):
# if name[0] == "_":
# return super(TwitchObject, self).__delattr__(name)
#
# del self[name]
#
# def __setitem__(self, key, value):
# key = key.lstrip("_")
# super(TwitchObject, self).__setitem__(key, value)
#
# @classmethod
# def construct_from(cls, values):
# instance = cls()
# instance.refresh_from(values)
# return instance
#
# def refresh_from(self, values):
# for key, value in values.copy().items():
# self.__setitem__(key, convert_to_twitch_object(key, value))
#
# class User(TwitchObject):
# pass
#
# class UserBlock(TwitchObject):
# pass
#
# class Video(TwitchObject):
# pass
#
# def convert_to_twitch_object(name, data):
# types = {
# "channel": Channel,
# "videos": Video,
# "user": User,
# "game": Game,
# "stream": Stream,
# "comments": Comment,
# "owner": User,
# }
#
# special_types = {
# "created_at": _DateTime,
# "updated_at": _DateTime,
# "published_at": _DateTime,
# "started_at": _DateTime,
# "followed_at": _DateTime,
# }
#
# if isinstance(data, list):
# return [convert_to_twitch_object(name, x) for x in data]
#
# if name in special_types:
# obj = special_types.get(name)
# return obj.construct_from(data)
#
# if isinstance(data, dict) and name in types:
# obj = types.get(name)
# return obj.construct_from(data)
#
# return data
. Output only the next line. | value = "spongebob" |
Based on the snippet: <|code_start|>def test_datetimes_are_converted_correctly_to_datetime_objects(name, data, expected):
result = convert_to_twitch_object(name, data)
if result is not None:
assert isinstance(result, datetime)
assert result == expected
class TestTwitchObject(object):
def test_attributes_are_stored_and_fetched_from_dict(self):
obj = TwitchObject()
value = "spongebob"
obj.spongebob = value
assert "spongebob" in obj
assert "_spongebob" not in obj.__dict__
assert "spongebob" not in obj.__dict__
assert obj["spongebob"] == value
assert obj.spongebob == value
del obj.spongebob
assert "spongebob" not in obj
assert "spongebob" not in obj.__dict__
def test_prefixed_attributes_are_stored_on_the_object(self):
obj = TwitchObject()
value = "spongebob"
obj._spongebob = value
obj._spongebob
<|code_end|>
, predict the immediate next line with the help of imports:
from datetime import datetime
from twitch.resources import (
Channel,
Comment,
Community,
Featured,
Follow,
Game,
Ingest,
Stream,
StreamMetadata,
Subscription,
Team,
TopGame,
TwitchObject,
User,
UserBlock,
Video,
convert_to_twitch_object,
)
import pytest
and context (classes, functions, sometimes code) from other files:
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Comment(TwitchObject):
# pass
#
# class Community(TwitchObject):
# pass
#
# class Featured(TwitchObject):
# pass
#
# class Follow(TwitchObject):
# pass
#
# class Game(TwitchObject):
# pass
#
# class Ingest(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
#
# class StreamMetadata(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class Team(TwitchObject):
# pass
#
# class TopGame(TwitchObject):
# pass
#
# class TwitchObject(dict):
# def __setattr__(self, name, value):
# if name[0] == "_" or name in self.__dict__:
# return super(TwitchObject, self).__setattr__(name, value)
#
# self[name] = value
#
# def __getattr__(self, name):
# return self[name]
#
# def __delattr__(self, name):
# if name[0] == "_":
# return super(TwitchObject, self).__delattr__(name)
#
# del self[name]
#
# def __setitem__(self, key, value):
# key = key.lstrip("_")
# super(TwitchObject, self).__setitem__(key, value)
#
# @classmethod
# def construct_from(cls, values):
# instance = cls()
# instance.refresh_from(values)
# return instance
#
# def refresh_from(self, values):
# for key, value in values.copy().items():
# self.__setitem__(key, convert_to_twitch_object(key, value))
#
# class User(TwitchObject):
# pass
#
# class UserBlock(TwitchObject):
# pass
#
# class Video(TwitchObject):
# pass
#
# def convert_to_twitch_object(name, data):
# types = {
# "channel": Channel,
# "videos": Video,
# "user": User,
# "game": Game,
# "stream": Stream,
# "comments": Comment,
# "owner": User,
# }
#
# special_types = {
# "created_at": _DateTime,
# "updated_at": _DateTime,
# "published_at": _DateTime,
# "started_at": _DateTime,
# "followed_at": _DateTime,
# }
#
# if isinstance(data, list):
# return [convert_to_twitch_object(name, x) for x in data]
#
# if name in special_types:
# obj = special_types.get(name)
# return obj.construct_from(data)
#
# if isinstance(data, dict) and name in types:
# obj = types.get(name)
# return obj.construct_from(data)
#
# return data
. Output only the next line. | getattr(obj, "_spongebob") |
Next line prediction: <|code_start|> (
"updated_at",
"2017-03-06T18:40:51.855Z",
datetime(2017, 3, 6, 18, 40, 51, 855000),
),
("published_at", "2017-02-14T22:27:54Z", datetime(2017, 2, 14, 22, 27, 54)),
("published_at", None, None),
],
)
def test_datetimes_are_converted_correctly_to_datetime_objects(name, data, expected):
result = convert_to_twitch_object(name, data)
if result is not None:
assert isinstance(result, datetime)
assert result == expected
class TestTwitchObject(object):
def test_attributes_are_stored_and_fetched_from_dict(self):
obj = TwitchObject()
value = "spongebob"
obj.spongebob = value
assert "spongebob" in obj
assert "_spongebob" not in obj.__dict__
assert "spongebob" not in obj.__dict__
assert obj["spongebob"] == value
assert obj.spongebob == value
del obj.spongebob
<|code_end|>
. Use current file imports:
(from datetime import datetime
from twitch.resources import (
Channel,
Comment,
Community,
Featured,
Follow,
Game,
Ingest,
Stream,
StreamMetadata,
Subscription,
Team,
TopGame,
TwitchObject,
User,
UserBlock,
Video,
convert_to_twitch_object,
)
import pytest)
and context including class names, function names, or small code snippets from other files:
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Comment(TwitchObject):
# pass
#
# class Community(TwitchObject):
# pass
#
# class Featured(TwitchObject):
# pass
#
# class Follow(TwitchObject):
# pass
#
# class Game(TwitchObject):
# pass
#
# class Ingest(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
#
# class StreamMetadata(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class Team(TwitchObject):
# pass
#
# class TopGame(TwitchObject):
# pass
#
# class TwitchObject(dict):
# def __setattr__(self, name, value):
# if name[0] == "_" or name in self.__dict__:
# return super(TwitchObject, self).__setattr__(name, value)
#
# self[name] = value
#
# def __getattr__(self, name):
# return self[name]
#
# def __delattr__(self, name):
# if name[0] == "_":
# return super(TwitchObject, self).__delattr__(name)
#
# del self[name]
#
# def __setitem__(self, key, value):
# key = key.lstrip("_")
# super(TwitchObject, self).__setitem__(key, value)
#
# @classmethod
# def construct_from(cls, values):
# instance = cls()
# instance.refresh_from(values)
# return instance
#
# def refresh_from(self, values):
# for key, value in values.copy().items():
# self.__setitem__(key, convert_to_twitch_object(key, value))
#
# class User(TwitchObject):
# pass
#
# class UserBlock(TwitchObject):
# pass
#
# class Video(TwitchObject):
# pass
#
# def convert_to_twitch_object(name, data):
# types = {
# "channel": Channel,
# "videos": Video,
# "user": User,
# "game": Game,
# "stream": Stream,
# "comments": Comment,
# "owner": User,
# }
#
# special_types = {
# "created_at": _DateTime,
# "updated_at": _DateTime,
# "published_at": _DateTime,
# "started_at": _DateTime,
# "followed_at": _DateTime,
# }
#
# if isinstance(data, list):
# return [convert_to_twitch_object(name, x) for x in data]
#
# if name in special_types:
# obj = special_types.get(name)
# return obj.construct_from(data)
#
# if isinstance(data, dict) and name in types:
# obj = types.get(name)
# return obj.construct_from(data)
#
# return data
. Output only the next line. | assert "spongebob" not in obj |
Given the following code snippet before the placeholder: <|code_start|>
def test_convert_to_twitch_object_output_returns_string_for_string_input():
data = "squarepants"
result = convert_to_twitch_object("spongebob", data)
<|code_end|>
, predict the next line using imports from the current file:
from datetime import datetime
from twitch.resources import (
Channel,
Comment,
Community,
Featured,
Follow,
Game,
Ingest,
Stream,
StreamMetadata,
Subscription,
Team,
TopGame,
TwitchObject,
User,
UserBlock,
Video,
convert_to_twitch_object,
)
import pytest
and context including class names, function names, and sometimes code from other files:
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Comment(TwitchObject):
# pass
#
# class Community(TwitchObject):
# pass
#
# class Featured(TwitchObject):
# pass
#
# class Follow(TwitchObject):
# pass
#
# class Game(TwitchObject):
# pass
#
# class Ingest(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
#
# class StreamMetadata(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class Team(TwitchObject):
# pass
#
# class TopGame(TwitchObject):
# pass
#
# class TwitchObject(dict):
# def __setattr__(self, name, value):
# if name[0] == "_" or name in self.__dict__:
# return super(TwitchObject, self).__setattr__(name, value)
#
# self[name] = value
#
# def __getattr__(self, name):
# return self[name]
#
# def __delattr__(self, name):
# if name[0] == "_":
# return super(TwitchObject, self).__delattr__(name)
#
# del self[name]
#
# def __setitem__(self, key, value):
# key = key.lstrip("_")
# super(TwitchObject, self).__setitem__(key, value)
#
# @classmethod
# def construct_from(cls, values):
# instance = cls()
# instance.refresh_from(values)
# return instance
#
# def refresh_from(self, values):
# for key, value in values.copy().items():
# self.__setitem__(key, convert_to_twitch_object(key, value))
#
# class User(TwitchObject):
# pass
#
# class UserBlock(TwitchObject):
# pass
#
# class Video(TwitchObject):
# pass
#
# def convert_to_twitch_object(name, data):
# types = {
# "channel": Channel,
# "videos": Video,
# "user": User,
# "game": Game,
# "stream": Stream,
# "comments": Comment,
# "owner": User,
# }
#
# special_types = {
# "created_at": _DateTime,
# "updated_at": _DateTime,
# "published_at": _DateTime,
# "started_at": _DateTime,
# "followed_at": _DateTime,
# }
#
# if isinstance(data, list):
# return [convert_to_twitch_object(name, x) for x in data]
#
# if name in special_types:
# obj = special_types.get(name)
# return obj.construct_from(data)
#
# if isinstance(data, dict) and name in types:
# obj = types.get(name)
# return obj.construct_from(data)
#
# return data
. Output only the next line. | assert result == data |
Based on the snippet: <|code_start|> assert isinstance(result, datetime)
assert result == expected
class TestTwitchObject(object):
def test_attributes_are_stored_and_fetched_from_dict(self):
obj = TwitchObject()
value = "spongebob"
obj.spongebob = value
assert "spongebob" in obj
assert "_spongebob" not in obj.__dict__
assert "spongebob" not in obj.__dict__
assert obj["spongebob"] == value
assert obj.spongebob == value
del obj.spongebob
assert "spongebob" not in obj
assert "spongebob" not in obj.__dict__
def test_prefixed_attributes_are_stored_on_the_object(self):
obj = TwitchObject()
value = "spongebob"
obj._spongebob = value
obj._spongebob
getattr(obj, "_spongebob")
assert "spongebob" not in obj
assert "_spongebob" not in obj
<|code_end|>
, predict the immediate next line with the help of imports:
from datetime import datetime
from twitch.resources import (
Channel,
Comment,
Community,
Featured,
Follow,
Game,
Ingest,
Stream,
StreamMetadata,
Subscription,
Team,
TopGame,
TwitchObject,
User,
UserBlock,
Video,
convert_to_twitch_object,
)
import pytest
and context (classes, functions, sometimes code) from other files:
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Comment(TwitchObject):
# pass
#
# class Community(TwitchObject):
# pass
#
# class Featured(TwitchObject):
# pass
#
# class Follow(TwitchObject):
# pass
#
# class Game(TwitchObject):
# pass
#
# class Ingest(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
#
# class StreamMetadata(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class Team(TwitchObject):
# pass
#
# class TopGame(TwitchObject):
# pass
#
# class TwitchObject(dict):
# def __setattr__(self, name, value):
# if name[0] == "_" or name in self.__dict__:
# return super(TwitchObject, self).__setattr__(name, value)
#
# self[name] = value
#
# def __getattr__(self, name):
# return self[name]
#
# def __delattr__(self, name):
# if name[0] == "_":
# return super(TwitchObject, self).__delattr__(name)
#
# del self[name]
#
# def __setitem__(self, key, value):
# key = key.lstrip("_")
# super(TwitchObject, self).__setitem__(key, value)
#
# @classmethod
# def construct_from(cls, values):
# instance = cls()
# instance.refresh_from(values)
# return instance
#
# def refresh_from(self, values):
# for key, value in values.copy().items():
# self.__setitem__(key, convert_to_twitch_object(key, value))
#
# class User(TwitchObject):
# pass
#
# class UserBlock(TwitchObject):
# pass
#
# class Video(TwitchObject):
# pass
#
# def convert_to_twitch_object(name, data):
# types = {
# "channel": Channel,
# "videos": Video,
# "user": User,
# "game": Game,
# "stream": Stream,
# "comments": Comment,
# "owner": User,
# }
#
# special_types = {
# "created_at": _DateTime,
# "updated_at": _DateTime,
# "published_at": _DateTime,
# "started_at": _DateTime,
# "followed_at": _DateTime,
# }
#
# if isinstance(data, list):
# return [convert_to_twitch_object(name, x) for x in data]
#
# if name in special_types:
# obj = special_types.get(name)
# return obj.construct_from(data)
#
# if isinstance(data, dict) and name in types:
# obj = types.get(name)
# return obj.construct_from(data)
#
# return data
. Output only the next line. | assert "_spongebob" in obj.__dict__ |
Based on the snippet: <|code_start|>def test_convert_to_twitch_object_output_returns_list_for_list_input():
data = ["squarepants", "patrick", "star"]
result = convert_to_twitch_object("spongebob", data)
assert isinstance(result, list)
def test_convert_to_twitch_object_output_returns_list_of_objects_for_list_of_objects_input():
data = [{"spongebob": "squarepants"}, {"patrick": "star"}]
result = convert_to_twitch_object("channel", data)
assert isinstance(result, list)
assert isinstance(result[0], Channel)
assert result[0] == data[0]
@pytest.mark.parametrize(
"name,data,expected_type",
[
("channel", {"spongebob": "squarepants"}, Channel),
("videos", {"spongebob": "squarepants"}, Video),
("user", {"spongebob": "squarepants"}, User),
("game", {"spongebob": "squarepants"}, Game),
("stream", {"spongebob": "squarepants"}, Stream),
("comments", {"spongebob": "squarepants"}, Comment),
("owner", {"spongebob": "squarepants"}, User),
],
)
def test_convert_to_twitch_object_output_returns_correct_object(
name, data, expected_type
):
result = convert_to_twitch_object(name, data)
<|code_end|>
, predict the immediate next line with the help of imports:
from datetime import datetime
from twitch.resources import (
Channel,
Comment,
Community,
Featured,
Follow,
Game,
Ingest,
Stream,
StreamMetadata,
Subscription,
Team,
TopGame,
TwitchObject,
User,
UserBlock,
Video,
convert_to_twitch_object,
)
import pytest
and context (classes, functions, sometimes code) from other files:
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Comment(TwitchObject):
# pass
#
# class Community(TwitchObject):
# pass
#
# class Featured(TwitchObject):
# pass
#
# class Follow(TwitchObject):
# pass
#
# class Game(TwitchObject):
# pass
#
# class Ingest(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
#
# class StreamMetadata(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class Team(TwitchObject):
# pass
#
# class TopGame(TwitchObject):
# pass
#
# class TwitchObject(dict):
# def __setattr__(self, name, value):
# if name[0] == "_" or name in self.__dict__:
# return super(TwitchObject, self).__setattr__(name, value)
#
# self[name] = value
#
# def __getattr__(self, name):
# return self[name]
#
# def __delattr__(self, name):
# if name[0] == "_":
# return super(TwitchObject, self).__delattr__(name)
#
# del self[name]
#
# def __setitem__(self, key, value):
# key = key.lstrip("_")
# super(TwitchObject, self).__setitem__(key, value)
#
# @classmethod
# def construct_from(cls, values):
# instance = cls()
# instance.refresh_from(values)
# return instance
#
# def refresh_from(self, values):
# for key, value in values.copy().items():
# self.__setitem__(key, convert_to_twitch_object(key, value))
#
# class User(TwitchObject):
# pass
#
# class UserBlock(TwitchObject):
# pass
#
# class Video(TwitchObject):
# pass
#
# def convert_to_twitch_object(name, data):
# types = {
# "channel": Channel,
# "videos": Video,
# "user": User,
# "game": Game,
# "stream": Stream,
# "comments": Comment,
# "owner": User,
# }
#
# special_types = {
# "created_at": _DateTime,
# "updated_at": _DateTime,
# "published_at": _DateTime,
# "started_at": _DateTime,
# "followed_at": _DateTime,
# }
#
# if isinstance(data, list):
# return [convert_to_twitch_object(name, x) for x in data]
#
# if name in special_types:
# obj = special_types.get(name)
# return obj.construct_from(data)
#
# if isinstance(data, dict) and name in types:
# obj = types.get(name)
# return obj.construct_from(data)
#
# return data
. Output only the next line. | assert isinstance(result, expected_type) |
Given snippet: <|code_start|> "name,data,expected_type",
[
("channel", {"spongebob": "squarepants"}, Channel),
("videos", {"spongebob": "squarepants"}, Video),
("user", {"spongebob": "squarepants"}, User),
("game", {"spongebob": "squarepants"}, Game),
("stream", {"spongebob": "squarepants"}, Stream),
("comments", {"spongebob": "squarepants"}, Comment),
("owner", {"spongebob": "squarepants"}, User),
],
)
def test_convert_to_twitch_object_output_returns_correct_object(
name, data, expected_type
):
result = convert_to_twitch_object(name, data)
assert isinstance(result, expected_type)
assert result == data
@pytest.mark.parametrize(
"name,data,expected",
[
("created_at", "2016-11-29T15:52:27Z", datetime(2016, 11, 29, 15, 52, 27)),
(
"updated_at",
"2017-03-06T18:40:51.855Z",
datetime(2017, 3, 6, 18, 40, 51, 855000),
),
("published_at", "2017-02-14T22:27:54Z", datetime(2017, 2, 14, 22, 27, 54)),
("published_at", None, None),
<|code_end|>
, continue by predicting the next line. Consider current file imports:
from datetime import datetime
from twitch.resources import (
Channel,
Comment,
Community,
Featured,
Follow,
Game,
Ingest,
Stream,
StreamMetadata,
Subscription,
Team,
TopGame,
TwitchObject,
User,
UserBlock,
Video,
convert_to_twitch_object,
)
import pytest
and context:
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Comment(TwitchObject):
# pass
#
# class Community(TwitchObject):
# pass
#
# class Featured(TwitchObject):
# pass
#
# class Follow(TwitchObject):
# pass
#
# class Game(TwitchObject):
# pass
#
# class Ingest(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
#
# class StreamMetadata(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class Team(TwitchObject):
# pass
#
# class TopGame(TwitchObject):
# pass
#
# class TwitchObject(dict):
# def __setattr__(self, name, value):
# if name[0] == "_" or name in self.__dict__:
# return super(TwitchObject, self).__setattr__(name, value)
#
# self[name] = value
#
# def __getattr__(self, name):
# return self[name]
#
# def __delattr__(self, name):
# if name[0] == "_":
# return super(TwitchObject, self).__delattr__(name)
#
# del self[name]
#
# def __setitem__(self, key, value):
# key = key.lstrip("_")
# super(TwitchObject, self).__setitem__(key, value)
#
# @classmethod
# def construct_from(cls, values):
# instance = cls()
# instance.refresh_from(values)
# return instance
#
# def refresh_from(self, values):
# for key, value in values.copy().items():
# self.__setitem__(key, convert_to_twitch_object(key, value))
#
# class User(TwitchObject):
# pass
#
# class UserBlock(TwitchObject):
# pass
#
# class Video(TwitchObject):
# pass
#
# def convert_to_twitch_object(name, data):
# types = {
# "channel": Channel,
# "videos": Video,
# "user": User,
# "game": Game,
# "stream": Stream,
# "comments": Comment,
# "owner": User,
# }
#
# special_types = {
# "created_at": _DateTime,
# "updated_at": _DateTime,
# "published_at": _DateTime,
# "started_at": _DateTime,
# "followed_at": _DateTime,
# }
#
# if isinstance(data, list):
# return [convert_to_twitch_object(name, x) for x in data]
#
# if name in special_types:
# obj = special_types.get(name)
# return obj.construct_from(data)
#
# if isinstance(data, dict) and name in types:
# obj = types.get(name)
# return obj.construct_from(data)
#
# return data
which might include code, classes, or functions. Output only the next line. | ], |
Given the following code snippet before the placeholder: <|code_start|> (
"updated_at",
"2017-03-06T18:40:51.855Z",
datetime(2017, 3, 6, 18, 40, 51, 855000),
),
("published_at", "2017-02-14T22:27:54Z", datetime(2017, 2, 14, 22, 27, 54)),
("published_at", None, None),
],
)
def test_datetimes_are_converted_correctly_to_datetime_objects(name, data, expected):
result = convert_to_twitch_object(name, data)
if result is not None:
assert isinstance(result, datetime)
assert result == expected
class TestTwitchObject(object):
def test_attributes_are_stored_and_fetched_from_dict(self):
obj = TwitchObject()
value = "spongebob"
obj.spongebob = value
assert "spongebob" in obj
assert "_spongebob" not in obj.__dict__
assert "spongebob" not in obj.__dict__
assert obj["spongebob"] == value
assert obj.spongebob == value
del obj.spongebob
<|code_end|>
, predict the next line using imports from the current file:
from datetime import datetime
from twitch.resources import (
Channel,
Comment,
Community,
Featured,
Follow,
Game,
Ingest,
Stream,
StreamMetadata,
Subscription,
Team,
TopGame,
TwitchObject,
User,
UserBlock,
Video,
convert_to_twitch_object,
)
import pytest
and context including class names, function names, and sometimes code from other files:
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Comment(TwitchObject):
# pass
#
# class Community(TwitchObject):
# pass
#
# class Featured(TwitchObject):
# pass
#
# class Follow(TwitchObject):
# pass
#
# class Game(TwitchObject):
# pass
#
# class Ingest(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
#
# class StreamMetadata(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class Team(TwitchObject):
# pass
#
# class TopGame(TwitchObject):
# pass
#
# class TwitchObject(dict):
# def __setattr__(self, name, value):
# if name[0] == "_" or name in self.__dict__:
# return super(TwitchObject, self).__setattr__(name, value)
#
# self[name] = value
#
# def __getattr__(self, name):
# return self[name]
#
# def __delattr__(self, name):
# if name[0] == "_":
# return super(TwitchObject, self).__delattr__(name)
#
# del self[name]
#
# def __setitem__(self, key, value):
# key = key.lstrip("_")
# super(TwitchObject, self).__setitem__(key, value)
#
# @classmethod
# def construct_from(cls, values):
# instance = cls()
# instance.refresh_from(values)
# return instance
#
# def refresh_from(self, values):
# for key, value in values.copy().items():
# self.__setitem__(key, convert_to_twitch_object(key, value))
#
# class User(TwitchObject):
# pass
#
# class UserBlock(TwitchObject):
# pass
#
# class Video(TwitchObject):
# pass
#
# def convert_to_twitch_object(name, data):
# types = {
# "channel": Channel,
# "videos": Video,
# "user": User,
# "game": Game,
# "stream": Stream,
# "comments": Comment,
# "owner": User,
# }
#
# special_types = {
# "created_at": _DateTime,
# "updated_at": _DateTime,
# "published_at": _DateTime,
# "started_at": _DateTime,
# "followed_at": _DateTime,
# }
#
# if isinstance(data, list):
# return [convert_to_twitch_object(name, x) for x in data]
#
# if name in special_types:
# obj = special_types.get(name)
# return obj.construct_from(data)
#
# if isinstance(data, dict) and name in types:
# obj = types.get(name)
# return obj.construct_from(data)
#
# return data
. Output only the next line. | assert "spongebob" not in obj |
Using the snippet: <|code_start|>@pytest.mark.parametrize(
"name,data,expected_type",
[
("channel", {"spongebob": "squarepants"}, Channel),
("videos", {"spongebob": "squarepants"}, Video),
("user", {"spongebob": "squarepants"}, User),
("game", {"spongebob": "squarepants"}, Game),
("stream", {"spongebob": "squarepants"}, Stream),
("comments", {"spongebob": "squarepants"}, Comment),
("owner", {"spongebob": "squarepants"}, User),
],
)
def test_convert_to_twitch_object_output_returns_correct_object(
name, data, expected_type
):
result = convert_to_twitch_object(name, data)
assert isinstance(result, expected_type)
assert result == data
@pytest.mark.parametrize(
"name,data,expected",
[
("created_at", "2016-11-29T15:52:27Z", datetime(2016, 11, 29, 15, 52, 27)),
(
"updated_at",
"2017-03-06T18:40:51.855Z",
datetime(2017, 3, 6, 18, 40, 51, 855000),
),
("published_at", "2017-02-14T22:27:54Z", datetime(2017, 2, 14, 22, 27, 54)),
<|code_end|>
, determine the next line of code. You have imports:
from datetime import datetime
from twitch.resources import (
Channel,
Comment,
Community,
Featured,
Follow,
Game,
Ingest,
Stream,
StreamMetadata,
Subscription,
Team,
TopGame,
TwitchObject,
User,
UserBlock,
Video,
convert_to_twitch_object,
)
import pytest
and context (class names, function names, or code) available:
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Comment(TwitchObject):
# pass
#
# class Community(TwitchObject):
# pass
#
# class Featured(TwitchObject):
# pass
#
# class Follow(TwitchObject):
# pass
#
# class Game(TwitchObject):
# pass
#
# class Ingest(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
#
# class StreamMetadata(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class Team(TwitchObject):
# pass
#
# class TopGame(TwitchObject):
# pass
#
# class TwitchObject(dict):
# def __setattr__(self, name, value):
# if name[0] == "_" or name in self.__dict__:
# return super(TwitchObject, self).__setattr__(name, value)
#
# self[name] = value
#
# def __getattr__(self, name):
# return self[name]
#
# def __delattr__(self, name):
# if name[0] == "_":
# return super(TwitchObject, self).__delattr__(name)
#
# del self[name]
#
# def __setitem__(self, key, value):
# key = key.lstrip("_")
# super(TwitchObject, self).__setitem__(key, value)
#
# @classmethod
# def construct_from(cls, values):
# instance = cls()
# instance.refresh_from(values)
# return instance
#
# def refresh_from(self, values):
# for key, value in values.copy().items():
# self.__setitem__(key, convert_to_twitch_object(key, value))
#
# class User(TwitchObject):
# pass
#
# class UserBlock(TwitchObject):
# pass
#
# class Video(TwitchObject):
# pass
#
# def convert_to_twitch_object(name, data):
# types = {
# "channel": Channel,
# "videos": Video,
# "user": User,
# "game": Game,
# "stream": Stream,
# "comments": Comment,
# "owner": User,
# }
#
# special_types = {
# "created_at": _DateTime,
# "updated_at": _DateTime,
# "published_at": _DateTime,
# "started_at": _DateTime,
# "followed_at": _DateTime,
# }
#
# if isinstance(data, list):
# return [convert_to_twitch_object(name, x) for x in data]
#
# if name in special_types:
# obj = special_types.get(name)
# return obj.construct_from(data)
#
# if isinstance(data, dict) and name in types:
# obj = types.get(name)
# return obj.construct_from(data)
#
# return data
. Output only the next line. | ("published_at", None, None), |
Next line prediction: <|code_start|>def test_datetimes_are_converted_correctly_to_datetime_objects(name, data, expected):
result = convert_to_twitch_object(name, data)
if result is not None:
assert isinstance(result, datetime)
assert result == expected
class TestTwitchObject(object):
def test_attributes_are_stored_and_fetched_from_dict(self):
obj = TwitchObject()
value = "spongebob"
obj.spongebob = value
assert "spongebob" in obj
assert "_spongebob" not in obj.__dict__
assert "spongebob" not in obj.__dict__
assert obj["spongebob"] == value
assert obj.spongebob == value
del obj.spongebob
assert "spongebob" not in obj
assert "spongebob" not in obj.__dict__
def test_prefixed_attributes_are_stored_on_the_object(self):
obj = TwitchObject()
value = "spongebob"
obj._spongebob = value
obj._spongebob
<|code_end|>
. Use current file imports:
(from datetime import datetime
from twitch.resources import (
Channel,
Comment,
Community,
Featured,
Follow,
Game,
Ingest,
Stream,
StreamMetadata,
Subscription,
Team,
TopGame,
TwitchObject,
User,
UserBlock,
Video,
convert_to_twitch_object,
)
import pytest)
and context including class names, function names, or small code snippets from other files:
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Comment(TwitchObject):
# pass
#
# class Community(TwitchObject):
# pass
#
# class Featured(TwitchObject):
# pass
#
# class Follow(TwitchObject):
# pass
#
# class Game(TwitchObject):
# pass
#
# class Ingest(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
#
# class StreamMetadata(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class Team(TwitchObject):
# pass
#
# class TopGame(TwitchObject):
# pass
#
# class TwitchObject(dict):
# def __setattr__(self, name, value):
# if name[0] == "_" or name in self.__dict__:
# return super(TwitchObject, self).__setattr__(name, value)
#
# self[name] = value
#
# def __getattr__(self, name):
# return self[name]
#
# def __delattr__(self, name):
# if name[0] == "_":
# return super(TwitchObject, self).__delattr__(name)
#
# del self[name]
#
# def __setitem__(self, key, value):
# key = key.lstrip("_")
# super(TwitchObject, self).__setitem__(key, value)
#
# @classmethod
# def construct_from(cls, values):
# instance = cls()
# instance.refresh_from(values)
# return instance
#
# def refresh_from(self, values):
# for key, value in values.copy().items():
# self.__setitem__(key, convert_to_twitch_object(key, value))
#
# class User(TwitchObject):
# pass
#
# class UserBlock(TwitchObject):
# pass
#
# class Video(TwitchObject):
# pass
#
# def convert_to_twitch_object(name, data):
# types = {
# "channel": Channel,
# "videos": Video,
# "user": User,
# "game": Game,
# "stream": Stream,
# "comments": Comment,
# "owner": User,
# }
#
# special_types = {
# "created_at": _DateTime,
# "updated_at": _DateTime,
# "published_at": _DateTime,
# "started_at": _DateTime,
# "followed_at": _DateTime,
# }
#
# if isinstance(data, list):
# return [convert_to_twitch_object(name, x) for x in data]
#
# if name in special_types:
# obj = special_types.get(name)
# return obj.construct_from(data)
#
# if isinstance(data, dict) and name in types:
# obj = types.get(name)
# return obj.construct_from(data)
#
# return data
. Output only the next line. | getattr(obj, "_spongebob") |
Given the code snippet: <|code_start|>
example_response = {"ingests": [{"_id": 24, "name": "EU: Amsterdam, NL"}]}
@responses.activate
def test_get_top():
responses.add(
responses.GET,
"{}ingests".format(BASE_URL),
body=json.dumps(example_response),
status=200,
content_type="application/json",
)
client = TwitchClient("abcd")
ingests = client.ingests.get_server_list()
assert len(responses.calls) == 1
assert len(ingests) == 1
ingest = ingests[0]
assert isinstance(ingest, Ingest)
<|code_end|>
, generate the next line using the imports in this file:
import json
import responses
from twitch.client import TwitchClient
from twitch.constants import BASE_URL
from twitch.resources import Ingest
and context (functions, classes, or occasionally code) from other files:
# Path: twitch/client.py
# class TwitchClient(object):
# """
# Twitch API v5 [kraken]
# """
#
# def __init__(self, client_id=None, oauth_token=None):
# self._client_id = client_id
# self._oauth_token = oauth_token
#
# if not client_id:
# self._client_id, self._oauth_token = credentials_from_config_file()
#
# self._clips = None
# self._channel_feed = None
# self._channels = None
# self._chat = None
# self._collections = None
# self._communities = None
# self._games = None
# self._ingests = None
# self._search = None
# self._streams = None
# self._teams = None
# self._users = None
# self._videos = None
#
# @property
# def channel_feed(self):
# if not self._channel_feed:
# self._channel_feed = ChannelFeed(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channel_feed
#
# @property
# def clips(self):
# if not self._clips:
# self._clips = Clips(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._clips
#
# @property
# def channels(self):
# if not self._channels:
# self._channels = Channels(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channels
#
# @property
# def chat(self):
# if not self._chat:
# self._chat = Chat(client_id=self._client_id, oauth_token=self._oauth_token)
# return self._chat
#
# @property
# def collections(self):
# if not self._collections:
# self._collections = Collections(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._collections
#
# @property
# def communities(self):
# if not self._communities:
# self._communities = Communities(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._communities
#
# @property
# def games(self):
# if not self._games:
# self._games = Games(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._games
#
# @property
# def ingests(self):
# if not self._ingests:
# self._ingests = Ingests(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._ingests
#
# @property
# def search(self):
# if not self._search:
# self._search = Search(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._search
#
# @property
# def streams(self):
# if not self._streams:
# self._streams = Streams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._streams
#
# @property
# def teams(self):
# if not self._teams:
# self._teams = Teams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._teams
#
# @property
# def users(self):
# if not self._users:
# self._users = Users(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._users
#
# @property
# def videos(self):
# if not self._videos:
# self._videos = Videos(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._videos
#
# Path: twitch/constants.py
# BASE_URL = "https://api.twitch.tv/kraken/"
#
# Path: twitch/resources.py
# class Ingest(TwitchObject):
# pass
. Output only the next line. | assert ingest.id == example_response["ingests"][0]["_id"] |
Based on the snippet: <|code_start|>
example_response = {"ingests": [{"_id": 24, "name": "EU: Amsterdam, NL"}]}
@responses.activate
def test_get_top():
responses.add(
responses.GET,
"{}ingests".format(BASE_URL),
body=json.dumps(example_response),
status=200,
<|code_end|>
, predict the immediate next line with the help of imports:
import json
import responses
from twitch.client import TwitchClient
from twitch.constants import BASE_URL
from twitch.resources import Ingest
and context (classes, functions, sometimes code) from other files:
# Path: twitch/client.py
# class TwitchClient(object):
# """
# Twitch API v5 [kraken]
# """
#
# def __init__(self, client_id=None, oauth_token=None):
# self._client_id = client_id
# self._oauth_token = oauth_token
#
# if not client_id:
# self._client_id, self._oauth_token = credentials_from_config_file()
#
# self._clips = None
# self._channel_feed = None
# self._channels = None
# self._chat = None
# self._collections = None
# self._communities = None
# self._games = None
# self._ingests = None
# self._search = None
# self._streams = None
# self._teams = None
# self._users = None
# self._videos = None
#
# @property
# def channel_feed(self):
# if not self._channel_feed:
# self._channel_feed = ChannelFeed(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channel_feed
#
# @property
# def clips(self):
# if not self._clips:
# self._clips = Clips(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._clips
#
# @property
# def channels(self):
# if not self._channels:
# self._channels = Channels(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channels
#
# @property
# def chat(self):
# if not self._chat:
# self._chat = Chat(client_id=self._client_id, oauth_token=self._oauth_token)
# return self._chat
#
# @property
# def collections(self):
# if not self._collections:
# self._collections = Collections(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._collections
#
# @property
# def communities(self):
# if not self._communities:
# self._communities = Communities(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._communities
#
# @property
# def games(self):
# if not self._games:
# self._games = Games(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._games
#
# @property
# def ingests(self):
# if not self._ingests:
# self._ingests = Ingests(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._ingests
#
# @property
# def search(self):
# if not self._search:
# self._search = Search(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._search
#
# @property
# def streams(self):
# if not self._streams:
# self._streams = Streams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._streams
#
# @property
# def teams(self):
# if not self._teams:
# self._teams = Teams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._teams
#
# @property
# def users(self):
# if not self._users:
# self._users = Users(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._users
#
# @property
# def videos(self):
# if not self._videos:
# self._videos = Videos(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._videos
#
# Path: twitch/constants.py
# BASE_URL = "https://api.twitch.tv/kraken/"
#
# Path: twitch/resources.py
# class Ingest(TwitchObject):
# pass
. Output only the next line. | content_type="application/json", |
Given snippet: <|code_start|> kwargs = {param: value}
with pytest.raises(TwitchAttributeException):
client.search.channels("mah query", **kwargs)
@responses.activate
def test_channels_does_not_raise_if_no_channels_were_found():
response = {"channels": None}
responses.add(
responses.GET,
"{}search/channels".format(BASE_URL),
body=json.dumps(response),
status=200,
content_type="application/json",
)
client = TwitchClient("client id")
channels = client.search.channels("mah bad query")
assert len(responses.calls) == 1
assert len(channels) == 0
@responses.activate
def test_games():
response = {"_total": 2147, "games": [example_game]}
responses.add(
responses.GET,
"{}search/games".format(BASE_URL),
<|code_end|>
, continue by predicting the next line. Consider current file imports:
import json
import pytest
import responses
from twitch.client import TwitchClient
from twitch.constants import BASE_URL
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Channel, Game, Stream
and context:
# Path: twitch/client.py
# class TwitchClient(object):
# """
# Twitch API v5 [kraken]
# """
#
# def __init__(self, client_id=None, oauth_token=None):
# self._client_id = client_id
# self._oauth_token = oauth_token
#
# if not client_id:
# self._client_id, self._oauth_token = credentials_from_config_file()
#
# self._clips = None
# self._channel_feed = None
# self._channels = None
# self._chat = None
# self._collections = None
# self._communities = None
# self._games = None
# self._ingests = None
# self._search = None
# self._streams = None
# self._teams = None
# self._users = None
# self._videos = None
#
# @property
# def channel_feed(self):
# if not self._channel_feed:
# self._channel_feed = ChannelFeed(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channel_feed
#
# @property
# def clips(self):
# if not self._clips:
# self._clips = Clips(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._clips
#
# @property
# def channels(self):
# if not self._channels:
# self._channels = Channels(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channels
#
# @property
# def chat(self):
# if not self._chat:
# self._chat = Chat(client_id=self._client_id, oauth_token=self._oauth_token)
# return self._chat
#
# @property
# def collections(self):
# if not self._collections:
# self._collections = Collections(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._collections
#
# @property
# def communities(self):
# if not self._communities:
# self._communities = Communities(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._communities
#
# @property
# def games(self):
# if not self._games:
# self._games = Games(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._games
#
# @property
# def ingests(self):
# if not self._ingests:
# self._ingests = Ingests(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._ingests
#
# @property
# def search(self):
# if not self._search:
# self._search = Search(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._search
#
# @property
# def streams(self):
# if not self._streams:
# self._streams = Streams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._streams
#
# @property
# def teams(self):
# if not self._teams:
# self._teams = Teams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._teams
#
# @property
# def users(self):
# if not self._users:
# self._users = Users(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._users
#
# @property
# def videos(self):
# if not self._videos:
# self._videos = Videos(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._videos
#
# Path: twitch/constants.py
# BASE_URL = "https://api.twitch.tv/kraken/"
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Game(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
which might include code, classes, or functions. Output only the next line. | body=json.dumps(response), |
Continue the code snippet: <|code_start|>def test_channels_raises_if_wrong_params_are_passed_in(param, value):
client = TwitchClient("client id")
kwargs = {param: value}
with pytest.raises(TwitchAttributeException):
client.search.channels("mah query", **kwargs)
@responses.activate
def test_channels_does_not_raise_if_no_channels_were_found():
response = {"channels": None}
responses.add(
responses.GET,
"{}search/channels".format(BASE_URL),
body=json.dumps(response),
status=200,
content_type="application/json",
)
client = TwitchClient("client id")
channels = client.search.channels("mah bad query")
assert len(responses.calls) == 1
assert len(channels) == 0
@responses.activate
def test_games():
response = {"_total": 2147, "games": [example_game]}
responses.add(
<|code_end|>
. Use current file imports:
import json
import pytest
import responses
from twitch.client import TwitchClient
from twitch.constants import BASE_URL
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Channel, Game, Stream
and context (classes, functions, or code) from other files:
# Path: twitch/client.py
# class TwitchClient(object):
# """
# Twitch API v5 [kraken]
# """
#
# def __init__(self, client_id=None, oauth_token=None):
# self._client_id = client_id
# self._oauth_token = oauth_token
#
# if not client_id:
# self._client_id, self._oauth_token = credentials_from_config_file()
#
# self._clips = None
# self._channel_feed = None
# self._channels = None
# self._chat = None
# self._collections = None
# self._communities = None
# self._games = None
# self._ingests = None
# self._search = None
# self._streams = None
# self._teams = None
# self._users = None
# self._videos = None
#
# @property
# def channel_feed(self):
# if not self._channel_feed:
# self._channel_feed = ChannelFeed(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channel_feed
#
# @property
# def clips(self):
# if not self._clips:
# self._clips = Clips(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._clips
#
# @property
# def channels(self):
# if not self._channels:
# self._channels = Channels(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channels
#
# @property
# def chat(self):
# if not self._chat:
# self._chat = Chat(client_id=self._client_id, oauth_token=self._oauth_token)
# return self._chat
#
# @property
# def collections(self):
# if not self._collections:
# self._collections = Collections(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._collections
#
# @property
# def communities(self):
# if not self._communities:
# self._communities = Communities(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._communities
#
# @property
# def games(self):
# if not self._games:
# self._games = Games(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._games
#
# @property
# def ingests(self):
# if not self._ingests:
# self._ingests = Ingests(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._ingests
#
# @property
# def search(self):
# if not self._search:
# self._search = Search(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._search
#
# @property
# def streams(self):
# if not self._streams:
# self._streams = Streams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._streams
#
# @property
# def teams(self):
# if not self._teams:
# self._teams = Teams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._teams
#
# @property
# def users(self):
# if not self._users:
# self._users = Users(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._users
#
# @property
# def videos(self):
# if not self._videos:
# self._videos = Videos(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._videos
#
# Path: twitch/constants.py
# BASE_URL = "https://api.twitch.tv/kraken/"
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Game(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
. Output only the next line. | responses.GET, |
Continue the code snippet: <|code_start|> content_type="application/json",
)
client = TwitchClient("client id")
channels = client.search.channels("mah bad query")
assert len(responses.calls) == 1
assert len(channels) == 0
@responses.activate
def test_games():
response = {"_total": 2147, "games": [example_game]}
responses.add(
responses.GET,
"{}search/games".format(BASE_URL),
body=json.dumps(response),
status=200,
content_type="application/json",
)
client = TwitchClient("client id")
games = client.search.games("mah query")
assert len(responses.calls) == 1
assert len(games) == 1
game = games[0]
assert isinstance(game, Game)
<|code_end|>
. Use current file imports:
import json
import pytest
import responses
from twitch.client import TwitchClient
from twitch.constants import BASE_URL
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Channel, Game, Stream
and context (classes, functions, or code) from other files:
# Path: twitch/client.py
# class TwitchClient(object):
# """
# Twitch API v5 [kraken]
# """
#
# def __init__(self, client_id=None, oauth_token=None):
# self._client_id = client_id
# self._oauth_token = oauth_token
#
# if not client_id:
# self._client_id, self._oauth_token = credentials_from_config_file()
#
# self._clips = None
# self._channel_feed = None
# self._channels = None
# self._chat = None
# self._collections = None
# self._communities = None
# self._games = None
# self._ingests = None
# self._search = None
# self._streams = None
# self._teams = None
# self._users = None
# self._videos = None
#
# @property
# def channel_feed(self):
# if not self._channel_feed:
# self._channel_feed = ChannelFeed(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channel_feed
#
# @property
# def clips(self):
# if not self._clips:
# self._clips = Clips(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._clips
#
# @property
# def channels(self):
# if not self._channels:
# self._channels = Channels(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channels
#
# @property
# def chat(self):
# if not self._chat:
# self._chat = Chat(client_id=self._client_id, oauth_token=self._oauth_token)
# return self._chat
#
# @property
# def collections(self):
# if not self._collections:
# self._collections = Collections(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._collections
#
# @property
# def communities(self):
# if not self._communities:
# self._communities = Communities(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._communities
#
# @property
# def games(self):
# if not self._games:
# self._games = Games(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._games
#
# @property
# def ingests(self):
# if not self._ingests:
# self._ingests = Ingests(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._ingests
#
# @property
# def search(self):
# if not self._search:
# self._search = Search(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._search
#
# @property
# def streams(self):
# if not self._streams:
# self._streams = Streams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._streams
#
# @property
# def teams(self):
# if not self._teams:
# self._teams = Teams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._teams
#
# @property
# def users(self):
# if not self._users:
# self._users = Users(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._users
#
# @property
# def videos(self):
# if not self._videos:
# self._videos = Videos(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._videos
#
# Path: twitch/constants.py
# BASE_URL = "https://api.twitch.tv/kraken/"
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Game(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
. Output only the next line. | assert game.id == example_game["_id"] |
Given the following code snippet before the placeholder: <|code_start|> client = TwitchClient("client id")
channels = client.search.channels("mah query")
assert len(responses.calls) == 1
assert len(channels) == 1
channel = channels[0]
assert isinstance(channel, Channel)
assert channel.id == example_channel["_id"]
assert channel.name == example_channel["name"]
@responses.activate
@pytest.mark.parametrize("param,value", [("limit", 101)])
def test_channels_raises_if_wrong_params_are_passed_in(param, value):
client = TwitchClient("client id")
kwargs = {param: value}
with pytest.raises(TwitchAttributeException):
client.search.channels("mah query", **kwargs)
@responses.activate
def test_channels_does_not_raise_if_no_channels_were_found():
response = {"channels": None}
responses.add(
responses.GET,
"{}search/channels".format(BASE_URL),
body=json.dumps(response),
status=200,
content_type="application/json",
<|code_end|>
, predict the next line using imports from the current file:
import json
import pytest
import responses
from twitch.client import TwitchClient
from twitch.constants import BASE_URL
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Channel, Game, Stream
and context including class names, function names, and sometimes code from other files:
# Path: twitch/client.py
# class TwitchClient(object):
# """
# Twitch API v5 [kraken]
# """
#
# def __init__(self, client_id=None, oauth_token=None):
# self._client_id = client_id
# self._oauth_token = oauth_token
#
# if not client_id:
# self._client_id, self._oauth_token = credentials_from_config_file()
#
# self._clips = None
# self._channel_feed = None
# self._channels = None
# self._chat = None
# self._collections = None
# self._communities = None
# self._games = None
# self._ingests = None
# self._search = None
# self._streams = None
# self._teams = None
# self._users = None
# self._videos = None
#
# @property
# def channel_feed(self):
# if not self._channel_feed:
# self._channel_feed = ChannelFeed(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channel_feed
#
# @property
# def clips(self):
# if not self._clips:
# self._clips = Clips(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._clips
#
# @property
# def channels(self):
# if not self._channels:
# self._channels = Channels(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channels
#
# @property
# def chat(self):
# if not self._chat:
# self._chat = Chat(client_id=self._client_id, oauth_token=self._oauth_token)
# return self._chat
#
# @property
# def collections(self):
# if not self._collections:
# self._collections = Collections(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._collections
#
# @property
# def communities(self):
# if not self._communities:
# self._communities = Communities(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._communities
#
# @property
# def games(self):
# if not self._games:
# self._games = Games(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._games
#
# @property
# def ingests(self):
# if not self._ingests:
# self._ingests = Ingests(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._ingests
#
# @property
# def search(self):
# if not self._search:
# self._search = Search(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._search
#
# @property
# def streams(self):
# if not self._streams:
# self._streams = Streams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._streams
#
# @property
# def teams(self):
# if not self._teams:
# self._teams = Teams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._teams
#
# @property
# def users(self):
# if not self._users:
# self._users = Users(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._users
#
# @property
# def videos(self):
# if not self._videos:
# self._videos = Videos(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._videos
#
# Path: twitch/constants.py
# BASE_URL = "https://api.twitch.tv/kraken/"
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Game(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
. Output only the next line. | ) |
Predict the next line for this snippet: <|code_start|> "game": "BATMAN - The Telltale Series",
"channel": example_channel,
}
@responses.activate
def test_channels():
response = {"_total": 2147, "channels": [example_channel]}
responses.add(
responses.GET,
"{}search/channels".format(BASE_URL),
body=json.dumps(response),
status=200,
content_type="application/json",
)
client = TwitchClient("client id")
channels = client.search.channels("mah query")
assert len(responses.calls) == 1
assert len(channels) == 1
channel = channels[0]
assert isinstance(channel, Channel)
assert channel.id == example_channel["_id"]
assert channel.name == example_channel["name"]
@responses.activate
@pytest.mark.parametrize("param,value", [("limit", 101)])
<|code_end|>
with the help of current file imports:
import json
import pytest
import responses
from twitch.client import TwitchClient
from twitch.constants import BASE_URL
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Channel, Game, Stream
and context from other files:
# Path: twitch/client.py
# class TwitchClient(object):
# """
# Twitch API v5 [kraken]
# """
#
# def __init__(self, client_id=None, oauth_token=None):
# self._client_id = client_id
# self._oauth_token = oauth_token
#
# if not client_id:
# self._client_id, self._oauth_token = credentials_from_config_file()
#
# self._clips = None
# self._channel_feed = None
# self._channels = None
# self._chat = None
# self._collections = None
# self._communities = None
# self._games = None
# self._ingests = None
# self._search = None
# self._streams = None
# self._teams = None
# self._users = None
# self._videos = None
#
# @property
# def channel_feed(self):
# if not self._channel_feed:
# self._channel_feed = ChannelFeed(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channel_feed
#
# @property
# def clips(self):
# if not self._clips:
# self._clips = Clips(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._clips
#
# @property
# def channels(self):
# if not self._channels:
# self._channels = Channels(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channels
#
# @property
# def chat(self):
# if not self._chat:
# self._chat = Chat(client_id=self._client_id, oauth_token=self._oauth_token)
# return self._chat
#
# @property
# def collections(self):
# if not self._collections:
# self._collections = Collections(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._collections
#
# @property
# def communities(self):
# if not self._communities:
# self._communities = Communities(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._communities
#
# @property
# def games(self):
# if not self._games:
# self._games = Games(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._games
#
# @property
# def ingests(self):
# if not self._ingests:
# self._ingests = Ingests(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._ingests
#
# @property
# def search(self):
# if not self._search:
# self._search = Search(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._search
#
# @property
# def streams(self):
# if not self._streams:
# self._streams = Streams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._streams
#
# @property
# def teams(self):
# if not self._teams:
# self._teams = Teams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._teams
#
# @property
# def users(self):
# if not self._users:
# self._users = Users(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._users
#
# @property
# def videos(self):
# if not self._videos:
# self._videos = Videos(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._videos
#
# Path: twitch/constants.py
# BASE_URL = "https://api.twitch.tv/kraken/"
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Game(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
, which may contain function names, class names, or code. Output only the next line. | def test_channels_raises_if_wrong_params_are_passed_in(param, value): |
Given the code snippet: <|code_start|> assert stream.id == example_stream["_id"]
assert stream.game == example_stream["game"]
assert isinstance(stream.channel, Channel)
assert stream.channel.id == example_channel["_id"]
assert stream.channel.name == example_channel["name"]
@responses.activate
@pytest.mark.parametrize("param,value", [("limit", 101)])
def test_streams_raises_if_wrong_params_are_passed_in(param, value):
client = TwitchClient("client id")
kwargs = {param: value}
with pytest.raises(TwitchAttributeException):
client.search.streams("mah query", **kwargs)
@responses.activate
def test_streams_does_not_raise_if_no_streams_were_found():
response = {"streams": None}
responses.add(
responses.GET,
"{}search/streams".format(BASE_URL),
body=json.dumps(response),
status=200,
content_type="application/json",
)
client = TwitchClient("client id")
<|code_end|>
, generate the next line using the imports in this file:
import json
import pytest
import responses
from twitch.client import TwitchClient
from twitch.constants import BASE_URL
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Channel, Game, Stream
and context (functions, classes, or occasionally code) from other files:
# Path: twitch/client.py
# class TwitchClient(object):
# """
# Twitch API v5 [kraken]
# """
#
# def __init__(self, client_id=None, oauth_token=None):
# self._client_id = client_id
# self._oauth_token = oauth_token
#
# if not client_id:
# self._client_id, self._oauth_token = credentials_from_config_file()
#
# self._clips = None
# self._channel_feed = None
# self._channels = None
# self._chat = None
# self._collections = None
# self._communities = None
# self._games = None
# self._ingests = None
# self._search = None
# self._streams = None
# self._teams = None
# self._users = None
# self._videos = None
#
# @property
# def channel_feed(self):
# if not self._channel_feed:
# self._channel_feed = ChannelFeed(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channel_feed
#
# @property
# def clips(self):
# if not self._clips:
# self._clips = Clips(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._clips
#
# @property
# def channels(self):
# if not self._channels:
# self._channels = Channels(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._channels
#
# @property
# def chat(self):
# if not self._chat:
# self._chat = Chat(client_id=self._client_id, oauth_token=self._oauth_token)
# return self._chat
#
# @property
# def collections(self):
# if not self._collections:
# self._collections = Collections(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._collections
#
# @property
# def communities(self):
# if not self._communities:
# self._communities = Communities(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._communities
#
# @property
# def games(self):
# if not self._games:
# self._games = Games(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._games
#
# @property
# def ingests(self):
# if not self._ingests:
# self._ingests = Ingests(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._ingests
#
# @property
# def search(self):
# if not self._search:
# self._search = Search(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._search
#
# @property
# def streams(self):
# if not self._streams:
# self._streams = Streams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._streams
#
# @property
# def teams(self):
# if not self._teams:
# self._teams = Teams(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._teams
#
# @property
# def users(self):
# if not self._users:
# self._users = Users(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._users
#
# @property
# def videos(self):
# if not self._videos:
# self._videos = Videos(
# client_id=self._client_id, oauth_token=self._oauth_token
# )
# return self._videos
#
# Path: twitch/constants.py
# BASE_URL = "https://api.twitch.tv/kraken/"
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Channel(TwitchObject):
# pass
#
# class Game(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
. Output only the next line. | streams = client.search.streams("mah bad query") |
Next line prediction: <|code_start|> content_type="application/octet-stream",
)
api = TwitchAPI(client_id="client")
response = api._request_get("", json=False)
assert response.content == b"binary"
@responses.activate
@pytest.mark.parametrize("status", [(500), (400)])
def test_request_get_raises_exception_if_not_200_response(status, monkeypatch):
responses.add(
responses.GET, BASE_URL, status=status, content_type="application/json"
)
def mockreturn(path):
return "tests/api/dummy_credentials.cfg"
monkeypatch.setattr(os.path, "expanduser", mockreturn)
api = TwitchAPI(client_id="client")
with pytest.raises(exceptions.HTTPError):
api._request_get("")
@responses.activate
def test_request_put_returns_dictionary_if_successful():
responses.add(
<|code_end|>
. Use current file imports:
(import json
import os
import pytest
import responses
from requests import exceptions
from twitch.api.base import BASE_URL, TwitchAPI)
and context including class names, function names, or small code snippets from other files:
# Path: twitch/api/base.py
# DEFAULT_TIMEOUT = 10
# class TwitchAPI(object):
# def __init__(self, client_id, oauth_token=None):
# def _get_request_headers(self):
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# def _request_delete(self, path, params=None, url=BASE_URL):
. Output only the next line. | responses.PUT, |
Here is a snippet: <|code_start|> )
api = TwitchAPI(client_id="client")
response = api._request_delete("")
assert response == dummy_data
@responses.activate
def test_request_delete_sends_headers_with_the_request():
responses.add(
responses.DELETE, BASE_URL, status=204, content_type="application/json"
)
api = TwitchAPI(client_id="client")
api._request_delete("")
assert "Client-ID" in responses.calls[0].request.headers
assert "Accept" in responses.calls[0].request.headers
@responses.activate
@pytest.mark.parametrize("status", [(500), (400)])
def test_request_delete_raises_exception_if_not_200_response(status):
responses.add(
responses.DELETE, BASE_URL, status=status, content_type="application/json"
)
api = TwitchAPI(client_id="client")
with pytest.raises(exceptions.HTTPError):
<|code_end|>
. Write the next line using the current file imports:
import json
import os
import pytest
import responses
from requests import exceptions
from twitch.api.base import BASE_URL, TwitchAPI
and context from other files:
# Path: twitch/api/base.py
# DEFAULT_TIMEOUT = 10
# class TwitchAPI(object):
# def __init__(self, client_id, oauth_token=None):
# def _get_request_headers(self):
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# def _request_delete(self, path, params=None, url=BASE_URL):
, which may include functions, classes, or code. Output only the next line. | api._request_delete("") |
Given the code snippet: <|code_start|>
def _get_config():
config = ConfigParser()
config.read(os.path.expanduser(CONFIG_FILE_PATH))
return config
def credentials_from_config_file():
client_id = None
oauth_token = None
config = _get_config()
if "Credentials" in config.sections():
client_id = config["Credentials"].get("client_id")
oauth_token = config["Credentials"].get("oauth_token")
return client_id, oauth_token
def backoff_config():
initial_backoff = 0.5
max_retries = 3
<|code_end|>
, generate the next line using the imports in this file:
import os
from configparser import ConfigParser
from twitch.constants import CONFIG_FILE_PATH
and context (functions, classes, or occasionally code) from other files:
# Path: twitch/constants.py
# CONFIG_FILE_PATH = "~/.twitch.cfg"
. Output only the next line. | config = _get_config() |
Based on the snippet: <|code_start|>class Videos(TwitchAPI):
def get_by_id(self, video_id):
response = self._request_get("videos/{}".format(video_id))
return Video.construct_from(response)
def get_top(
self,
limit=10,
offset=0,
game=None,
period=PERIOD_WEEK,
broadcast_type=BROADCAST_TYPE_HIGHLIGHT,
):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
)
if period not in PERIODS:
raise TwitchAttributeException(
"Period is not valid. Valid values are {}".format(PERIODS)
)
if broadcast_type not in BROADCAST_TYPES:
raise TwitchAttributeException(
"Broadcast type is not valid. Valid values are {}".format(
BROADCAST_TYPES
)
)
params = {
<|code_end|>
, predict the immediate next line with the help of imports:
from twitch.api.base import TwitchAPI
from twitch.constants import (
BROADCAST_TYPE_HIGHLIGHT,
BROADCAST_TYPES,
PERIOD_WEEK,
PERIODS,
VOD_FETCH_URL,
)
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Video
and context (classes, functions, sometimes code) from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/constants.py
# BROADCAST_TYPE_HIGHLIGHT = "highlight"
#
# BROADCAST_TYPES = [
# BROADCAST_TYPE_ARCHIVE,
# BROADCAST_TYPE_HIGHLIGHT,
# BROADCAST_TYPE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_HIGHLIGHT,
# BROADCAST_TYPE_HIGHLIGHT_UPLOAD,
# BROADCAST_TYPE_ALL,
# ]
#
# PERIOD_WEEK = "week"
#
# PERIODS = [PERIOD_DAY, PERIOD_WEEK, PERIOD_MONTH, PERIOD_ALL]
#
# VOD_FETCH_URL = "https://usher.ttvnw.net/"
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Video(TwitchObject):
# pass
. Output only the next line. | "limit": limit, |
Here is a snippet: <|code_start|> if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
)
if period not in PERIODS:
raise TwitchAttributeException(
"Period is not valid. Valid values are {}".format(PERIODS)
)
if broadcast_type not in BROADCAST_TYPES:
raise TwitchAttributeException(
"Broadcast type is not valid. Valid values are {}".format(
BROADCAST_TYPES
)
)
params = {
"limit": limit,
"offset": offset,
"game": game,
"period": period,
"broadcast_type": ",".join(broadcast_type),
}
response = self._request_get("videos/top", params=params)
return [Video.construct_from(x) for x in response["vods"]]
@oauth_required
def get_followed_videos(
self, limit=10, offset=0, broadcast_type=BROADCAST_TYPE_HIGHLIGHT
<|code_end|>
. Write the next line using the current file imports:
from twitch.api.base import TwitchAPI
from twitch.constants import (
BROADCAST_TYPE_HIGHLIGHT,
BROADCAST_TYPES,
PERIOD_WEEK,
PERIODS,
VOD_FETCH_URL,
)
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Video
and context from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/constants.py
# BROADCAST_TYPE_HIGHLIGHT = "highlight"
#
# BROADCAST_TYPES = [
# BROADCAST_TYPE_ARCHIVE,
# BROADCAST_TYPE_HIGHLIGHT,
# BROADCAST_TYPE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_HIGHLIGHT,
# BROADCAST_TYPE_HIGHLIGHT_UPLOAD,
# BROADCAST_TYPE_ALL,
# ]
#
# PERIOD_WEEK = "week"
#
# PERIODS = [PERIOD_DAY, PERIOD_WEEK, PERIOD_MONTH, PERIOD_ALL]
#
# VOD_FETCH_URL = "https://usher.ttvnw.net/"
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Video(TwitchObject):
# pass
, which may include functions, classes, or code. Output only the next line. | ): |
Using the snippet: <|code_start|>
class Videos(TwitchAPI):
def get_by_id(self, video_id):
response = self._request_get("videos/{}".format(video_id))
return Video.construct_from(response)
def get_top(
self,
limit=10,
offset=0,
game=None,
period=PERIOD_WEEK,
broadcast_type=BROADCAST_TYPE_HIGHLIGHT,
):
if limit > 100:
raise TwitchAttributeException(
<|code_end|>
, determine the next line of code. You have imports:
from twitch.api.base import TwitchAPI
from twitch.constants import (
BROADCAST_TYPE_HIGHLIGHT,
BROADCAST_TYPES,
PERIOD_WEEK,
PERIODS,
VOD_FETCH_URL,
)
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Video
and context (class names, function names, or code) available:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/constants.py
# BROADCAST_TYPE_HIGHLIGHT = "highlight"
#
# BROADCAST_TYPES = [
# BROADCAST_TYPE_ARCHIVE,
# BROADCAST_TYPE_HIGHLIGHT,
# BROADCAST_TYPE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_HIGHLIGHT,
# BROADCAST_TYPE_HIGHLIGHT_UPLOAD,
# BROADCAST_TYPE_ALL,
# ]
#
# PERIOD_WEEK = "week"
#
# PERIODS = [PERIOD_DAY, PERIOD_WEEK, PERIOD_MONTH, PERIOD_ALL]
#
# VOD_FETCH_URL = "https://usher.ttvnw.net/"
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Video(TwitchObject):
# pass
. Output only the next line. | "Maximum number of objects returned in one request is 100" |
Given snippet: <|code_start|>
class Videos(TwitchAPI):
def get_by_id(self, video_id):
response = self._request_get("videos/{}".format(video_id))
return Video.construct_from(response)
def get_top(
self,
limit=10,
offset=0,
game=None,
period=PERIOD_WEEK,
broadcast_type=BROADCAST_TYPE_HIGHLIGHT,
<|code_end|>
, continue by predicting the next line. Consider current file imports:
from twitch.api.base import TwitchAPI
from twitch.constants import (
BROADCAST_TYPE_HIGHLIGHT,
BROADCAST_TYPES,
PERIOD_WEEK,
PERIODS,
VOD_FETCH_URL,
)
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Video
and context:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/constants.py
# BROADCAST_TYPE_HIGHLIGHT = "highlight"
#
# BROADCAST_TYPES = [
# BROADCAST_TYPE_ARCHIVE,
# BROADCAST_TYPE_HIGHLIGHT,
# BROADCAST_TYPE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_HIGHLIGHT,
# BROADCAST_TYPE_HIGHLIGHT_UPLOAD,
# BROADCAST_TYPE_ALL,
# ]
#
# PERIOD_WEEK = "week"
#
# PERIODS = [PERIOD_DAY, PERIOD_WEEK, PERIOD_MONTH, PERIOD_ALL]
#
# VOD_FETCH_URL = "https://usher.ttvnw.net/"
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Video(TwitchObject):
# pass
which might include code, classes, or functions. Output only the next line. | ): |
Using the snippet: <|code_start|>
class Videos(TwitchAPI):
def get_by_id(self, video_id):
response = self._request_get("videos/{}".format(video_id))
return Video.construct_from(response)
def get_top(
self,
limit=10,
offset=0,
game=None,
period=PERIOD_WEEK,
broadcast_type=BROADCAST_TYPE_HIGHLIGHT,
):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
)
if period not in PERIODS:
raise TwitchAttributeException(
"Period is not valid. Valid values are {}".format(PERIODS)
)
if broadcast_type not in BROADCAST_TYPES:
raise TwitchAttributeException(
"Broadcast type is not valid. Valid values are {}".format(
BROADCAST_TYPES
<|code_end|>
, determine the next line of code. You have imports:
from twitch.api.base import TwitchAPI
from twitch.constants import (
BROADCAST_TYPE_HIGHLIGHT,
BROADCAST_TYPES,
PERIOD_WEEK,
PERIODS,
VOD_FETCH_URL,
)
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Video
and context (class names, function names, or code) available:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/constants.py
# BROADCAST_TYPE_HIGHLIGHT = "highlight"
#
# BROADCAST_TYPES = [
# BROADCAST_TYPE_ARCHIVE,
# BROADCAST_TYPE_HIGHLIGHT,
# BROADCAST_TYPE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_HIGHLIGHT,
# BROADCAST_TYPE_HIGHLIGHT_UPLOAD,
# BROADCAST_TYPE_ALL,
# ]
#
# PERIOD_WEEK = "week"
#
# PERIODS = [PERIOD_DAY, PERIOD_WEEK, PERIOD_MONTH, PERIOD_ALL]
#
# VOD_FETCH_URL = "https://usher.ttvnw.net/"
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Video(TwitchObject):
# pass
. Output only the next line. | ) |
Given the code snippet: <|code_start|>
class Videos(TwitchAPI):
def get_by_id(self, video_id):
response = self._request_get("videos/{}".format(video_id))
return Video.construct_from(response)
def get_top(
self,
<|code_end|>
, generate the next line using the imports in this file:
from twitch.api.base import TwitchAPI
from twitch.constants import (
BROADCAST_TYPE_HIGHLIGHT,
BROADCAST_TYPES,
PERIOD_WEEK,
PERIODS,
VOD_FETCH_URL,
)
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Video
and context (functions, classes, or occasionally code) from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/constants.py
# BROADCAST_TYPE_HIGHLIGHT = "highlight"
#
# BROADCAST_TYPES = [
# BROADCAST_TYPE_ARCHIVE,
# BROADCAST_TYPE_HIGHLIGHT,
# BROADCAST_TYPE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_HIGHLIGHT,
# BROADCAST_TYPE_HIGHLIGHT_UPLOAD,
# BROADCAST_TYPE_ALL,
# ]
#
# PERIOD_WEEK = "week"
#
# PERIODS = [PERIOD_DAY, PERIOD_WEEK, PERIOD_MONTH, PERIOD_ALL]
#
# VOD_FETCH_URL = "https://usher.ttvnw.net/"
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Video(TwitchObject):
# pass
. Output only the next line. | limit=10, |
Based on the snippet: <|code_start|> raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
)
if period not in PERIODS:
raise TwitchAttributeException(
"Period is not valid. Valid values are {}".format(PERIODS)
)
if broadcast_type not in BROADCAST_TYPES:
raise TwitchAttributeException(
"Broadcast type is not valid. Valid values are {}".format(
BROADCAST_TYPES
)
)
params = {
"limit": limit,
"offset": offset,
"game": game,
"period": period,
"broadcast_type": ",".join(broadcast_type),
}
response = self._request_get("videos/top", params=params)
return [Video.construct_from(x) for x in response["vods"]]
@oauth_required
def get_followed_videos(
self, limit=10, offset=0, broadcast_type=BROADCAST_TYPE_HIGHLIGHT
):
<|code_end|>
, predict the immediate next line with the help of imports:
from twitch.api.base import TwitchAPI
from twitch.constants import (
BROADCAST_TYPE_HIGHLIGHT,
BROADCAST_TYPES,
PERIOD_WEEK,
PERIODS,
VOD_FETCH_URL,
)
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Video
and context (classes, functions, sometimes code) from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/constants.py
# BROADCAST_TYPE_HIGHLIGHT = "highlight"
#
# BROADCAST_TYPES = [
# BROADCAST_TYPE_ARCHIVE,
# BROADCAST_TYPE_HIGHLIGHT,
# BROADCAST_TYPE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_HIGHLIGHT,
# BROADCAST_TYPE_HIGHLIGHT_UPLOAD,
# BROADCAST_TYPE_ALL,
# ]
#
# PERIOD_WEEK = "week"
#
# PERIODS = [PERIOD_DAY, PERIOD_WEEK, PERIOD_MONTH, PERIOD_ALL]
#
# VOD_FETCH_URL = "https://usher.ttvnw.net/"
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Video(TwitchObject):
# pass
. Output only the next line. | if limit > 100: |
Next line prediction: <|code_start|> def get_by_id(self, video_id):
response = self._request_get("videos/{}".format(video_id))
return Video.construct_from(response)
def get_top(
self,
limit=10,
offset=0,
game=None,
period=PERIOD_WEEK,
broadcast_type=BROADCAST_TYPE_HIGHLIGHT,
):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
)
if period not in PERIODS:
raise TwitchAttributeException(
"Period is not valid. Valid values are {}".format(PERIODS)
)
if broadcast_type not in BROADCAST_TYPES:
raise TwitchAttributeException(
"Broadcast type is not valid. Valid values are {}".format(
BROADCAST_TYPES
)
)
params = {
"limit": limit,
<|code_end|>
. Use current file imports:
(from twitch.api.base import TwitchAPI
from twitch.constants import (
BROADCAST_TYPE_HIGHLIGHT,
BROADCAST_TYPES,
PERIOD_WEEK,
PERIODS,
VOD_FETCH_URL,
)
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Video)
and context including class names, function names, or small code snippets from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/constants.py
# BROADCAST_TYPE_HIGHLIGHT = "highlight"
#
# BROADCAST_TYPES = [
# BROADCAST_TYPE_ARCHIVE,
# BROADCAST_TYPE_HIGHLIGHT,
# BROADCAST_TYPE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_HIGHLIGHT,
# BROADCAST_TYPE_HIGHLIGHT_UPLOAD,
# BROADCAST_TYPE_ALL,
# ]
#
# PERIOD_WEEK = "week"
#
# PERIODS = [PERIOD_DAY, PERIOD_WEEK, PERIOD_MONTH, PERIOD_ALL]
#
# VOD_FETCH_URL = "https://usher.ttvnw.net/"
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Video(TwitchObject):
# pass
. Output only the next line. | "offset": offset, |
Given the following code snippet before the placeholder: <|code_start|>
class Videos(TwitchAPI):
def get_by_id(self, video_id):
response = self._request_get("videos/{}".format(video_id))
return Video.construct_from(response)
def get_top(
self,
limit=10,
offset=0,
game=None,
period=PERIOD_WEEK,
broadcast_type=BROADCAST_TYPE_HIGHLIGHT,
):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
)
if period not in PERIODS:
raise TwitchAttributeException(
"Period is not valid. Valid values are {}".format(PERIODS)
)
if broadcast_type not in BROADCAST_TYPES:
raise TwitchAttributeException(
<|code_end|>
, predict the next line using imports from the current file:
from twitch.api.base import TwitchAPI
from twitch.constants import (
BROADCAST_TYPE_HIGHLIGHT,
BROADCAST_TYPES,
PERIOD_WEEK,
PERIODS,
VOD_FETCH_URL,
)
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Video
and context including class names, function names, and sometimes code from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/constants.py
# BROADCAST_TYPE_HIGHLIGHT = "highlight"
#
# BROADCAST_TYPES = [
# BROADCAST_TYPE_ARCHIVE,
# BROADCAST_TYPE_HIGHLIGHT,
# BROADCAST_TYPE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_UPLOAD,
# BROADCAST_TYPE_ARCHIVE_HIGHLIGHT,
# BROADCAST_TYPE_HIGHLIGHT_UPLOAD,
# BROADCAST_TYPE_ALL,
# ]
#
# PERIOD_WEEK = "week"
#
# PERIODS = [PERIOD_DAY, PERIOD_WEEK, PERIOD_MONTH, PERIOD_ALL]
#
# VOD_FETCH_URL = "https://usher.ttvnw.net/"
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Video(TwitchObject):
# pass
. Output only the next line. | "Broadcast type is not valid. Valid values are {}".format( |
Given the following code snippet before the placeholder: <|code_start|>
class Streams(TwitchAPI):
def get_stream_by_user(self, channel_id, stream_type=STREAM_TYPE_LIVE):
if stream_type not in STREAM_TYPES:
raise TwitchAttributeException(
"Stream type is not valid. Valid values are {}".format(STREAM_TYPES)
)
params = {
"stream_type": stream_type,
<|code_end|>
, predict the next line using imports from the current file:
from twitch.api.base import TwitchAPI
from twitch.constants import STREAM_TYPE_LIVE, STREAM_TYPES
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Featured, Stream
and context including class names, function names, and sometimes code from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/constants.py
# STREAM_TYPE_LIVE = "live"
#
# STREAM_TYPES = [STREAM_TYPE_LIVE, STREAM_TYPE_PLAYLIST, STREAM_TYPE_ALL]
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Featured(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
. Output only the next line. | } |
Given the code snippet: <|code_start|>
class Streams(TwitchAPI):
def get_stream_by_user(self, channel_id, stream_type=STREAM_TYPE_LIVE):
if stream_type not in STREAM_TYPES:
raise TwitchAttributeException(
"Stream type is not valid. Valid values are {}".format(STREAM_TYPES)
)
params = {
"stream_type": stream_type,
}
response = self._request_get("streams/{}".format(channel_id), params=params)
if not response["stream"]:
return None
return Stream.construct_from(response["stream"])
def get_live_streams(
self,
<|code_end|>
, generate the next line using the imports in this file:
from twitch.api.base import TwitchAPI
from twitch.constants import STREAM_TYPE_LIVE, STREAM_TYPES
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Featured, Stream
and context (functions, classes, or occasionally code) from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/constants.py
# STREAM_TYPE_LIVE = "live"
#
# STREAM_TYPES = [STREAM_TYPE_LIVE, STREAM_TYPE_PLAYLIST, STREAM_TYPE_ALL]
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Featured(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
. Output only the next line. | channel=None, |
Next line prediction: <|code_start|>
class Streams(TwitchAPI):
def get_stream_by_user(self, channel_id, stream_type=STREAM_TYPE_LIVE):
if stream_type not in STREAM_TYPES:
raise TwitchAttributeException(
"Stream type is not valid. Valid values are {}".format(STREAM_TYPES)
)
params = {
"stream_type": stream_type,
}
response = self._request_get("streams/{}".format(channel_id), params=params)
if not response["stream"]:
return None
return Stream.construct_from(response["stream"])
def get_live_streams(
self,
channel=None,
game=None,
language=None,
stream_type=STREAM_TYPE_LIVE,
limit=25,
offset=0,
):
if limit > 100:
raise TwitchAttributeException(
<|code_end|>
. Use current file imports:
(from twitch.api.base import TwitchAPI
from twitch.constants import STREAM_TYPE_LIVE, STREAM_TYPES
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Featured, Stream)
and context including class names, function names, or small code snippets from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/constants.py
# STREAM_TYPE_LIVE = "live"
#
# STREAM_TYPES = [STREAM_TYPE_LIVE, STREAM_TYPE_PLAYLIST, STREAM_TYPE_ALL]
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Featured(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
. Output only the next line. | "Maximum number of objects returned in one request is 100" |
Predict the next line after this snippet: <|code_start|> offset=0,
):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
)
params = {"stream_type": stream_type, "limit": limit, "offset": offset}
if channel is not None:
params["channel"] = channel
if game is not None:
params["game"] = game
if language is not None:
params["language"] = language
response = self._request_get("streams", params=params)
return [Stream.construct_from(x) for x in response["streams"]]
def get_summary(self, game=None):
params = {}
if game is not None:
params["game"] = game
response = self._request_get("streams/summary", params=params)
return response
def get_featured(self, limit=25, offset=0):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
)
<|code_end|>
using the current file's imports:
from twitch.api.base import TwitchAPI
from twitch.constants import STREAM_TYPE_LIVE, STREAM_TYPES
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Featured, Stream
and any relevant context from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/constants.py
# STREAM_TYPE_LIVE = "live"
#
# STREAM_TYPES = [STREAM_TYPE_LIVE, STREAM_TYPE_PLAYLIST, STREAM_TYPE_ALL]
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Featured(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
. Output only the next line. | params = {"limit": limit, "offset": offset} |
Predict the next line for this snippet: <|code_start|>
params = {
"stream_type": stream_type,
}
response = self._request_get("streams/{}".format(channel_id), params=params)
if not response["stream"]:
return None
return Stream.construct_from(response["stream"])
def get_live_streams(
self,
channel=None,
game=None,
language=None,
stream_type=STREAM_TYPE_LIVE,
limit=25,
offset=0,
):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
)
params = {"stream_type": stream_type, "limit": limit, "offset": offset}
if channel is not None:
params["channel"] = channel
if game is not None:
params["game"] = game
if language is not None:
<|code_end|>
with the help of current file imports:
from twitch.api.base import TwitchAPI
from twitch.constants import STREAM_TYPE_LIVE, STREAM_TYPES
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Featured, Stream
and context from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/constants.py
# STREAM_TYPE_LIVE = "live"
#
# STREAM_TYPES = [STREAM_TYPE_LIVE, STREAM_TYPE_PLAYLIST, STREAM_TYPE_ALL]
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Featured(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
, which may contain function names, class names, or code. Output only the next line. | params["language"] = language |
Using the snippet: <|code_start|>
class Streams(TwitchAPI):
def get_stream_by_user(self, channel_id, stream_type=STREAM_TYPE_LIVE):
if stream_type not in STREAM_TYPES:
raise TwitchAttributeException(
"Stream type is not valid. Valid values are {}".format(STREAM_TYPES)
)
params = {
"stream_type": stream_type,
}
response = self._request_get("streams/{}".format(channel_id), params=params)
if not response["stream"]:
return None
return Stream.construct_from(response["stream"])
def get_live_streams(
self,
channel=None,
game=None,
language=None,
stream_type=STREAM_TYPE_LIVE,
<|code_end|>
, determine the next line of code. You have imports:
from twitch.api.base import TwitchAPI
from twitch.constants import STREAM_TYPE_LIVE, STREAM_TYPES
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Featured, Stream
and context (class names, function names, or code) available:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/constants.py
# STREAM_TYPE_LIVE = "live"
#
# STREAM_TYPES = [STREAM_TYPE_LIVE, STREAM_TYPE_PLAYLIST, STREAM_TYPE_ALL]
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Featured(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
. Output only the next line. | limit=25, |
Here is a snippet: <|code_start|> language=None,
stream_type=STREAM_TYPE_LIVE,
limit=25,
offset=0,
):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
)
params = {"stream_type": stream_type, "limit": limit, "offset": offset}
if channel is not None:
params["channel"] = channel
if game is not None:
params["game"] = game
if language is not None:
params["language"] = language
response = self._request_get("streams", params=params)
return [Stream.construct_from(x) for x in response["streams"]]
def get_summary(self, game=None):
params = {}
if game is not None:
params["game"] = game
response = self._request_get("streams/summary", params=params)
return response
def get_featured(self, limit=25, offset=0):
if limit > 100:
raise TwitchAttributeException(
<|code_end|>
. Write the next line using the current file imports:
from twitch.api.base import TwitchAPI
from twitch.constants import STREAM_TYPE_LIVE, STREAM_TYPES
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Featured, Stream
and context from other files:
# Path: twitch/api/base.py
# class TwitchAPI(object):
# """Twitch API client."""
#
# def __init__(self, client_id, oauth_token=None):
# """Initialize the API."""
# super(TwitchAPI, self).__init__()
# self._client_id = client_id
# self._oauth_token = oauth_token
# self._initial_backoff, self._max_retries = backoff_config()
#
# def _get_request_headers(self):
# """Prepare the headers for the requests."""
# headers = {
# "Accept": "application/vnd.twitchtv.v5+json",
# "Client-ID": self._client_id,
# }
#
# if self._oauth_token:
# headers["Authorization"] = "OAuth {}".format(self._oauth_token)
#
# return headers
#
# def _request_get(self, path, params=None, json=True, url=BASE_URL):
# """Perform a HTTP GET request."""
# url = urljoin(url, path)
# headers = self._get_request_headers()
#
# response = requests.get(url, params=params, headers=headers)
# if response.status_code >= 500:
#
# backoff = self._initial_backoff
# for _ in range(self._max_retries):
# time.sleep(backoff)
# backoff_response = requests.get(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# if backoff_response.status_code < 500:
# response = backoff_response
# break
# backoff *= 2
#
# response.raise_for_status()
# if json:
# return response.json()
# else:
# return response
#
# def _request_post(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP POST request.."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.post(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_put(self, path, data=None, params=None, url=BASE_URL):
# """Perform a HTTP PUT request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
# response = requests.put(
# url, json=data, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# def _request_delete(self, path, params=None, url=BASE_URL):
# """Perform a HTTP DELETE request."""
# url = urljoin(url, path)
#
# headers = self._get_request_headers()
#
# response = requests.delete(
# url, params=params, headers=headers, timeout=DEFAULT_TIMEOUT
# )
# response.raise_for_status()
# if response.status_code == 200:
# return response.json()
#
# Path: twitch/constants.py
# STREAM_TYPE_LIVE = "live"
#
# STREAM_TYPES = [STREAM_TYPE_LIVE, STREAM_TYPE_PLAYLIST, STREAM_TYPE_ALL]
#
# Path: twitch/decorators.py
# def oauth_required(func):
# def wrapper(*args, **kwargs):
# if not args[0]._oauth_token:
# raise TwitchAuthException("OAuth token required")
# return func(*args, **kwargs)
#
# return wrapper
#
# Path: twitch/exceptions.py
# class TwitchAttributeException(TwitchException):
# pass
#
# Path: twitch/resources.py
# class Featured(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
, which may include functions, classes, or code. Output only the next line. | "Maximum number of objects returned in one request is 100" |
Predict the next line for this snippet: <|code_start|> "name": ["--apply-changes"],
"default": False,
"switch": True,
"help": "apply {} after a successful rebase".format(CHANGES_PATCH),
},
{
"name": ["--disable-inapplicable-patches"],
"default": False,
"switch": True,
"dest": "disable_inapplicable_patches",
"help": "disable inapplicable patches in rebased SPEC file",
},
{
"name": ["--keep-comments"],
"default": False,
"switch": True,
"dest": "keep_comments",
"help": "do not remove associated comments when removing patches from spec file",
},
{
"name": ["--skip-version-check"],
"default": False,
"switch": True,
"help": "force rebase even if current version is newer than requested version",
},
{
"name": ["--update-sources"],
"default": False,
"switch": True,
"help": "update \"sources\" file and upload new sources to lookaside cache",
<|code_end|>
with the help of current file imports:
import os
from rebasehelper.types import Options
from rebasehelper.constants import CONFIG_PATH, CONFIG_FILENAME, CHANGES_PATCH
from rebasehelper.plugins.plugin_manager import plugin_manager
and context from other files:
# Path: rebasehelper/types.py
#
# Path: rebasehelper/constants.py
# CONFIG_PATH: str = '$XDG_CONFIG_HOME'
#
# CONFIG_FILENAME: str = 'rebase-helper.cfg'
#
# CHANGES_PATCH: str = 'changes.patch'
#
# Path: rebasehelper/plugins/plugin_manager.py
# class PluginManager:
# COLLECTIONS: List[Type[PluginCollection]] = [
# BuildLogHookCollection,
# BuildToolCollection,
# SRPMBuildToolCollection,
# CheckerCollection,
# OutputToolCollection,
# SpecHookCollection,
# VersioneerCollection,
# ]
# def __init__(self):
# def convert_class_name(class_name):
# def get_options(self) -> Options:
# def __getattr__(self, name):
, which may contain function names, class names, or code. Output only the next line. | }, |
Given snippet: <|code_start|> # behavior control
{
"name": ["--bugzilla-id"],
"metavar": "BUG_ID",
"default": None,
"help": "do a rebase based on Upstream Release Monitoring bugzilla"
},
{
"name": ["--non-interactive"],
"default": False,
"switch": True,
"dest": "non_interactive",
"help": "do not interact with user",
},
{
"name": ["--favor-on-conflict"],
"choices": ["downstream", "upstream", "off"],
"default": "off",
"dest": "favor_on_conflict",
"help": "favor downstream or upstream changes when conflicts appear",
},
{
"name": ["--not-download-sources"],
"default": False,
"switch": True,
"help": "do not download sources",
},
{
"name": ["-w", "--keep-workspace"],
"default": False,
<|code_end|>
, continue by predicting the next line. Consider current file imports:
import os
from rebasehelper.types import Options
from rebasehelper.constants import CONFIG_PATH, CONFIG_FILENAME, CHANGES_PATCH
from rebasehelper.plugins.plugin_manager import plugin_manager
and context:
# Path: rebasehelper/types.py
#
# Path: rebasehelper/constants.py
# CONFIG_PATH: str = '$XDG_CONFIG_HOME'
#
# CONFIG_FILENAME: str = 'rebase-helper.cfg'
#
# CHANGES_PATCH: str = 'changes.patch'
#
# Path: rebasehelper/plugins/plugin_manager.py
# class PluginManager:
# COLLECTIONS: List[Type[PluginCollection]] = [
# BuildLogHookCollection,
# BuildToolCollection,
# SRPMBuildToolCollection,
# CheckerCollection,
# OutputToolCollection,
# SpecHookCollection,
# VersioneerCollection,
# ]
# def __init__(self):
# def convert_class_name(class_name):
# def get_options(self) -> Options:
# def __getattr__(self, name):
which might include code, classes, or functions. Output only the next line. | "switch": True, |
Given the following code snippet before the placeholder: <|code_start|> "name": ["--srpm-builder-options"],
"default": None,
"metavar": "SRPM_BUILDER_OPTIONS",
"help": "enable arbitrary local srpm builder option(s), enclose %(metavar)s in quotes "
"to pass more than one",
},
# misc
{
"name": ["--lookaside-cache-preset"],
"choices": ["fedpkg", "centpkg", "rhpkg", "rhpkg-sha512"],
"default": "fedpkg",
"help": "use specified lookaside cache configuration preset, defaults to %(default)s",
},
{
"name": ["--changelog-entry"],
"default": "- New upstream release %{version}",
"help": "text to use as changelog entry, can contain RPM macros, which will be expanded",
},
{
"name": ["--no-changelog-entry"],
"default": False,
"switch": True,
"help": "do not add a changelog entry at all",
},
{
"name": ["--config-file"],
"default": os.path.join(CONFIG_PATH, CONFIG_FILENAME),
"help": "path to a configuration file, defaults to %(default)s",
},
{
<|code_end|>
, predict the next line using imports from the current file:
import os
from rebasehelper.types import Options
from rebasehelper.constants import CONFIG_PATH, CONFIG_FILENAME, CHANGES_PATCH
from rebasehelper.plugins.plugin_manager import plugin_manager
and context including class names, function names, and sometimes code from other files:
# Path: rebasehelper/types.py
#
# Path: rebasehelper/constants.py
# CONFIG_PATH: str = '$XDG_CONFIG_HOME'
#
# CONFIG_FILENAME: str = 'rebase-helper.cfg'
#
# CHANGES_PATCH: str = 'changes.patch'
#
# Path: rebasehelper/plugins/plugin_manager.py
# class PluginManager:
# COLLECTIONS: List[Type[PluginCollection]] = [
# BuildLogHookCollection,
# BuildToolCollection,
# SRPMBuildToolCollection,
# CheckerCollection,
# OutputToolCollection,
# SpecHookCollection,
# VersioneerCollection,
# ]
# def __init__(self):
# def convert_class_name(class_name):
# def get_options(self) -> Options:
# def __getattr__(self, name):
. Output only the next line. | "name": ["-D", "--define"], |
Given snippet: <|code_start|># GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Authors: Petr Hráček <phracek@redhat.com>
# Tomáš Hozza <thozza@redhat.com>
# Nikola Forró <nforro@redhat.com>
# František Nečas <fifinecas@seznam.cz>
OPTIONS: Options = [
# basic
{
"name": ["--version"],
"default": False,
"switch": True,
"help": "show rebase-helper version and exit",
},
# output control
{
"name": ["-v", "--verbose"],
"default": 0,
"counter": True,
"help": "be more verbose",
},
{
<|code_end|>
, continue by predicting the next line. Consider current file imports:
import os
from rebasehelper.types import Options
from rebasehelper.constants import CONFIG_PATH, CONFIG_FILENAME, CHANGES_PATCH
from rebasehelper.plugins.plugin_manager import plugin_manager
and context:
# Path: rebasehelper/types.py
#
# Path: rebasehelper/constants.py
# CONFIG_PATH: str = '$XDG_CONFIG_HOME'
#
# CONFIG_FILENAME: str = 'rebase-helper.cfg'
#
# CHANGES_PATCH: str = 'changes.patch'
#
# Path: rebasehelper/plugins/plugin_manager.py
# class PluginManager:
# COLLECTIONS: List[Type[PluginCollection]] = [
# BuildLogHookCollection,
# BuildToolCollection,
# SRPMBuildToolCollection,
# CheckerCollection,
# OutputToolCollection,
# SpecHookCollection,
# VersioneerCollection,
# ]
# def __init__(self):
# def convert_class_name(class_name):
# def get_options(self) -> Options:
# def __getattr__(self, name):
which might include code, classes, or functions. Output only the next line. | "name": ["--color"], |
Predict the next line after this snippet: <|code_start|> },
{
"name": ["--spec-hook-blacklist"],
"choices": plugin_manager.spec_hooks.get_all_plugins(),
"available_choices": plugin_manager.spec_hooks.get_supported_plugins(),
"nargs": "?",
"const": [""],
"default": [],
"type": lambda s: s.split(","),
"help": "prevent specified spec hooks from being run",
},
{
"name": ["--build-log-hook-blacklist"],
"choices": plugin_manager.build_log_hooks.get_all_plugins(),
"available_choices": plugin_manager.build_log_hooks.get_supported_plugins(),
"nargs": "?",
"const": [""],
"default": [],
"type": lambda s: s.split(","),
"help": "prevent specified build log hooks from being run"
},
# behavior control
{
"name": ["--bugzilla-id"],
"metavar": "BUG_ID",
"default": None,
"help": "do a rebase based on Upstream Release Monitoring bugzilla"
},
{
"name": ["--non-interactive"],
<|code_end|>
using the current file's imports:
import os
from rebasehelper.types import Options
from rebasehelper.constants import CONFIG_PATH, CONFIG_FILENAME, CHANGES_PATCH
from rebasehelper.plugins.plugin_manager import plugin_manager
and any relevant context from other files:
# Path: rebasehelper/types.py
#
# Path: rebasehelper/constants.py
# CONFIG_PATH: str = '$XDG_CONFIG_HOME'
#
# CONFIG_FILENAME: str = 'rebase-helper.cfg'
#
# CHANGES_PATCH: str = 'changes.patch'
#
# Path: rebasehelper/plugins/plugin_manager.py
# class PluginManager:
# COLLECTIONS: List[Type[PluginCollection]] = [
# BuildLogHookCollection,
# BuildToolCollection,
# SRPMBuildToolCollection,
# CheckerCollection,
# OutputToolCollection,
# SpecHookCollection,
# VersioneerCollection,
# ]
# def __init__(self):
# def convert_class_name(class_name):
# def get_options(self) -> Options:
# def __getattr__(self, name):
. Output only the next line. | "default": False, |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.