Instruction stringlengths 362 7.83k | output_code stringlengths 1 945 |
|---|---|
Based on the snippet: <|code_start|>
class MemberForm(ModelForm):
input_formats = ['%Y-%m-%d', '%y-%m-%d', '%d-%m-%y', '%d-%m-%Y',
'%Y/%m/%d', '%y/%m/%d', '%d/%m/%y', '%d/%m/%Y']
waiver_substitute = BooleanField(required=False, label='I have read and agree to the above terms & conditions.',
widget=CheckboxInput(attrs={'class': 'mdl-checkbox__input'}))
date_of_birth = DateField(required=False, input_formats=input_formats,
widget=DateInput(attrs={'class': 'mdl-textfield__input'}))
class Meta:
model = Member
exclude = ('waiver',)
fields = ['email', 'email_consent', 'first_name', 'last_name', 'preferred_name', 'date_of_birth',
'guardian_name', 'phone', 'street', 'city', 'province', 'country', 'post_code', 'waiver',
'banned', 'suspended', 'notes', 'involvement']
widgets = {
'email': EmailInput(attrs={'class': 'mdl-textfield__input'}),
'email_consent': CheckboxInput(attrs={'class': 'mdl-checkbox__input'}),
<|code_end|>
, predict the immediate next line with the help of imports:
from django.forms import ModelForm, EmailInput, TextInput, DateInput, CheckboxInput, BooleanField, Textarea, DateField, CheckboxSelectMultiple
from django.utils import timezone
from registration.models import Member
from core.models import Visit
and context (classes, functions, sometimes code) from other files:
# Path: registration/models.py
# class Member(models.Model):
# involvement_choices = (
# ('21cd9799b6', 'General (receive email)'),
# ('3a5a719017', 'Volunteering'),
# ('0ebb0b5468', 'Events'),
# ('84309225e7', 'Workshops'),
# ('c96d389517', 'Shop'),
# )
#
# user = models.OneToOneField(CustomUser, on_delete=models.CASCADE,
# null=True, blank=True)
# email = models.EmailField(
# verbose_name='email address',
# max_length=255,
# unique=False,
# null=True,
# blank=True,
# )
# email_consent = models.BooleanField(default=False, blank=False)
# first_name = models.CharField(max_length=255, null=False, blank=False)
# last_name = models.CharField(max_length=255, null=False, blank=False)
# preferred_name = models.CharField(max_length=255, null=True, blank=True)
# date_of_birth = models.DateField(null=True, blank=True)
# guardian_name = models.CharField(max_length=255, null=True, blank=True)
# phone = models.CharField(max_length=20, null=True, blank=True)
# street = models.CharField(max_length=255, null=True, blank=True)
# city = models.CharField(max_length=255, null=True, blank=True)
# province = models.CharField(max_length=255, null=True, blank=True)
# country = models.CharField(max_length=255, null=True, blank=True)
# post_code = models.CharField(max_length=20, null=True, blank=False)
# waiver = models.DateTimeField(null=True, blank=True)
# is_active = models.BooleanField(default=True)
# notes = models.TextField(null=True, blank=True)
# suspended = models.BooleanField(default=False)
# banned = models.BooleanField(default=False)
# created_at = models.DateTimeField(auto_now_add=True)
# modified_at = models.DateTimeField(auto_now=True)
# involvement = MultiSelectField(choices=involvement_choices, null=True, blank=True)
#
# @property
# def full_name(self):
# return self.get_full_name()
#
# def get_full_name(self):
# # The user is identified by their email address
# return '{0} {1}'.format(self.first_name, self.last_name)
#
# def get_short_name(self):
# # The user is identified by their email address
# if self.email:
# return self.email
# else:
# return self.last_name
#
# def __str__(self): # __unicode__ on Python 2
# return self.email
#
# Path: core/models.py
# class Visit(models.Model):
# VOLUNTEER = 'VOLUNTEER'
# FIX = 'FIX'
# BUILD = 'BUILD'
# WORKSHOP = 'WORKSHOP'
# VISIT = 'VISIT'
# DONATE = 'DONATE'
# STAFF = 'STAFF'
# PARTS = 'PARTS'
# BUY_BIKE = 'BUY_BIKE'
# TOUR = 'TOUR'
#
# visit_choices = (
# (VOLUNTEER, 'volunteer'),
# (FIX, 'fix bike'),
# (BUILD, 'build bike'),
# (WORKSHOP, 'workshop'),
# (VISIT, 'visit'),
# (DONATE, 'donate'),
# (STAFF, 'staff'),
# (PARTS, 'parts'),
# (BUY_BIKE, 'buy bike'),
# (TOUR, 'tour / visit')
# )
#
# member = models.ForeignKey(
# 'registration.Member',
# on_delete=models.CASCADE
# )
# created_at = models.DateTimeField(default=timezone.now)
# purpose = models.CharField(max_length=50, choices=visit_choices)
#
# def __str__(self):
# return '<Visit purpose: {purpose} created_at: {created_at}>'.format(purpose=self.purpose,
# created_at=self.created_at.isoformat())
. Output only the next line. | 'first_name': TextInput(attrs={'class': 'mdl-textfield__input'}), |
Using the snippet: <|code_start|>
class MemberForm(ModelForm):
input_formats = ['%Y-%m-%d', '%y-%m-%d', '%d-%m-%y', '%d-%m-%Y',
'%Y/%m/%d', '%y/%m/%d', '%d/%m/%y', '%d/%m/%Y']
waiver_substitute = BooleanField(required=False, label='I have read and agree to the above terms & conditions.',
widget=CheckboxInput(attrs={'class': 'mdl-checkbox__input'}))
date_of_birth = DateField(required=False, input_formats=input_formats,
<|code_end|>
, determine the next line of code. You have imports:
from django.forms import ModelForm, EmailInput, TextInput, DateInput, CheckboxInput, BooleanField, Textarea, DateField, CheckboxSelectMultiple
from django.utils import timezone
from registration.models import Member
from core.models import Visit
and context (class names, function names, or code) available:
# Path: registration/models.py
# class Member(models.Model):
# involvement_choices = (
# ('21cd9799b6', 'General (receive email)'),
# ('3a5a719017', 'Volunteering'),
# ('0ebb0b5468', 'Events'),
# ('84309225e7', 'Workshops'),
# ('c96d389517', 'Shop'),
# )
#
# user = models.OneToOneField(CustomUser, on_delete=models.CASCADE,
# null=True, blank=True)
# email = models.EmailField(
# verbose_name='email address',
# max_length=255,
# unique=False,
# null=True,
# blank=True,
# )
# email_consent = models.BooleanField(default=False, blank=False)
# first_name = models.CharField(max_length=255, null=False, blank=False)
# last_name = models.CharField(max_length=255, null=False, blank=False)
# preferred_name = models.CharField(max_length=255, null=True, blank=True)
# date_of_birth = models.DateField(null=True, blank=True)
# guardian_name = models.CharField(max_length=255, null=True, blank=True)
# phone = models.CharField(max_length=20, null=True, blank=True)
# street = models.CharField(max_length=255, null=True, blank=True)
# city = models.CharField(max_length=255, null=True, blank=True)
# province = models.CharField(max_length=255, null=True, blank=True)
# country = models.CharField(max_length=255, null=True, blank=True)
# post_code = models.CharField(max_length=20, null=True, blank=False)
# waiver = models.DateTimeField(null=True, blank=True)
# is_active = models.BooleanField(default=True)
# notes = models.TextField(null=True, blank=True)
# suspended = models.BooleanField(default=False)
# banned = models.BooleanField(default=False)
# created_at = models.DateTimeField(auto_now_add=True)
# modified_at = models.DateTimeField(auto_now=True)
# involvement = MultiSelectField(choices=involvement_choices, null=True, blank=True)
#
# @property
# def full_name(self):
# return self.get_full_name()
#
# def get_full_name(self):
# # The user is identified by their email address
# return '{0} {1}'.format(self.first_name, self.last_name)
#
# def get_short_name(self):
# # The user is identified by their email address
# if self.email:
# return self.email
# else:
# return self.last_name
#
# def __str__(self): # __unicode__ on Python 2
# return self.email
#
# Path: core/models.py
# class Visit(models.Model):
# VOLUNTEER = 'VOLUNTEER'
# FIX = 'FIX'
# BUILD = 'BUILD'
# WORKSHOP = 'WORKSHOP'
# VISIT = 'VISIT'
# DONATE = 'DONATE'
# STAFF = 'STAFF'
# PARTS = 'PARTS'
# BUY_BIKE = 'BUY_BIKE'
# TOUR = 'TOUR'
#
# visit_choices = (
# (VOLUNTEER, 'volunteer'),
# (FIX, 'fix bike'),
# (BUILD, 'build bike'),
# (WORKSHOP, 'workshop'),
# (VISIT, 'visit'),
# (DONATE, 'donate'),
# (STAFF, 'staff'),
# (PARTS, 'parts'),
# (BUY_BIKE, 'buy bike'),
# (TOUR, 'tour / visit')
# )
#
# member = models.ForeignKey(
# 'registration.Member',
# on_delete=models.CASCADE
# )
# created_at = models.DateTimeField(default=timezone.now)
# purpose = models.CharField(max_length=50, choices=visit_choices)
#
# def __str__(self):
# return '<Visit purpose: {purpose} created_at: {created_at}>'.format(purpose=self.purpose,
# created_at=self.created_at.isoformat())
. Output only the next line. | widget=DateInput(attrs={'class': 'mdl-textfield__input'})) |
Given the code snippet: <|code_start|>
class CustomUserChangeForm(UserChangeForm):
class Meta(UserChangeForm.Meta):
model = CustomUser
@admin.register(CustomUser)
class CustomUserAdmin(UserAdmin):
form = CustomUserChangeForm
fieldsets = (
(None, {'fields': ('email', 'password')}),
('Permissions', {'fields': ('is_active', 'is_superuser', 'is_admin', 'groups', 'user_permissions')}),
('Important dates', {'fields': ('last_login',)}),
)
add_fieldsets = (
<|code_end|>
, generate the next line using the imports in this file:
from django.contrib import admin
from .models import CustomUser, Member
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.forms import UserChangeForm
and context (functions, classes, or occasionally code) from other files:
# Path: registration/models.py
# class CustomUser(AbstractBaseUser, PermissionsMixin):
# email = models.EmailField(
# verbose_name='email address',
# max_length=255,
# unique=True,
# )
# is_admin = models.BooleanField(default=False)
# is_active = models.BooleanField(default=True)
#
# objects = CustomUserManager()
#
# USERNAME_FIELD = 'email'
#
# @property
# def is_staff(self):
# # Simplest possible answer: All admins are staff
# return self.is_admin
#
# def get_short_name(self):
# return self.email
#
# def get_full_name(self):
# return self.email
#
# def __str__(self): # __unicode__ on Python 2
# return self.email
#
# class Meta:
# verbose_name = 'User'
# verbose_name_plural = 'Users'
#
# class Member(models.Model):
# involvement_choices = (
# ('21cd9799b6', 'General (receive email)'),
# ('3a5a719017', 'Volunteering'),
# ('0ebb0b5468', 'Events'),
# ('84309225e7', 'Workshops'),
# ('c96d389517', 'Shop'),
# )
#
# user = models.OneToOneField(CustomUser, on_delete=models.CASCADE,
# null=True, blank=True)
# email = models.EmailField(
# verbose_name='email address',
# max_length=255,
# unique=False,
# null=True,
# blank=True,
# )
# email_consent = models.BooleanField(default=False, blank=False)
# first_name = models.CharField(max_length=255, null=False, blank=False)
# last_name = models.CharField(max_length=255, null=False, blank=False)
# preferred_name = models.CharField(max_length=255, null=True, blank=True)
# date_of_birth = models.DateField(null=True, blank=True)
# guardian_name = models.CharField(max_length=255, null=True, blank=True)
# phone = models.CharField(max_length=20, null=True, blank=True)
# street = models.CharField(max_length=255, null=True, blank=True)
# city = models.CharField(max_length=255, null=True, blank=True)
# province = models.CharField(max_length=255, null=True, blank=True)
# country = models.CharField(max_length=255, null=True, blank=True)
# post_code = models.CharField(max_length=20, null=True, blank=False)
# waiver = models.DateTimeField(null=True, blank=True)
# is_active = models.BooleanField(default=True)
# notes = models.TextField(null=True, blank=True)
# suspended = models.BooleanField(default=False)
# banned = models.BooleanField(default=False)
# created_at = models.DateTimeField(auto_now_add=True)
# modified_at = models.DateTimeField(auto_now=True)
# involvement = MultiSelectField(choices=involvement_choices, null=True, blank=True)
#
# @property
# def full_name(self):
# return self.get_full_name()
#
# def get_full_name(self):
# # The user is identified by their email address
# return '{0} {1}'.format(self.first_name, self.last_name)
#
# def get_short_name(self):
# # The user is identified by their email address
# if self.email:
# return self.email
# else:
# return self.last_name
#
# def __str__(self): # __unicode__ on Python 2
# return self.email
. Output only the next line. | (None, { |
Predict the next line after this snippet: <|code_start|>
jobAllMD = PyContactJob("./PyContact/exampleData/rpn11_ubq_interface-ionized.psf","./PyContact/exampleData/short.dcd", "test", JobConfig(5.0, 2.5, 120, [0,0,0,1,1,0], [0,0,0,1,1,0], "segid UBQ", "segid RN11"))
jobAllMD.runJob(1)
# jobAllMD.writeSessionToFile()
contacts = jobAllMD.analyzer.finalAccumulatedContacts
filter = ScoreFilter("score", "greater", 0.0, u"Median")
contacts = filter.filterContacts(contacts)
N = len(contacts)
frames = len(jobAllMD.analyzer.contactResults)
print("frms:", frames)
covMatrix = np.zeros((N, N))
idx1 = 0
r_vec = np.zeros((N, frames))
r_names = np.zeros(N).tolist()
for c1 in contacts:
<|code_end|>
using the current file's imports:
from PyContact.core.Scripting import (PyContactJob, JobConfig)
from PyContact.core.ContactFilters import ScoreFilter
from numpy import linalg as LA
from sklearn.decomposition import PCA
from sklearn.manifold import TSNE
import numpy as np
import matplotlib.pyplot as plt
and any relevant context from other files:
# Path: PyContact/core/Scripting.py
# class PyContactJob:
# """Job class that is given a JobConfig and input files and handles
# running/analyzing the job as such."""
# def __init__(self, topo, traj, name, configuration):
# self.topo = topo
# self.traj = traj
# self.name = name
# self.configuration = configuration
# self.analyzer = None
#
# def runJob(self, ncores=1):
# """Runs contact analysis and accumulation with ncores threads."""
# print("Running job: " + self.name + " on " + str(ncores) + " cores.")
# self.analyzer = Analyzer(self.topo,self.traj, self.configuration.cutoff, self.configuration.hbondcutoff, self.configuration.hbondcutangle, self.configuration.sel1, self.configuration.sel2)
# self.analyzer.runFrameScan(ncores)
# self.analyzer.runContactAnalysis(self.configuration.map1, self.configuration.map2, ncores)
#
# def writeSessionToFile(self, fname=""):
# """Writes the current analysis session to a file with either self.name + .session or fname as output filename"""
# if fname != "":
# DataHandler.writeSessionToFile(fname, self.analyzer)
# else:
# DataHandler.writeSessionToFile(self.name + ".session", self.analyzer)
# print("Wrote session to file")
#
# class JobConfig:
# """Configuration/Settings for a PyContact contact analysis job"""
# def __init__(self, cutoff, hbondcutoff, hbondcutangle, map1, map2, sel1, sel2):
# self.cutoff = cutoff
# self.hbondcutoff = hbondcutoff
# self.hbondcutangle = hbondcutangle
# self.map1 = map1
# self.map2 = map2
# self.sel1 = sel1
# self.sel2 = sel2
#
# Path: PyContact/core/ContactFilters.py
# class ScoreFilter(BinaryFilter):
# """Compares contact score of every frame, only adds contact if true for all frames."""
# def __init__(self, name, operator, value, ftype):
# super(ScoreFilter, self).__init__(name, operator, value)
# self.ftype = ftype
#
# def filterContacts(self, contacts):
# filtered = []
# op = Operator()
# if self.ftype == u"Mean":
# for c in contacts:
# mean = c.mean_score()
# if op.compare(mean, self.value, self.operator):
# filtered.append(c)
# elif self.ftype == u"Median":
# for c in contacts:
# med = c.median_score()
# if op.compare(med, self.value, self.operator):
# filtered.append(c)
# elif self.ftype == u"HB %":
# for c in contacts:
# med = c.hbond_percentage()
# print(med)
# if op.compare(med, self.value, self.operator):
# filtered.append(c)
# return filtered
. Output only the next line. | for f in range(frames): |
Next line prediction: <|code_start|>
jobAllMD = PyContactJob("./PyContact/exampleData/rpn11_ubq_interface-ionized.psf","./PyContact/exampleData/short.dcd", "test", JobConfig(5.0, 2.5, 120, [0,0,0,1,1,0], [0,0,0,1,1,0], "segid UBQ", "segid RN11"))
jobAllMD.runJob(1)
# jobAllMD.writeSessionToFile()
contacts = jobAllMD.analyzer.finalAccumulatedContacts
filter = ScoreFilter("score", "greater", 0.0, u"Median")
contacts = filter.filterContacts(contacts)
N = len(contacts)
frames = len(jobAllMD.analyzer.contactResults)
print("frms:", frames)
covMatrix = np.zeros((N, N))
idx1 = 0
r_vec = np.zeros((N, frames))
r_names = np.zeros(N).tolist()
for c1 in contacts:
for f in range(frames):
r_vec[idx1, f] = c1.scoreArray[f]
r_names[idx1] = c1.human_readable_title()
idx1 += 1
<|code_end|>
. Use current file imports:
(from PyContact.core.Scripting import (PyContactJob, JobConfig)
from PyContact.core.ContactFilters import ScoreFilter
from numpy import linalg as LA
from sklearn.decomposition import PCA
from sklearn.manifold import TSNE
import numpy as np
import matplotlib.pyplot as plt)
and context including class names, function names, or small code snippets from other files:
# Path: PyContact/core/Scripting.py
# class PyContactJob:
# """Job class that is given a JobConfig and input files and handles
# running/analyzing the job as such."""
# def __init__(self, topo, traj, name, configuration):
# self.topo = topo
# self.traj = traj
# self.name = name
# self.configuration = configuration
# self.analyzer = None
#
# def runJob(self, ncores=1):
# """Runs contact analysis and accumulation with ncores threads."""
# print("Running job: " + self.name + " on " + str(ncores) + " cores.")
# self.analyzer = Analyzer(self.topo,self.traj, self.configuration.cutoff, self.configuration.hbondcutoff, self.configuration.hbondcutangle, self.configuration.sel1, self.configuration.sel2)
# self.analyzer.runFrameScan(ncores)
# self.analyzer.runContactAnalysis(self.configuration.map1, self.configuration.map2, ncores)
#
# def writeSessionToFile(self, fname=""):
# """Writes the current analysis session to a file with either self.name + .session or fname as output filename"""
# if fname != "":
# DataHandler.writeSessionToFile(fname, self.analyzer)
# else:
# DataHandler.writeSessionToFile(self.name + ".session", self.analyzer)
# print("Wrote session to file")
#
# class JobConfig:
# """Configuration/Settings for a PyContact contact analysis job"""
# def __init__(self, cutoff, hbondcutoff, hbondcutangle, map1, map2, sel1, sel2):
# self.cutoff = cutoff
# self.hbondcutoff = hbondcutoff
# self.hbondcutangle = hbondcutangle
# self.map1 = map1
# self.map2 = map2
# self.sel1 = sel1
# self.sel2 = sel2
#
# Path: PyContact/core/ContactFilters.py
# class ScoreFilter(BinaryFilter):
# """Compares contact score of every frame, only adds contact if true for all frames."""
# def __init__(self, name, operator, value, ftype):
# super(ScoreFilter, self).__init__(name, operator, value)
# self.ftype = ftype
#
# def filterContacts(self, contacts):
# filtered = []
# op = Operator()
# if self.ftype == u"Mean":
# for c in contacts:
# mean = c.mean_score()
# if op.compare(mean, self.value, self.operator):
# filtered.append(c)
# elif self.ftype == u"Median":
# for c in contacts:
# med = c.median_score()
# if op.compare(med, self.value, self.operator):
# filtered.append(c)
# elif self.ftype == u"HB %":
# for c in contacts:
# med = c.hbond_percentage()
# print(med)
# if op.compare(med, self.value, self.operator):
# filtered.append(c)
# return filtered
. Output only the next line. | pca = PCA(n_components=10) |
Given the following code snippet before the placeholder: <|code_start|>"""contains classes in order to faciliate scripting the PyContact package."""
class JobConfig:
"""Configuration/Settings for a PyContact contact analysis job"""
def __init__(self, cutoff, hbondcutoff, hbondcutangle, map1, map2, sel1, sel2):
self.cutoff = cutoff
self.hbondcutoff = hbondcutoff
self.hbondcutangle = hbondcutangle
self.map1 = map1
self.map2 = map2
self.sel1 = sel1
self.sel2 = sel2
class PyContactJob:
"""Job class that is given a JobConfig and input files and handles
running/analyzing the job as such."""
def __init__(self, topo, traj, name, configuration):
self.topo = topo
self.traj = traj
self.name = name
<|code_end|>
, predict the next line using imports from the current file:
from PyContact.core.ContactAnalyzer import *
from PyContact.core.DataHandler import DataHandler
and context including class names, function names, and sometimes code from other files:
# Path: PyContact/core/DataHandler.py
# class DataHandler:
# """Handles the import or export of a session."""
#
# @staticmethod
# def importSessionFromFile(fileName):
# """Imports a saved session from 'filename'."""
# importDict = pickle.load(open(fileName, "rb"))
# contacts = importDict["contacts"]
# arguments = importDict["analyzer"][0:-1]
# trajArgs = importDict["trajectory"]
# maps = importDict["maps"]
# contactResults = importDict["analyzer"][-1]
# del importDict
# return [contacts, arguments, trajArgs, maps, contactResults]
#
# @staticmethod
# def writeSessionToFile(fileName, analysis):
# """Saves the current Session (analysis) at 'filename'."""
# analyzerArgs = [analysis.psf, analysis.dcd, analysis.cutoff, analysis.hbondcutoff,
# analysis.hbondcutangle, analysis.sel1text, analysis.sel2text,
# analysis.contactResults]
# trajArgs = analysis.getTrajectoryData()
# exportDict = {"contacts": analysis.finalAccumulatedContacts, "analyzer": analyzerArgs, "trajectory": trajArgs,
# "maps": [analysis.lastMap1, analysis.lastMap2]}
# pickle.dump(exportDict, open(fileName, "wb"))
. Output only the next line. | self.configuration = configuration |
Here is a snippet: <|code_start|>multiprocessing.log_to_stderr()
sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
class PsfDcdReadingTest(TestCase):
def setUp(self):
self.dcdfile = DCD
self.psffile = PSF
self.tpr = TPR
self.xtc = XTC
def tearDown(self):
del self.dcdfile
del self.psffile
def test_import_dcd_file(self):
mda.Universe(self.psffile, self.dcdfile)
<|code_end|>
. Write the next line using the current file imports:
from unittest import TestCase
from os import path
from PyContact.core.ContactAnalyzer import *
from PyContact.exampleData.datafiles import DCD, PSF, TPR, XTC
import sys
import MDAnalysis as mda
import multiprocessing
and context from other files:
# Path: PyContact/exampleData/datafiles.py
# DCD = res(__name__, './rpn11_ubq.dcd')
#
# PSF = res(__name__, './rpn11_ubq.psf')
#
# TPR = res(__name__, './md.tpr')
#
# XTC = res(__name__, './md_noPBC.xtc')
, which may include functions, classes, or code. Output only the next line. | def test_import_xtc_file(self): |
Given the following code snippet before the placeholder: <|code_start|>
def tearDown(self):
del self.dcdfile
del self.psffile
def test_import_dcd_file(self):
mda.Universe(self.psffile, self.dcdfile)
def test_import_xtc_file(self):
# seg_0_Protein_chain_U
# seg_1_Protein_chain_R
mda.Universe(self.tpr, self.xtc)
def test_singleCore_analysis(self):
analyzer = Analyzer(self.psffile, self.dcdfile, 5.0, 2.5, 120, "segid RN11", "segid UBQ")
analyzer.runFrameScan(1)
self.assertEqual(len(analyzer.contactResults), 50)
map1 = [0, 0, 1, 1, 0]
map2 = [0, 0, 1, 1, 0]
analyzer.runContactAnalysis(map1, map2, 1)
self.assertEqual(len(analyzer.finalAccumulatedContacts), 148)
hbond_sum = 0
for c in analyzer.finalAccumulatedContacts:
hbond_sum += c.hbond_percentage()
self.assertEqual(hbond_sum, 676.0)
def test_selfInteraction_analysis(self):
analyzer = Analyzer(self.psffile, self.dcdfile, 5.0, 2.5, 120, "segid RN11", "self")
analyzer.runFrameScan(1)
self.assertEqual(len(analyzer.contactResults), 50)
<|code_end|>
, predict the next line using imports from the current file:
from unittest import TestCase
from os import path
from PyContact.core.ContactAnalyzer import *
from PyContact.exampleData.datafiles import DCD, PSF, TPR, XTC
import sys
import MDAnalysis as mda
import multiprocessing
and context including class names, function names, and sometimes code from other files:
# Path: PyContact/exampleData/datafiles.py
# DCD = res(__name__, './rpn11_ubq.dcd')
#
# PSF = res(__name__, './rpn11_ubq.psf')
#
# TPR = res(__name__, './md.tpr')
#
# XTC = res(__name__, './md_noPBC.xtc')
. Output only the next line. | map1 = [0, 0, 1, 1, 0] |
Given the following code snippet before the placeholder: <|code_start|> self.assertEqual(len(analyzer.finalAccumulatedContacts), 148)
hbond_sum = 0
for c in analyzer.finalAccumulatedContacts:
hbond_sum += c.hbond_percentage()
self.assertEqual(hbond_sum, 676.0)
def test_selfInteraction_analysis(self):
analyzer = Analyzer(self.psffile, self.dcdfile, 5.0, 2.5, 120, "segid RN11", "self")
analyzer.runFrameScan(1)
self.assertEqual(len(analyzer.contactResults), 50)
map1 = [0, 0, 1, 1, 0]
map2 = [0, 0, 1, 1, 0]
analyzer.runContactAnalysis(map1, map2, 1)
def test_zero_atomselection(self):
analyzer = Analyzer(self.psffile, self.dcdfile, 5.0, 2.5, 120, "segid A", "resid 100")
try:
analyzer.runFrameScan(1)
except:
print("Error in atom selection caught.")
try:
analyzer.runFrameScan(4)
except:
print("Error in atom selection (multicore) caught.")
def test_selfInteraction_analysis_parallel(self):
analyzer = Analyzer(self.psffile, self.dcdfile, 5.0, 2.5, 120, "segid RN11", "self")
analyzer.runFrameScan(2)
self.assertEqual(len(analyzer.contactResults), 50)
<|code_end|>
, predict the next line using imports from the current file:
from unittest import TestCase
from os import path
from PyContact.core.ContactAnalyzer import *
from PyContact.exampleData.datafiles import DCD, PSF, TPR, XTC
import sys
import MDAnalysis as mda
import multiprocessing
and context including class names, function names, and sometimes code from other files:
# Path: PyContact/exampleData/datafiles.py
# DCD = res(__name__, './rpn11_ubq.dcd')
#
# PSF = res(__name__, './rpn11_ubq.psf')
#
# TPR = res(__name__, './md.tpr')
#
# XTC = res(__name__, './md_noPBC.xtc')
. Output only the next line. | map1 = [0, 0, 1, 1, 0] |
Based on the snippet: <|code_start|>
try:
analyzer.runFrameScan(4)
except:
print("Error in atom selection (multicore) caught.")
def test_selfInteraction_analysis_parallel(self):
analyzer = Analyzer(self.psffile, self.dcdfile, 5.0, 2.5, 120, "segid RN11", "self")
analyzer.runFrameScan(2)
self.assertEqual(len(analyzer.contactResults), 50)
map1 = [0, 0, 1, 1, 0]
map2 = [0, 0, 1, 1, 0]
analyzer.runContactAnalysis(map1, map2, 1)
def test_multiCore_analysis(self):
analyzer = Analyzer(self.psffile, self.dcdfile, 5.0, 2.5, 120, "segid RN11", "segid UBQ")
analyzer.runFrameScan(2)
self.assertEqual(len(analyzer.contactResults), 50)
map1 = [0, 0, 1, 1, 0]
map2 = [0, 0, 1, 1, 0]
analyzer.runContactAnalysis(map1, map2, 2)
self.assertEqual(len(analyzer.finalAccumulatedContacts), 148)
hbond_sum = 0
for c in analyzer.finalAccumulatedContacts:
hbond_sum += c.hbond_percentage()
self.assertEqual(hbond_sum, 676.0)
def test_around_selection_patch(self):
univ = mda.Universe(self.psffile, self.dcdfile)
aroundText = "segid UBQ and around 5 segid RN11"
<|code_end|>
, predict the immediate next line with the help of imports:
from unittest import TestCase
from os import path
from PyContact.core.ContactAnalyzer import *
from PyContact.exampleData.datafiles import DCD, PSF, TPR, XTC
import sys
import MDAnalysis as mda
import multiprocessing
and context (classes, functions, sometimes code) from other files:
# Path: PyContact/exampleData/datafiles.py
# DCD = res(__name__, './rpn11_ubq.dcd')
#
# PSF = res(__name__, './rpn11_ubq.psf')
#
# TPR = res(__name__, './md.tpr')
#
# XTC = res(__name__, './md_noPBC.xtc')
. Output only the next line. | sel = univ.select_atoms(aroundText) |
Given snippet: <|code_start|>
class Statistics(QWidget, Ui_Statistics):
def __init__(self, data, nspf, parent=None):
super(QWidget, self).__init__(parent)
self.setupUi(self)
self.contacts = data
self.nsPerFrame = nspf
self.labelNumFrames.setText(str(len(self.contacts[0].scoreArray)))
self.labelTotalContacts.setText(str(len(self.contacts)))
self.labelMeanScore.setText(str(mean_score_of_contactArray(self.contacts)))
self.labelMedianScore.setText(str(median_score_of_contactArray(self.contacts)))
self.savePlotButton.clicked.connect(self.savePlot)
self.plotButton.clicked.connect(self.plotAttribute)
posIntValidator = QIntValidator()
<|code_end|>
, continue by predicting the next line. Consider current file imports:
import sip
import os
from PyQt5.QtWidgets import QWidget, QFileDialog
from PyQt5.QtGui import QIntValidator
from .Plotters import ContactPlotter
from .statistics_ui import *
from ..core.LogPool import *
from .ErrorBox import ErrorBox
from ..core.Biochemistry import mean_score_of_contactArray, median_score_of_contactArray
and context:
# Path: PyContact/gui/Plotters.py
# class ContactPlotter(MplPlotter):
# """Plots a frame-score plot with lines."""
#
# def plot_contact_figure(self, contact, nsPerFrame):
# frames = np.arange(0, len(contact.scoreArray), 1) * nsPerFrame
# self.axes.plot(frames, contact.scoreArray)
# self.axes.set_xlabel("time [ns]")
# self.axes.set_ylabel("score")
#
# def plot_all_contacts_figure(self, contacts, smooth, nsPerFrame):
# values = []
#
# for frame in range(len(contacts[0].scoreArray)):
# current = 0
# for c in contacts:
# current += c.scoreArray[frame]
# values.append(current)
# frames = np.arange(0, len(values), 1) * nsPerFrame
# if smooth:
# val = self.savitzky_golay(np.array(values), smooth, 2)
# smaller = np.where(val < 0)
# val[smaller] = 0
# self.axes.plot(val)
# else:
# self.axes.plot(values)
# self.axes.set_xlabel("time [ns]")
# self.axes.set_ylabel("score")
#
# def plot_hbondNumber(self, contacts, smooth, nsPerFrame):
# values = []
# for c in contacts:
# c.hbondFramesScan()
#
# for frame in range(len(contacts[0].scoreArray)):
# current = 0
# for c in contacts:
# current += c.hbondFrames[frame]
# values.append(current)
# frames = np.arange(0, len(values), 1) * nsPerFrame
# if smooth:
# val = self.savitzky_golay(np.array(values), smooth, 2)
# smaller = np.where(val < 0)
# val[smaller] = 0
# self.axes.plot(frames, val)
# else:
# self.axes.plot(frames, values)
# self.axes.set_xlabel("time [ns]")
# self.axes.set_ylabel("hbond number")
#
# # from http://scipy.github.io/old-wiki/pages/Cookbook/SavitzkyGolay
# def savitzky_golay(self, y, window_size, order, deriv=0, rate=1):
#
# try:
# window_size = np.abs(np.int(window_size))
# order = np.abs(np.int(order))
# except ValueError:
# raise ValueError("window_size and order have to be of type int")
# if window_size % 2 != 1 or window_size < 1:
# raise TypeError("window_size size must be a positive odd number")
# if window_size < order + 2:
# raise TypeError("window_size is too small for the polynomials order")
# order_range = range(order+1)
# half_window = (window_size -1) // 2
# # precompute coefficients
# b = np.mat([[k**i for i in order_range] for k in range(-half_window, half_window+1)])
# m = np.linalg.pinv(b).A[deriv] * rate**deriv * factorial(deriv)
# # pad the signal at the extremes with
# # values taken from the signal itself
# firstvals = y[0] - np.abs( y[1:half_window+1][::-1] - y[0] )
# lastvals = y[-1] + np.abs(y[-half_window-1:-1][::-1] - y[-1])
# y = np.concatenate((firstvals, y, lastvals))
# return np.convolve( m[::-1], y, mode='valid')
#
# def saveFigure(self, path, outputFormat):
# self.fig.savefig(path + "." + outputFormat, format=outputFormat)
#
# Path: PyContact/gui/ErrorBox.py
# class ErrorBox(QMessageBox):
# """Creates an Error dialog which displays the corresponding error message 'msg'."""
# def __init__(self, msg):
# super(ErrorBox, self).__init__()
# self.msg = msg
# self.setIcon(QMessageBox.Warning)
# self.setText(self.msg)
# self.setWindowTitle("Error")
# self.setStandardButtons(QMessageBox.Ok)
#
# Path: PyContact/core/Biochemistry.py
# def mean_score_of_contactArray(contacts):
# """Computes the mean score using the contacts array."""
# meanList = []
# for c in contacts:
# meanList = np.concatenate((meanList, c.scoreArray), axis=0)
# return np.mean(meanList)
#
# def median_score_of_contactArray(contacts):
# """Computes the mean score using the contacts array."""
# medianList = []
# for c in contacts:
# medianList = np.concatenate((medianList, c.scoreArray), axis=0)
# return np.median(medianList)
which might include code, classes, or functions. Output only the next line. | posIntValidator.setBottom(3) |
Continue the code snippet: <|code_start|>
class Statistics(QWidget, Ui_Statistics):
def __init__(self, data, nspf, parent=None):
super(QWidget, self).__init__(parent)
self.setupUi(self)
self.contacts = data
<|code_end|>
. Use current file imports:
import sip
import os
from PyQt5.QtWidgets import QWidget, QFileDialog
from PyQt5.QtGui import QIntValidator
from .Plotters import ContactPlotter
from .statistics_ui import *
from ..core.LogPool import *
from .ErrorBox import ErrorBox
from ..core.Biochemistry import mean_score_of_contactArray, median_score_of_contactArray
and context (classes, functions, or code) from other files:
# Path: PyContact/gui/Plotters.py
# class ContactPlotter(MplPlotter):
# """Plots a frame-score plot with lines."""
#
# def plot_contact_figure(self, contact, nsPerFrame):
# frames = np.arange(0, len(contact.scoreArray), 1) * nsPerFrame
# self.axes.plot(frames, contact.scoreArray)
# self.axes.set_xlabel("time [ns]")
# self.axes.set_ylabel("score")
#
# def plot_all_contacts_figure(self, contacts, smooth, nsPerFrame):
# values = []
#
# for frame in range(len(contacts[0].scoreArray)):
# current = 0
# for c in contacts:
# current += c.scoreArray[frame]
# values.append(current)
# frames = np.arange(0, len(values), 1) * nsPerFrame
# if smooth:
# val = self.savitzky_golay(np.array(values), smooth, 2)
# smaller = np.where(val < 0)
# val[smaller] = 0
# self.axes.plot(val)
# else:
# self.axes.plot(values)
# self.axes.set_xlabel("time [ns]")
# self.axes.set_ylabel("score")
#
# def plot_hbondNumber(self, contacts, smooth, nsPerFrame):
# values = []
# for c in contacts:
# c.hbondFramesScan()
#
# for frame in range(len(contacts[0].scoreArray)):
# current = 0
# for c in contacts:
# current += c.hbondFrames[frame]
# values.append(current)
# frames = np.arange(0, len(values), 1) * nsPerFrame
# if smooth:
# val = self.savitzky_golay(np.array(values), smooth, 2)
# smaller = np.where(val < 0)
# val[smaller] = 0
# self.axes.plot(frames, val)
# else:
# self.axes.plot(frames, values)
# self.axes.set_xlabel("time [ns]")
# self.axes.set_ylabel("hbond number")
#
# # from http://scipy.github.io/old-wiki/pages/Cookbook/SavitzkyGolay
# def savitzky_golay(self, y, window_size, order, deriv=0, rate=1):
#
# try:
# window_size = np.abs(np.int(window_size))
# order = np.abs(np.int(order))
# except ValueError:
# raise ValueError("window_size and order have to be of type int")
# if window_size % 2 != 1 or window_size < 1:
# raise TypeError("window_size size must be a positive odd number")
# if window_size < order + 2:
# raise TypeError("window_size is too small for the polynomials order")
# order_range = range(order+1)
# half_window = (window_size -1) // 2
# # precompute coefficients
# b = np.mat([[k**i for i in order_range] for k in range(-half_window, half_window+1)])
# m = np.linalg.pinv(b).A[deriv] * rate**deriv * factorial(deriv)
# # pad the signal at the extremes with
# # values taken from the signal itself
# firstvals = y[0] - np.abs( y[1:half_window+1][::-1] - y[0] )
# lastvals = y[-1] + np.abs(y[-half_window-1:-1][::-1] - y[-1])
# y = np.concatenate((firstvals, y, lastvals))
# return np.convolve( m[::-1], y, mode='valid')
#
# def saveFigure(self, path, outputFormat):
# self.fig.savefig(path + "." + outputFormat, format=outputFormat)
#
# Path: PyContact/gui/ErrorBox.py
# class ErrorBox(QMessageBox):
# """Creates an Error dialog which displays the corresponding error message 'msg'."""
# def __init__(self, msg):
# super(ErrorBox, self).__init__()
# self.msg = msg
# self.setIcon(QMessageBox.Warning)
# self.setText(self.msg)
# self.setWindowTitle("Error")
# self.setStandardButtons(QMessageBox.Ok)
#
# Path: PyContact/core/Biochemistry.py
# def mean_score_of_contactArray(contacts):
# """Computes the mean score using the contacts array."""
# meanList = []
# for c in contacts:
# meanList = np.concatenate((meanList, c.scoreArray), axis=0)
# return np.mean(meanList)
#
# def median_score_of_contactArray(contacts):
# """Computes the mean score using the contacts array."""
# medianList = []
# for c in contacts:
# medianList = np.concatenate((medianList, c.scoreArray), axis=0)
# return np.median(medianList)
. Output only the next line. | self.nsPerFrame = nspf |
Next line prediction: <|code_start|>
class Statistics(QWidget, Ui_Statistics):
def __init__(self, data, nspf, parent=None):
super(QWidget, self).__init__(parent)
self.setupUi(self)
self.contacts = data
<|code_end|>
. Use current file imports:
(import sip
import os
from PyQt5.QtWidgets import QWidget, QFileDialog
from PyQt5.QtGui import QIntValidator
from .Plotters import ContactPlotter
from .statistics_ui import *
from ..core.LogPool import *
from .ErrorBox import ErrorBox
from ..core.Biochemistry import mean_score_of_contactArray, median_score_of_contactArray)
and context including class names, function names, or small code snippets from other files:
# Path: PyContact/gui/Plotters.py
# class ContactPlotter(MplPlotter):
# """Plots a frame-score plot with lines."""
#
# def plot_contact_figure(self, contact, nsPerFrame):
# frames = np.arange(0, len(contact.scoreArray), 1) * nsPerFrame
# self.axes.plot(frames, contact.scoreArray)
# self.axes.set_xlabel("time [ns]")
# self.axes.set_ylabel("score")
#
# def plot_all_contacts_figure(self, contacts, smooth, nsPerFrame):
# values = []
#
# for frame in range(len(contacts[0].scoreArray)):
# current = 0
# for c in contacts:
# current += c.scoreArray[frame]
# values.append(current)
# frames = np.arange(0, len(values), 1) * nsPerFrame
# if smooth:
# val = self.savitzky_golay(np.array(values), smooth, 2)
# smaller = np.where(val < 0)
# val[smaller] = 0
# self.axes.plot(val)
# else:
# self.axes.plot(values)
# self.axes.set_xlabel("time [ns]")
# self.axes.set_ylabel("score")
#
# def plot_hbondNumber(self, contacts, smooth, nsPerFrame):
# values = []
# for c in contacts:
# c.hbondFramesScan()
#
# for frame in range(len(contacts[0].scoreArray)):
# current = 0
# for c in contacts:
# current += c.hbondFrames[frame]
# values.append(current)
# frames = np.arange(0, len(values), 1) * nsPerFrame
# if smooth:
# val = self.savitzky_golay(np.array(values), smooth, 2)
# smaller = np.where(val < 0)
# val[smaller] = 0
# self.axes.plot(frames, val)
# else:
# self.axes.plot(frames, values)
# self.axes.set_xlabel("time [ns]")
# self.axes.set_ylabel("hbond number")
#
# # from http://scipy.github.io/old-wiki/pages/Cookbook/SavitzkyGolay
# def savitzky_golay(self, y, window_size, order, deriv=0, rate=1):
#
# try:
# window_size = np.abs(np.int(window_size))
# order = np.abs(np.int(order))
# except ValueError:
# raise ValueError("window_size and order have to be of type int")
# if window_size % 2 != 1 or window_size < 1:
# raise TypeError("window_size size must be a positive odd number")
# if window_size < order + 2:
# raise TypeError("window_size is too small for the polynomials order")
# order_range = range(order+1)
# half_window = (window_size -1) // 2
# # precompute coefficients
# b = np.mat([[k**i for i in order_range] for k in range(-half_window, half_window+1)])
# m = np.linalg.pinv(b).A[deriv] * rate**deriv * factorial(deriv)
# # pad the signal at the extremes with
# # values taken from the signal itself
# firstvals = y[0] - np.abs( y[1:half_window+1][::-1] - y[0] )
# lastvals = y[-1] + np.abs(y[-half_window-1:-1][::-1] - y[-1])
# y = np.concatenate((firstvals, y, lastvals))
# return np.convolve( m[::-1], y, mode='valid')
#
# def saveFigure(self, path, outputFormat):
# self.fig.savefig(path + "." + outputFormat, format=outputFormat)
#
# Path: PyContact/gui/ErrorBox.py
# class ErrorBox(QMessageBox):
# """Creates an Error dialog which displays the corresponding error message 'msg'."""
# def __init__(self, msg):
# super(ErrorBox, self).__init__()
# self.msg = msg
# self.setIcon(QMessageBox.Warning)
# self.setText(self.msg)
# self.setWindowTitle("Error")
# self.setStandardButtons(QMessageBox.Ok)
#
# Path: PyContact/core/Biochemistry.py
# def mean_score_of_contactArray(contacts):
# """Computes the mean score using the contacts array."""
# meanList = []
# for c in contacts:
# meanList = np.concatenate((meanList, c.scoreArray), axis=0)
# return np.mean(meanList)
#
# def median_score_of_contactArray(contacts):
# """Computes the mean score using the contacts array."""
# medianList = []
# for c in contacts:
# medianList = np.concatenate((medianList, c.scoreArray), axis=0)
# return np.median(medianList)
. Output only the next line. | self.nsPerFrame = nspf |
Using the snippet: <|code_start|>
class Statistics(QWidget, Ui_Statistics):
def __init__(self, data, nspf, parent=None):
super(QWidget, self).__init__(parent)
self.setupUi(self)
self.contacts = data
self.nsPerFrame = nspf
self.labelNumFrames.setText(str(len(self.contacts[0].scoreArray)))
self.labelTotalContacts.setText(str(len(self.contacts)))
self.labelMeanScore.setText(str(mean_score_of_contactArray(self.contacts)))
self.labelMedianScore.setText(str(median_score_of_contactArray(self.contacts)))
self.savePlotButton.clicked.connect(self.savePlot)
self.plotButton.clicked.connect(self.plotAttribute)
posIntValidator = QIntValidator()
posIntValidator.setBottom(3)
<|code_end|>
, determine the next line of code. You have imports:
import sip
import os
from PyQt5.QtWidgets import QWidget, QFileDialog
from PyQt5.QtGui import QIntValidator
from .Plotters import ContactPlotter
from .statistics_ui import *
from ..core.LogPool import *
from .ErrorBox import ErrorBox
from ..core.Biochemistry import mean_score_of_contactArray, median_score_of_contactArray
and context (class names, function names, or code) available:
# Path: PyContact/gui/Plotters.py
# class ContactPlotter(MplPlotter):
# """Plots a frame-score plot with lines."""
#
# def plot_contact_figure(self, contact, nsPerFrame):
# frames = np.arange(0, len(contact.scoreArray), 1) * nsPerFrame
# self.axes.plot(frames, contact.scoreArray)
# self.axes.set_xlabel("time [ns]")
# self.axes.set_ylabel("score")
#
# def plot_all_contacts_figure(self, contacts, smooth, nsPerFrame):
# values = []
#
# for frame in range(len(contacts[0].scoreArray)):
# current = 0
# for c in contacts:
# current += c.scoreArray[frame]
# values.append(current)
# frames = np.arange(0, len(values), 1) * nsPerFrame
# if smooth:
# val = self.savitzky_golay(np.array(values), smooth, 2)
# smaller = np.where(val < 0)
# val[smaller] = 0
# self.axes.plot(val)
# else:
# self.axes.plot(values)
# self.axes.set_xlabel("time [ns]")
# self.axes.set_ylabel("score")
#
# def plot_hbondNumber(self, contacts, smooth, nsPerFrame):
# values = []
# for c in contacts:
# c.hbondFramesScan()
#
# for frame in range(len(contacts[0].scoreArray)):
# current = 0
# for c in contacts:
# current += c.hbondFrames[frame]
# values.append(current)
# frames = np.arange(0, len(values), 1) * nsPerFrame
# if smooth:
# val = self.savitzky_golay(np.array(values), smooth, 2)
# smaller = np.where(val < 0)
# val[smaller] = 0
# self.axes.plot(frames, val)
# else:
# self.axes.plot(frames, values)
# self.axes.set_xlabel("time [ns]")
# self.axes.set_ylabel("hbond number")
#
# # from http://scipy.github.io/old-wiki/pages/Cookbook/SavitzkyGolay
# def savitzky_golay(self, y, window_size, order, deriv=0, rate=1):
#
# try:
# window_size = np.abs(np.int(window_size))
# order = np.abs(np.int(order))
# except ValueError:
# raise ValueError("window_size and order have to be of type int")
# if window_size % 2 != 1 or window_size < 1:
# raise TypeError("window_size size must be a positive odd number")
# if window_size < order + 2:
# raise TypeError("window_size is too small for the polynomials order")
# order_range = range(order+1)
# half_window = (window_size -1) // 2
# # precompute coefficients
# b = np.mat([[k**i for i in order_range] for k in range(-half_window, half_window+1)])
# m = np.linalg.pinv(b).A[deriv] * rate**deriv * factorial(deriv)
# # pad the signal at the extremes with
# # values taken from the signal itself
# firstvals = y[0] - np.abs( y[1:half_window+1][::-1] - y[0] )
# lastvals = y[-1] + np.abs(y[-half_window-1:-1][::-1] - y[-1])
# y = np.concatenate((firstvals, y, lastvals))
# return np.convolve( m[::-1], y, mode='valid')
#
# def saveFigure(self, path, outputFormat):
# self.fig.savefig(path + "." + outputFormat, format=outputFormat)
#
# Path: PyContact/gui/ErrorBox.py
# class ErrorBox(QMessageBox):
# """Creates an Error dialog which displays the corresponding error message 'msg'."""
# def __init__(self, msg):
# super(ErrorBox, self).__init__()
# self.msg = msg
# self.setIcon(QMessageBox.Warning)
# self.setText(self.msg)
# self.setWindowTitle("Error")
# self.setStandardButtons(QMessageBox.Ok)
#
# Path: PyContact/core/Biochemistry.py
# def mean_score_of_contactArray(contacts):
# """Computes the mean score using the contacts array."""
# meanList = []
# for c in contacts:
# meanList = np.concatenate((meanList, c.scoreArray), axis=0)
# return np.mean(meanList)
#
# def median_score_of_contactArray(contacts):
# """Computes the mean score using the contacts array."""
# medianList = []
# for c in contacts:
# medianList = np.concatenate((medianList, c.scoreArray), axis=0)
# return np.median(medianList)
. Output only the next line. | self.smoothStrideField.setValidator(posIntValidator) |
Based on the snippet: <|code_start|>dcdfile = DCD
psffile = PSF
analyzer = Analyzer(psffile, dcdfile, 5.0, 2.5, 120, "segid RN11", "segid UBQ")
<|code_end|>
, predict the immediate next line with the help of imports:
from PyContact.core.ContactAnalyzer import *
from PyContact.exampleData.datafiles import DCD, PSF
import MDAnalysis as mda
and context (classes, functions, sometimes code) from other files:
# Path: PyContact/exampleData/datafiles.py
# DCD = res(__name__, './rpn11_ubq.dcd')
#
# PSF = res(__name__, './rpn11_ubq.psf')
. Output only the next line. | analyzer.runFrameScan() |
Predict the next line for this snippet: <|code_start|> """Selects and shows the given frame."""
return "animate goto %s" % str(frame)
@staticmethod
def styleBackbone():
"""Sets a suitable visualization style for the backbone in VMD."""
return """
mol addrep 0
mol modstyle top 0 NewCartoon 0.300000 10.000000 4.100000 0
mol modselect top 0 backbone
mol modcolor top 0 Chain
"""
@staticmethod
def addSelection(sel, representations, colorID):
idx = str(len(representations))
representations.append(sel)
return ["""
mol addrep top
mol modstyle %s top Licorice
mol modselect %s top (%s)
mol modcolor %s top ColorID %d
""" % (idx, idx, sel, idx, colorID), representations]
@staticmethod
def addUserFieldSelection(sel, representations):
idx = str(len(representations))
representations.append(sel)
return ["""
mol addrep top
<|code_end|>
with the help of current file imports:
from socket import *
from pkg_resources import resource_filename as res
from PyQt5.QtWidgets import QWidget, QGridLayout, QLabel, QPushButton, QLineEdit
from PyQt5 import QtCore
from .Dialogues import TopoTrajLoaderDialog
from ..core.Biochemistry import *
import subprocess
and context from other files:
# Path: PyContact/gui/Dialogues.py
# class TopoTrajLoaderDialog(QDialog):
# """Dialog to load the topology and trajectory file."""
# def __init__(self, parent=None):
# super(TopoTrajLoaderDialog, self).__init__(parent)
# self.setWindowTitle("Load Data")
# self.psf = ""
# self.dcd = ""
#
# grid = QGridLayout(self)
#
# buttonPsf = QPushButton("Topology")
# buttonPsf.clicked.connect(self.pick_psf)
#
# buttonDcd = QPushButton("Trajectory")
# buttonDcd.clicked.connect(self.pick_dcd)
#
# helpButton = HelpButton()
#
# grid.addWidget(buttonPsf, 0, 0)
# grid.addWidget(buttonDcd, 0, 1)
# buttons = QDialogButtonBox(
# QDialogButtonBox.Ok | QDialogButtonBox.Cancel,
# Qt.Horizontal, self)
# buttons.accepted.connect(self.accept)
# buttons.rejected.connect(self.reject)
# grid.addWidget(buttons, 1, 0)
# grid.addWidget(helpButton, 2, 0)
#
# def pick_psf(self):
# """Pick the topology file."""
# psfname = QFileDialog.getOpenFileNames(self, "Open topology")
# for file in psfname[0]:
# self.psf = file
# break
#
# def pick_dcd(self):
# """Pick the trajectory file."""
# dcdname = QFileDialog.getOpenFileNames(self, "Open trajectory")
# for file in dcdname[0]:
# self.dcd = file
# break
#
# def configuration(self):
# """Returns the chosen configuration."""
# config = [self.psf, self.dcd]
# return config
#
# @staticmethod
# def getConfig(parent=None):
# """Static method to create the dialog and return (date, time, accepted)."""
# dialog = TopoTrajLoaderDialog(parent)
# result = dialog.exec_()
# config = dialog.configuration()
# return config, result == QDialog.Accepted
, which may contain function names, class names, or code. Output only the next line. | mol modstyle %s top QuickSurf 0.500000 0.500000 0.500000 1.000000 |
Using the snippet: <|code_start|>
class Detail(QWidget, Ui_Detail):
def __init__(self, data, nsPerFrame, threshold, parent=None):
super(QWidget, self).__init__(parent)
self.setupUi(self)
self.contact = data
self.nsPerFrame = nsPerFrame
self.threshold = threshold
self.setWindowTitle(self.contact.title)
self.labelTotalTime.setText(str(self.contact.total_time(self.nsPerFrame, self.threshold)))
self.labelThreshold.setText(str(self.threshold))
self.labelMedianScore.setText(str(self.contact.median_score()))
self.labelMeanScore.setText(str(self.contact.mean_score()))
self.labelMedianLifetime.setText(str(self.contact.median_life_time(self.nsPerFrame, self.threshold)))
self.labelMeanLifetime.setText(str(self.contact.mean_life_time(self.nsPerFrame, self.threshold)))
self.labelBackboneSidechainA.setText("%.2f/%.2f" % (self.contact.bb1, self.contact.sc1))
self.labelBackboneSidechainB.setText("%.2f/%.2f" % (self.contact.bb2, self.contact.sc2))
self.savePlotButton.clicked.connect(self.savePlot)
self.plotButton.clicked.connect(self.plotAttribute)
self.contactPlotter = ContactPlotter(None, width=4, height=2, dpi=70)
<|code_end|>
, determine the next line of code. You have imports:
import sip
import os
from PyQt5.QtWidgets import QWidget, QFileDialog
from .Plotters import ContactPlotter
from .detail_ui import *
from ..core.LogPool import *
from .ErrorBox import ErrorBox
and context (class names, function names, or code) available:
# Path: PyContact/gui/Plotters.py
# class ContactPlotter(MplPlotter):
# """Plots a frame-score plot with lines."""
#
# def plot_contact_figure(self, contact, nsPerFrame):
# frames = np.arange(0, len(contact.scoreArray), 1) * nsPerFrame
# self.axes.plot(frames, contact.scoreArray)
# self.axes.set_xlabel("time [ns]")
# self.axes.set_ylabel("score")
#
# def plot_all_contacts_figure(self, contacts, smooth, nsPerFrame):
# values = []
#
# for frame in range(len(contacts[0].scoreArray)):
# current = 0
# for c in contacts:
# current += c.scoreArray[frame]
# values.append(current)
# frames = np.arange(0, len(values), 1) * nsPerFrame
# if smooth:
# val = self.savitzky_golay(np.array(values), smooth, 2)
# smaller = np.where(val < 0)
# val[smaller] = 0
# self.axes.plot(val)
# else:
# self.axes.plot(values)
# self.axes.set_xlabel("time [ns]")
# self.axes.set_ylabel("score")
#
# def plot_hbondNumber(self, contacts, smooth, nsPerFrame):
# values = []
# for c in contacts:
# c.hbondFramesScan()
#
# for frame in range(len(contacts[0].scoreArray)):
# current = 0
# for c in contacts:
# current += c.hbondFrames[frame]
# values.append(current)
# frames = np.arange(0, len(values), 1) * nsPerFrame
# if smooth:
# val = self.savitzky_golay(np.array(values), smooth, 2)
# smaller = np.where(val < 0)
# val[smaller] = 0
# self.axes.plot(frames, val)
# else:
# self.axes.plot(frames, values)
# self.axes.set_xlabel("time [ns]")
# self.axes.set_ylabel("hbond number")
#
# # from http://scipy.github.io/old-wiki/pages/Cookbook/SavitzkyGolay
# def savitzky_golay(self, y, window_size, order, deriv=0, rate=1):
#
# try:
# window_size = np.abs(np.int(window_size))
# order = np.abs(np.int(order))
# except ValueError:
# raise ValueError("window_size and order have to be of type int")
# if window_size % 2 != 1 or window_size < 1:
# raise TypeError("window_size size must be a positive odd number")
# if window_size < order + 2:
# raise TypeError("window_size is too small for the polynomials order")
# order_range = range(order+1)
# half_window = (window_size -1) // 2
# # precompute coefficients
# b = np.mat([[k**i for i in order_range] for k in range(-half_window, half_window+1)])
# m = np.linalg.pinv(b).A[deriv] * rate**deriv * factorial(deriv)
# # pad the signal at the extremes with
# # values taken from the signal itself
# firstvals = y[0] - np.abs( y[1:half_window+1][::-1] - y[0] )
# lastvals = y[-1] + np.abs(y[-half_window-1:-1][::-1] - y[-1])
# y = np.concatenate((firstvals, y, lastvals))
# return np.convolve( m[::-1], y, mode='valid')
#
# def saveFigure(self, path, outputFormat):
# self.fig.savefig(path + "." + outputFormat, format=outputFormat)
#
# Path: PyContact/gui/ErrorBox.py
# class ErrorBox(QMessageBox):
# """Creates an Error dialog which displays the corresponding error message 'msg'."""
# def __init__(self, msg):
# super(ErrorBox, self).__init__()
# self.msg = msg
# self.setIcon(QMessageBox.Warning)
# self.setText(self.msg)
# self.setWindowTitle("Error")
# self.setStandardButtons(QMessageBox.Ok)
. Output only the next line. | self.contactPlotter.plot_contact_figure(self.contact, self.nsPerFrame) |
Given the code snippet: <|code_start|>
class Detail(QWidget, Ui_Detail):
def __init__(self, data, nsPerFrame, threshold, parent=None):
super(QWidget, self).__init__(parent)
self.setupUi(self)
self.contact = data
self.nsPerFrame = nsPerFrame
self.threshold = threshold
self.setWindowTitle(self.contact.title)
self.labelTotalTime.setText(str(self.contact.total_time(self.nsPerFrame, self.threshold)))
self.labelThreshold.setText(str(self.threshold))
self.labelMedianScore.setText(str(self.contact.median_score()))
self.labelMeanScore.setText(str(self.contact.mean_score()))
<|code_end|>
, generate the next line using the imports in this file:
import sip
import os
from PyQt5.QtWidgets import QWidget, QFileDialog
from .Plotters import ContactPlotter
from .detail_ui import *
from ..core.LogPool import *
from .ErrorBox import ErrorBox
and context (functions, classes, or occasionally code) from other files:
# Path: PyContact/gui/Plotters.py
# class ContactPlotter(MplPlotter):
# """Plots a frame-score plot with lines."""
#
# def plot_contact_figure(self, contact, nsPerFrame):
# frames = np.arange(0, len(contact.scoreArray), 1) * nsPerFrame
# self.axes.plot(frames, contact.scoreArray)
# self.axes.set_xlabel("time [ns]")
# self.axes.set_ylabel("score")
#
# def plot_all_contacts_figure(self, contacts, smooth, nsPerFrame):
# values = []
#
# for frame in range(len(contacts[0].scoreArray)):
# current = 0
# for c in contacts:
# current += c.scoreArray[frame]
# values.append(current)
# frames = np.arange(0, len(values), 1) * nsPerFrame
# if smooth:
# val = self.savitzky_golay(np.array(values), smooth, 2)
# smaller = np.where(val < 0)
# val[smaller] = 0
# self.axes.plot(val)
# else:
# self.axes.plot(values)
# self.axes.set_xlabel("time [ns]")
# self.axes.set_ylabel("score")
#
# def plot_hbondNumber(self, contacts, smooth, nsPerFrame):
# values = []
# for c in contacts:
# c.hbondFramesScan()
#
# for frame in range(len(contacts[0].scoreArray)):
# current = 0
# for c in contacts:
# current += c.hbondFrames[frame]
# values.append(current)
# frames = np.arange(0, len(values), 1) * nsPerFrame
# if smooth:
# val = self.savitzky_golay(np.array(values), smooth, 2)
# smaller = np.where(val < 0)
# val[smaller] = 0
# self.axes.plot(frames, val)
# else:
# self.axes.plot(frames, values)
# self.axes.set_xlabel("time [ns]")
# self.axes.set_ylabel("hbond number")
#
# # from http://scipy.github.io/old-wiki/pages/Cookbook/SavitzkyGolay
# def savitzky_golay(self, y, window_size, order, deriv=0, rate=1):
#
# try:
# window_size = np.abs(np.int(window_size))
# order = np.abs(np.int(order))
# except ValueError:
# raise ValueError("window_size and order have to be of type int")
# if window_size % 2 != 1 or window_size < 1:
# raise TypeError("window_size size must be a positive odd number")
# if window_size < order + 2:
# raise TypeError("window_size is too small for the polynomials order")
# order_range = range(order+1)
# half_window = (window_size -1) // 2
# # precompute coefficients
# b = np.mat([[k**i for i in order_range] for k in range(-half_window, half_window+1)])
# m = np.linalg.pinv(b).A[deriv] * rate**deriv * factorial(deriv)
# # pad the signal at the extremes with
# # values taken from the signal itself
# firstvals = y[0] - np.abs( y[1:half_window+1][::-1] - y[0] )
# lastvals = y[-1] + np.abs(y[-half_window-1:-1][::-1] - y[-1])
# y = np.concatenate((firstvals, y, lastvals))
# return np.convolve( m[::-1], y, mode='valid')
#
# def saveFigure(self, path, outputFormat):
# self.fig.savefig(path + "." + outputFormat, format=outputFormat)
#
# Path: PyContact/gui/ErrorBox.py
# class ErrorBox(QMessageBox):
# """Creates an Error dialog which displays the corresponding error message 'msg'."""
# def __init__(self, msg):
# super(ErrorBox, self).__init__()
# self.msg = msg
# self.setIcon(QMessageBox.Warning)
# self.setText(self.msg)
# self.setWindowTitle("Error")
# self.setStandardButtons(QMessageBox.Ok)
. Output only the next line. | self.labelMedianLifetime.setText(str(self.contact.median_life_time(self.nsPerFrame, self.threshold))) |
Based on the snippet: <|code_start|>
plt.style.use('ggplot')
font = {'family' : 'normal',
'weight' : 'normal',
'size' : 14}
matplotlib.rc('font', **font)
sns.set()
sns.set_context("talk")
<|code_end|>
, predict the immediate next line with the help of imports:
from PyQt5.QtWidgets import QSizePolicy, QApplication
from math import factorial
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg \
as FigureCanvas
from matplotlib.figure import Figure
from matplotlib import cm
from matplotlib import animation as ani
from ..core.ContactFilters import *
from ..core.Biochemistry import AccumulationMapIndex
from matplotlib import pyplot as plt
import numpy as np
import matplotlib
import seaborn as sns
and context (classes, functions, sometimes code) from other files:
# Path: PyContact/core/Biochemistry.py
# class AccumulationMapIndex:
# """Enum and mapping for atom properties.
# Used to dynamically define keys and have a bijective nomenclature for all properties
# """
# index, name, resid, resname, segid = range(5)
# mapping = ["i.", "nm.", "r.", "rn.", "s."]
# vmdsel = ["index", "name", "resid", "resname", "segname"]
. Output only the next line. | class MplPlotter(FigureCanvas): |
Based on the snippet: <|code_start|># documents.
#default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# If true, keep warnings as "system message" paragraphs in the built documents.
#keep_warnings = False
# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = True
# -- Options for HTML output ----------------------------------------------
if is_rtd:
<|code_end|>
, predict the immediate next line with the help of imports:
import sys
import os
import re
import logging
import types
import sphinx.environment
import sphinx_rtd_theme
from awslimitchecker.version import _get_version_info, _VERSION
from docutils.utils import get_source_line
from docutils.nodes import GenericNodeVisitor, inline, Text, literal
from sphinx.addnodes import pending_xref
and context (classes, functions, sometimes code) from other files:
# Path: awslimitchecker/version.py
# def _get_version_info():
# """
# Returns the currently-installed awslimitchecker version, and a best-effort
# attempt at finding the origin URL and commit/tag if installed from an
# editable git clone.
#
# :returns: awslimitchecker version
# :rtype: str
# """
# if os.environ.get('VERSIONCHECK_DEBUG', '') != 'true':
# for lname in ['versionfinder', 'pip', 'git']:
# l = logging.getLogger(lname)
# l.setLevel(logging.CRITICAL)
# l.propagate = True
# try:
# vinfo = find_version('awslimitchecker')
# dirty = ''
# if vinfo.git_is_dirty:
# dirty = '*'
# tag = vinfo.git_tag
# if tag is not None:
# tag += dirty
# commit = vinfo.git_commit
# if commit is not None:
# if len(commit) > 7:
# commit = commit[:8]
# commit += dirty
# return AWSLimitCheckerVersion(
# vinfo.version,
# vinfo.url,
# tag=tag,
# commit=commit
# )
# except Exception:
# logger.exception("Error checking installed version; this installation "
# "may not be in compliance with the AGPLv3 license:")
# # fall back to returning just the hard-coded release information
# return AWSLimitCheckerVersion(_VERSION, _PROJECT_URL)
#
# _VERSION = '.'.join([str(x) for x in _VERSION_TUP])
. Output only the next line. | html_theme = 'sphinx_rtd_theme' |
Predict the next line after this snippet: <|code_start|>
# Documents to append as an appendix to all manuals.
#texinfo_appendices = []
# If false, no module index is generated.
#texinfo_domain_indices = True
# How to display URL addresses: 'footnote', 'no', or 'inline'.
#texinfo_show_urls = 'footnote'
# If true, do not generate a @detailmenu in the "Top" node's menu.
#texinfo_no_detailmenu = False
# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {
'https://docs.python.org/3/': None,
'boto': ('http://boto.readthedocs.org/en/latest/', None),
'boto3': ('http://boto3.readthedocs.org/en/latest/', None)
}
autoclass_content = 'init'
autodoc_default_flags = ['members', 'undoc-members', 'private-members', 'special-members', 'show-inheritance']
nitpick_ignore = [
('py:class', 'ABCMeta'),
('py:obj', 'function')
]
linkcheck_ignore = [
<|code_end|>
using the current file's imports:
import sys
import os
import re
import logging
import types
import sphinx.environment
import sphinx_rtd_theme
from awslimitchecker.version import _get_version_info, _VERSION
from docutils.utils import get_source_line
from docutils.nodes import GenericNodeVisitor, inline, Text, literal
from sphinx.addnodes import pending_xref
and any relevant context from other files:
# Path: awslimitchecker/version.py
# def _get_version_info():
# """
# Returns the currently-installed awslimitchecker version, and a best-effort
# attempt at finding the origin URL and commit/tag if installed from an
# editable git clone.
#
# :returns: awslimitchecker version
# :rtype: str
# """
# if os.environ.get('VERSIONCHECK_DEBUG', '') != 'true':
# for lname in ['versionfinder', 'pip', 'git']:
# l = logging.getLogger(lname)
# l.setLevel(logging.CRITICAL)
# l.propagate = True
# try:
# vinfo = find_version('awslimitchecker')
# dirty = ''
# if vinfo.git_is_dirty:
# dirty = '*'
# tag = vinfo.git_tag
# if tag is not None:
# tag += dirty
# commit = vinfo.git_commit
# if commit is not None:
# if len(commit) > 7:
# commit = commit[:8]
# commit += dirty
# return AWSLimitCheckerVersion(
# vinfo.version,
# vinfo.url,
# tag=tag,
# commit=commit
# )
# except Exception:
# logger.exception("Error checking installed version; this installation "
# "may not be in compliance with the AGPLv3 license:")
# # fall back to returning just the hard-coded release information
# return AWSLimitCheckerVersion(_VERSION, _PROJECT_URL)
#
# _VERSION = '.'.join([str(x) for x in _VERSION_TUP])
. Output only the next line. | r'https?://landscape\.io.*', |
Predict the next line after this snippet: <|code_start|> 'urllib3'
]
classifiers = [
'Development Status :: 6 - Mature',
'Environment :: Console',
'Intended Audience :: Developers',
'Intended Audience :: Information Technology',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)',
'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Topic :: Internet',
'Topic :: System :: Monitoring',
]
setup(
name='awslimitchecker',
version=_VERSION,
author='Jason Antman',
author_email='jason@jasonantman.com',
packages=find_packages(),
entry_points="""
[console_scripts]
<|code_end|>
using the current file's imports:
from setuptools import setup, find_packages
from awslimitchecker.version import _VERSION, _PROJECT_URL
and any relevant context from other files:
# Path: awslimitchecker/version.py
# _VERSION = '.'.join([str(x) for x in _VERSION_TUP])
#
# _PROJECT_URL = 'https://github.com/jantman/awslimitchecker'
. Output only the next line. | awslimitchecker = awslimitchecker.runner:console_entry_point |
Given the code snippet: <|code_start|> 'pytz',
'urllib3'
]
classifiers = [
'Development Status :: 6 - Mature',
'Environment :: Console',
'Intended Audience :: Developers',
'Intended Audience :: Information Technology',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)',
'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Topic :: Internet',
'Topic :: System :: Monitoring',
]
setup(
name='awslimitchecker',
version=_VERSION,
author='Jason Antman',
author_email='jason@jasonantman.com',
packages=find_packages(),
entry_points="""
<|code_end|>
, generate the next line using the imports in this file:
from setuptools import setup, find_packages
from awslimitchecker.version import _VERSION, _PROJECT_URL
and context (functions, classes, or occasionally code) from other files:
# Path: awslimitchecker/version.py
# _VERSION = '.'.join([str(x) for x in _VERSION_TUP])
#
# _PROJECT_URL = 'https://github.com/jantman/awslimitchecker'
. Output only the next line. | [console_scripts] |
Predict the next line for this snippet: <|code_start|>#!/usr/bin/env python
# encoding: utf-8
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
from __future__ import absolute_import
class ClientTest(unittest.TestCase):
def setUp(self):
self.client = Client(
<|code_end|>
with the help of current file imports:
import unittest
from pyoauth2.client import Client
from pyoauth2 import utils
and context from other files:
# Path: pyoauth2/client.py
# class Client(object):
#
# def __init__(self, client_id, client_secret, redirect_uri,
# authorization_uri, token_uri):
# """Constructor for OAuth 2.0 Client.
#
# :param client_id: Client ID.
# :type client_id: str
# :param client_secret: Client secret.
# :type client_secret: str
# :param redirect_uri: Client redirect URI: handle provider response.
# :type redirect_uri: str
# :param authorization_uri: Provider authorization URI.
# :type authorization_uri: str
# :param token_uri: Provider token URI.
# :type token_uri: str
# """
# self.client_id = client_id
# self.client_secret = client_secret
# self.redirect_uri = redirect_uri
# self.authorization_uri = authorization_uri
# self.token_uri = token_uri
#
# @property
# def default_response_type(self):
# return 'code'
#
# @property
# def default_grant_type(self):
# return 'authorization_code'
#
# def http_post(self, url, data=None):
# """POST to URL and get result as a response object.
#
# :param url: URL to POST.
# :type url: str
# :param data: Data to send in the form body.
# :type data: str
# :rtype: requests.Response
# """
# if not url.startswith('https://'):
# raise ValueError('Protocol must be HTTPS, invalid URL: %s' % url)
# return requests.post(url, data, verify=True)
#
# def get_authorization_code_uri(self, **params):
# """Construct a full URL that can be used to obtain an authorization
# code from the provider authorization_uri. Use this URI in a client
# frame to cause the provider to generate an authorization code.
#
# :rtype: str
# """
# if 'response_type' not in params:
# params['response_type'] = self.default_response_type
# params.update({'client_id': self.client_id,
# 'redirect_uri': self.redirect_uri})
# return utils.build_url(self.authorization_uri, params)
#
# def get_token(self, code, **params):
# """Get an access token from the provider token URI.
#
# :param code: Authorization code.
# :type code: str
# :return: Dict containing access token, refresh token, etc.
# :rtype: dict
# """
# params['code'] = code
# if 'grant_type' not in params:
# params['grant_type'] = self.default_grant_type
# params.update({'client_id': self.client_id,
# 'client_secret': self.client_secret,
# 'redirect_uri': self.redirect_uri})
# response = self.http_post(self.token_uri, params)
# try:
# return response.json()
# except TypeError:
# return response.json
#
# Path: pyoauth2/utils.py
# UNICODE_ASCII_CHARACTERS = (string.ascii_letters.decode('ascii') +
# string.digits.decode('ascii'))
# def random_ascii_string(length):
# def url_query_params(url):
# def url_dequery(url):
# def build_url(base, additional_params=None):
, which may contain function names, class names, or code. Output only the next line. | client_id='some.client', |
Given the following code snippet before the placeholder: <|code_start|># with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
from __future__ import with_statement
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)
# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.
database_file = os.path.join(
<|code_end|>
, predict the next line using imports from the current file:
from alembic import context
from sqlalchemy import engine_from_config, pool
from logging.config import fileConfig
from gstack.core import db
import os
and context including class names, function names, and sometimes code from other files:
# Path: gstack/core.py
# class Service(object):
# def _isinstance(self, model, raise_error=True):
# def save(self, model):
# def get(self, primarykey):
# def create(self, **kwargs):
# def delete(self, model):
. Output only the next line. | os.path.expanduser('~'), |
Based on the snippet: <|code_start|>#!/usr/bin/env python
# encoding: utf-8
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
resource_provider = CloudstackResourceProvider()
def required(f):
@wraps(f)
def decorated(*args, **kwargs):
<|code_end|>
, predict the immediate next line with the help of imports:
from flask import abort
from functools import wraps
from gstack.oauth2provider import CloudstackResourceProvider
and context (classes, functions, sometimes code) from other files:
# Path: gstack/oauth2provider.py
# class CloudstackResourceProvider(ResourceProvider):
#
# @property
# def authorization_class(self):
# return CloudstackResourceAuthorization
#
# def get_authorization_header(self):
# return request.headers.get('Authorization')
#
# def validate_access_token(self, access_token, authorization):
# found_access_token = AccessToken.query.get(access_token)
# if found_access_token is not None and found_access_token.data != 'false':
# access_token_data = json.loads(found_access_token.data)
# client = Client.query.get(access_token_data.get('client_id'))
#
# authorization.is_valid = True
# authorization.client_id = access_token_data.get('client_id')
# authorization.expires_in = access_token_data.get('expires_in')
# authorization.client_secret = client.client_secret
. Output only the next line. | authorization = resource_provider.get_authorization() |
Given snippet: <|code_start|>#!/usr/bin/env python
# encoding: utf-8
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
from __future__ import absolute_import
class UtilsTest(unittest.TestCase):
def setUp(self):
self.base_url = 'https://www.grapheffect.com/some/path;hello?c=30&b=2&a=10'
<|code_end|>
, continue by predicting the next line. Consider current file imports:
import unittest
from pyoauth2 import utils
and context:
# Path: pyoauth2/utils.py
# UNICODE_ASCII_CHARACTERS = (string.ascii_letters.decode('ascii') +
# string.digits.decode('ascii'))
# def random_ascii_string(length):
# def url_query_params(url):
# def url_dequery(url):
# def build_url(base, additional_params=None):
which might include code, classes, or functions. Output only the next line. | def test_random_ascii_string(self): |
Given snippet: <|code_start|> help='Space-separated random seeds with which to initialize each chain. Specify one for each chain.')
parser.add_argument('-I', '--chain-inclusion-factor', dest='chain_inclusion_factor', default=1.1, type=float,
help='Factor for determining which chains will be included in the output "merged" folder. ' \
'Default is 1.1, meaning that the sum of the likelihoods of the trees found in each chain must ' \
'be greater than 1.1x the maximum of that value across chains. Setting this value = inf ' \
'includes all chains and setting it = 1 will include only the best chain.')
parser.add_argument('-O', '--output-dir', dest='output_dir', default='chains',
help='Directory where results from each chain will be saved. We will create it if it does not exist.')
# Ideally, I wouldn't specify `ssm_file` or `cnv_file` as multievolve.py
# arguments, since I don't need them here -- I just want to pass them
# through to evolve.py. But then printing the help is confusing, as you
# don't realize that you should pass them as arguments to multievolve. So,
# I should specify them here -- otherwise, you can invoke multievolve.py
# with no ssm_data.txt or cnv_data.txt, and it will dutifully invoke
# multiple copies of evolve.py with no input files (with the evolve.py runs
# immediately failing.
#
# Since --ssms and --cnvs are required, it would be better to make them
# positional arguments. But this screws up parsing with parse_known_args()
# -- it mixes up unknown and known arguments if I make ssm_file and cnv_file positional, then call
# `python2 ../multievolve.py -n2 -s 5 -B 3 ../ssm_data.txt ../cnv_data.txt`.
# To fix this, just make all known arguments for multievolve (required) optional arguments.
#
# Much of this mess arises from having a wrapper script to start multiple
# chains. In a better world, evolve.py would natively support multiple
# chains, with the user able to choose to have only a single chain if she
# desires.
parser.add_argument('--ssms', dest='ssm_file', required=True,
help='File listing SSMs (simple somatic mutations, i.e., single nucleotide variants. For proper format, see README.md.')
parser.add_argument('--cnvs',dest='cnv_file', required=True,
<|code_end|>
, continue by predicting the next line. Consider current file imports:
import argparse
import os
import subprocess
import zipfile
import numpy as np
import sys
import re
import Queue
import threading
import time
import scipy.misc
import hashlib
from util2 import logmsg
from collections import defaultdict
and context:
# Path: util2.py
# def logmsg(msg, fd=sys.stdout):
# print >> fd, '[%s] %s' % (datetime.now().strftime('%Y-%m-%d %H:%m:%S'), msg)
which might include code, classes, or functions. Output only the next line. | help='File listing CNVs (copy number variations). For proper format, see README.md.') |
Continue the code snippet: <|code_start|> # Occurs when sample covariance matrix is singular because, e.g., data lies
# on manifold. We see this happen when all trees are linear, implying BI=0.
# To overcome this error, calculate density in 1D without using the BI.
try:
density = list(scipy.stats.gaussian_kde(X)(X))
except (np.linalg.linalg.LinAlgError, FloatingPointError):
# ... but an exception may still occur if all trees have the same
# structure, I think. This was triggered when working with Steph's trees,
# using PhyloSteph.
density = np.zeros(len(X))
return dict(zip(tidxs, density))
class JsonWriter(object):
def __init__(self, dataset_name):
self._dataset_name = dataset_name
def write_mutlist(self, mutlist, mutlist_outfn):
with gzip.GzipFile(mutlist_outfn, 'w') as mutf:
mutlist['dataset_name'] = self._dataset_name
json.dump(mutlist, mutf)
def write_summaries(self, summaries, params, summaries_outfn):
for summary in summaries.values():
calculator = IndexCalculator(summary)
summary['linearity_index'] = calculator.calc_linearity_index()
summary['branching_index'] = calculator.calc_branching_index()
summary['clustering_index'] = calculator.calc_clustering_index()
to_dump = {
<|code_end|>
. Use current file imports:
from pwgsresults.index_calculator import IndexCalculator
import json
import gzip
import zipfile
import numpy as np
import scipy.stats
and context (classes, functions, or code) from other files:
# Path: pwgsresults/index_calculator.py
# class IndexCalculator(object):
# def __init__(self, tree_summ):
# self._tree_summ = tree_summ
# self._poprel = self._determine_pop_relations(tree_summ['structure'])
#
# def _determine_pop_relations(self, tree_struct):
# relations = {}
# all_verts = set()
#
# def _traverse_r(vertex, ancestors):
# all_verts.add(vertex)
# for anc in ancestors:
# relations[(anc, vertex)] = 'anc_desc'
# relations[(vertex, anc)] = 'desc_anc'
# if vertex in tree_struct:
# for child in tree_struct[vertex]:
# _traverse_r(child, ancestors + [vertex])
#
# root = 0
# _traverse_r(root, [])
#
# for vert1, vert2 in itertools.combinations(all_verts, 2):
# if (vert1, vert2) in relations:
# continue
# relations[(vert1, vert2)] = 'cousin'
# relations[(vert2, vert1)] = 'cousin'
#
# return relations
#
# def _calc_index(self, reltype):
# tree_pops = self._tree_summ['populations']
# totalssms = sum([P['num_ssms'] for P in tree_pops.values()])
# index = 0
#
# for (popidx1, popidx2), relation in self._poprel.items():
# if relation != reltype:
# continue
# nssms1, nssms2 = tree_pops[popidx1]['num_ssms'], tree_pops[popidx2]['num_ssms']
# index += nssms1 * nssms2
#
# # The maximum value of `index` will be `N(N - 1)`, as we exclude the
# # diagonal. If we ignore the diagonal, then if we were to explicitly
# # calculate the N*N matrices corresponding to each of the indices and then
# # sum the matrices, every entry in the sum would be 1.
# normidx = float(index) / (totalssms * (totalssms - 1))
# assert 0. <= normidx <= 1.
# return normidx
#
# def calc_linearity_index(self):
# lowertrisum = self._calc_index('anc_desc')
# # Note that the matrix isn't symmetric -- if A is an ancestor of B, then we
# # know that B is *not* an ancestor of A. The clustering and branching
# # matrices are, however, symmetric. Thus, for this, we should be
# # normalizing against (N choose 2) instead of (N permute 2); but since
# # _calc_index() normalizes against the latter, we multiply by two to
# # correct for this, since (N permute 2) = 2(N choose 2).
# linidx = 2 * lowertrisum
# assert 0. <= linidx <= 1.
# return linidx
#
# def calc_branching_index(self):
# return self._calc_index('cousin')
#
# def calc_clustering_index(self):
# # Technically, in the clustering matrix, the diagonal should be 1's
# # (since a mutation should be said to cluster with itself). But to keep the
# # value in the denominator against which we normalize the same across all
# # three indices, thereby ensuring that the sum of the three normalized
# # indices will be 1, we force the diagonal to be zero -- which is why we
# # add nssms(nssms - 1) rather than nssms^2 below.
# ccidx = 0
# totalssms = 0
# for pop in self._tree_summ['populations'].values():
# nssms = pop['num_ssms']
# ccidx += nssms * (nssms - 1)
# totalssms += nssms
# normccidx = float(ccidx) / (totalssms * (totalssms - 1))
#
# assert 0. <= normccidx <= 1.
# # It's enough just to subtract the other two indices from one to calculate
# # the branching index. However, calculating it independently and then
# # checking it against that result gives more confidnece it's correct.
# assert np.isclose(normccidx, 1 - self.calc_linearity_index() - self.calc_branching_index())
# return normccidx
. Output only the next line. | 'dataset_name': self._dataset_name, |
Predict the next line for this snippet: <|code_start|>
def assinatura_nfse_issdsf(self, NFe):
assinatura = NFe.infNFe.emit.IM.valor.zfill(11)[:11]
assinatura += 'NF '
assinatura += str(NFe.infNFe.ide.nRPS.valor).zfill(12)[:12]
assinatura += NFe.infNFe.ide.dhEmi.formato_iso[:10].replace('-', '')
if NFe.infNFe.emit.CRT.valor == 1:
assinatura += 'H '
else:
if NFe.infNFe.ide.natureza_nfse == '0':
assinatura += 'T '
if NFe.infNFe.ide.natureza_nfse == '1':
assinatura += 'E '
if NFe.infNFe.ide.natureza_nfse == '2':
assinatura += 'C '
if NFe.infNFe.ide.natureza_nfse == '3':
assinatura += 'F '
if NFe.infNFe.ide.natureza_nfse == '4':
assinatura += 'K '
assinatura += 'N'
assinatura += 'S' if NFe.infNFe.total.ISSQNTot.vISSRet.valor > 0 else 'N'
assinatura += str(int(NFe.infNFe.total.ISSQNTot.vServ.valor * 100)).zfill(15)
assinatura += str(int(NFe.infNFe.total.ISSQNTot.vDeducao.valor * 100)).zfill(15)
assinatura += NFe.infNFe.det[0].imposto.ISSQN.cServico.valor.zfill(10)[:10]
if NFe.infNFe.dest.CPF.valor:
assinatura += NFe.infNFe.dest.CPF.valor.zfill(14)[:14]
elif NFe.infNFe.dest.CNPJ.valor:
<|code_end|>
with the help of current file imports:
import os
import sys
import socket
import ssl
import time
import json
import hashlib
import pybrasil
from datetime import datetime
from uuid import uuid4
from builtins import str
from io import open
from httplib import HTTPSConnection, HTTPConnection
from http.client import HTTPSConnection, HTTPConnection
from .danfse import DANFSE
and context from other files:
# Path: pysped/nfse/danfse.py
# class DANFSE(DANFE):
# def __init__(self):
# super(DANFSE, self).__init__()
# self.imprime_descricao_servico = True
# self.imprime_item_servico = True
# self.imprime_codigo_cnae = True
# self.imprime_codigo_servico = False
# self.imprime_codigo_servico_federal = True
# self.imprime_construcao_civil = False
#
# def reset(self):
# super(DANFSE, self).reset()
#
# def gerar_danfse(self):
# if self.NFe is None:
# raise ValueError('Não é possível gerar um DANFSE sem a informação de uma NFS-e')
#
# if self.protNFe is None:
# self.reset()
#
# #
# # Prepara o queryset para impressão
# #
# self.NFe.site = self.site
#
# if self.template:
# if isinstance(self.template, (file, BytesIO)):
# template = self.template
# else:
# template = open(self.template, 'rb')
#
# else:
# template = open(os.path.join(DIRNAME, 'danfse_a4.odt'), 'rb')
#
# self._gera_pdf(template)
#
# if self.salvar_arquivo:
# #nome_arq = self.caminho + self.NFe.chave + '.pdf'
# nome_arq = self.caminho + 'nfse.pdf'
# open(nome_arq, 'wb').write(self.conteudo_pdf)
#
# def gerar_danfe(self):
# self.gerar_danfse()
#
# @property
# def logo_prefeitura(self):
# import ipdb; ipdb
# if self.NFe is None:
# return ''
#
# if not self.NFe.nome_cidade:
# return ''
#
# if self.NFe.nome_cidade in CACHE_LOGO:
# return CACHE_LOGO[self.NFe.nome_cidade]
#
# caminho_logo = os.path.join(DIRNAME, 'logo_prefeitura', self.NFe.nome_cidade + '.jpeg')
#
# if not os.path.exists(caminho_logo):
# return ''
#
# logo = open(caminho_logo, 'rb').read()
#
# CACHE_LOGO[self.NFe.nome_cidade] = base64.encodebytes(logo)
#
# return CACHE_LOGO[self.NFe.nome_cidade]
#
# def gerar_darl(self):
# if self.NFe is None:
# raise ValueError('Não é possível gerar um DARL sem a informação de um Recibo de Locação')
#
# if self.protNFe is None:
# self.reset()
#
# #
# # Prepara o queryset para impressão
# #
# self.NFe.site = self.site
#
# if self.template:
# if isinstance(self.template, (file, BytesIO)):
# template = self.template
# else:
# template = open(self.template, 'rb')
#
# else:
# template = open(os.path.join(DIRNAME, 'darl_a4.odt'), 'rb')
#
# self._gera_pdf(template)
#
# if self.salvar_arquivo:
# #nome_arq = self.caminho + self.NFe.chave + '.pdf'
# nome_arq = self.caminho + 'recibo_locacao.pdf'
# open(nome_arq, 'wb').write(self.conteudo_pdf)
, which may contain function names, class names, or code. Output only the next line. | assinatura += NFe.infNFe.dest.CNPJ.valor.zfill(14)[:14] |
Using the snippet: <|code_start|>
DIRNAME = os.path.dirname(__file__)
class Signature(XMLNFe):
def __init__(self):
super(Signature, self).__init__()
self.URI = u''
self.DigestValue = u''
self.SignatureValue = u''
self.X509Certificate = u''
self.caminho_esquema = os.path.join(DIRNAME, u'schema/')
self.arquivo_esquema = u'xmldsig-core-schema_v1.01.xsd'
self.metodo = 'sha1'
def get_xml(self):
if not len(self.URI):
self.URI = u'#'
if self.URI[0] != u'#':
self.URI = u'#' + self.URI
xml = u'<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">'
xml += u'<SignedInfo>'
xml += u'<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />'
if self.metodo == 'sha1':
xml += u'<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />'
elif self.metodo == 'sha256':
xml += u'<SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" />'
<|code_end|>
, determine the next line of code. You have imports:
from pysped.xml_sped import XMLNFe
import os
and context (class names, function names, or code) available:
# Path: pysped/xml_sped/base.py
# class XMLNFe(NohXML):
# def __init__(self, *args, **kwargs):
# super(XMLNFe, self).__init__(*args, **kwargs)
# self._xml = None
# self.alertas = []
# self.arquivo_esquema = None
# self.caminho_esquema = None
#
# def get_xml(self):
# self.alertas = []
# return ''
#
# def validar(self):
# arquivo_esquema = self.caminho_esquema + self.arquivo_esquema
#
# # Aqui é importante remover a declaração do encoding
# # para evitar erros de conversão unicode para ascii
# xml = tira_abertura(self.xml).encode('utf-8')
#
# esquema = etree.XMLSchema(etree.parse(arquivo_esquema))
# esquema.validate(etree.fromstring(xml))
#
# namespace = '{http://www.portalfiscal.inf.br/nfe}'
# return "\n".join([x.message.replace(namespace, '') for x in esquema.error_log])
#
# def le_grupo(self, raiz_grupo, classe_grupo, sigla_ns='nfe', namespace=None):
# tags = []
#
# grupos = self._le_nohs(raiz_grupo, sigla_ns=sigla_ns, ns=namespace)
#
# if grupos is not None:
# tags = [classe_grupo() for g in grupos]
# for i in range(len(grupos)):
# tags[i].xml = grupos[i]
#
# return tags
. Output only the next line. | xml += u'<Reference URI="' + self.URI + u'">' |
Predict the next line for this snippet: <|code_start|> assert channel.name == example_channel["name"]
@responses.activate
def test_get_editors():
channel_id = example_channel["_id"]
response = {"users": [example_user]}
responses.add(
responses.GET,
"{}channels/{}/editors".format(BASE_URL, channel_id),
body=json.dumps(response),
status=200,
content_type="application/json",
)
client = TwitchClient("client id", "oauth token")
users = client.channels.get_editors(channel_id)
assert len(responses.calls) == 1
assert len(users) == 1
user = users[0]
assert isinstance(user, User)
assert user.id == example_user["_id"]
assert user.name == example_user["name"]
@responses.activate
def test_get_followers():
channel_id = example_channel["_id"]
<|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, Community, Follow, Subscription, Team, User, Video
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 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. | response = { |
Given snippet: <|code_start|> )
client = TwitchClient("client id", "oauth token")
channel = client.channels.reset_stream_key(channel_id)
assert len(responses.calls) == 1
assert isinstance(channel, Channel)
assert channel.id == example_channel["_id"]
assert channel.name == example_channel["name"]
@responses.activate
def test_get_community():
channel_id = example_channel["_id"]
responses.add(
responses.GET,
"{}channels/{}/community".format(BASE_URL, channel_id),
body=json.dumps(example_community),
status=200,
content_type="application/json",
)
client = TwitchClient("client id")
community = client.channels.get_community(channel_id)
assert len(responses.calls) == 1
assert isinstance(community, Community)
assert community.id == example_community["_id"]
<|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, Community, Follow, Subscription, Team, User, 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/"
#
# 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. | assert community.name == example_community["name"] |
Based on the snippet: <|code_start|>example_team = {
"_id": 10,
"name": "staff",
}
example_subscription = {
"_id": "67123294ed8305ce3a8ef09649d2237c5a300590",
"created_at": "2014-05-19T23:38:53Z",
"user": example_user,
}
example_video = {
"_id": "v106400740",
"description": "Protect your chat with AutoMod!",
"fps": {"1080p": 23.9767661758746},
}
example_community = {
"_id": "e9f17055-810f-4736-ba40-fba4ac541caa",
"name": "DallasTesterCommunity",
}
@responses.activate
def test_get():
responses.add(
responses.GET,
"{}channel".format(BASE_URL),
body=json.dumps(example_channel),
status=200,
<|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, Community, Follow, Subscription, Team, User, Video
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 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. | content_type="application/json", |
Predict the next line for this snippet: <|code_start|> assert community.id == example_community["_id"]
assert community.name == example_community["name"]
@responses.activate
def test_set_community():
channel_id = example_channel["_id"]
community_id = example_community["_id"]
responses.add(
responses.PUT,
"{}channels/{}/community/{}".format(BASE_URL, channel_id, community_id),
status=204,
content_type="application/json",
)
client = TwitchClient("client id")
client.channels.set_community(channel_id, community_id)
assert len(responses.calls) == 1
@responses.activate
def test_delete_from_community():
channel_id = example_channel["_id"]
responses.add(
responses.DELETE,
"{}channels/{}/community".format(BASE_URL, channel_id),
body=json.dumps(example_community),
status=204,
<|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, Community, Follow, Subscription, Team, User, Video
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 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. | content_type="application/json", |
Given the code snippet: <|code_start|>
@responses.activate
def test_get_subscribers():
channel_id = example_channel["_id"]
response = {"_total": 1, "subscriptions": [example_subscription]}
responses.add(
responses.GET,
"{}channels/{}/subscriptions".format(BASE_URL, channel_id),
body=json.dumps(response),
status=200,
content_type="application/json",
)
client = TwitchClient("client id", "oauth token")
subscribers = client.channels.get_subscribers(channel_id)
assert len(responses.calls) == 1
assert len(subscribers) == 1
subscribe = subscribers[0]
assert isinstance(subscribe, Subscription)
assert subscribe.id == example_subscription["_id"]
assert isinstance(subscribe.user, User)
assert subscribe.user.id == example_user["_id"]
assert subscribe.user.name == example_user["name"]
@responses.activate
@pytest.mark.parametrize("param,value", [("limit", 101), ("direction", "abcd")])
<|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, Community, Follow, Subscription, Team, User, 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/"
#
# 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. | def test_get_subscribers_raises_if_wrong_params_are_passed_in(param, value): |
Given the following code snippet before the placeholder: <|code_start|> client.channels.get_videos("1234", **kwargs)
@responses.activate
def test_start_commercial():
channel_id = example_channel["_id"]
response = {"duration": 30, "message": "", "retryafter": 480}
responses.add(
responses.POST,
"{}channels/{}/commercial".format(BASE_URL, channel_id),
body=json.dumps(response),
status=200,
content_type="application/json",
)
client = TwitchClient("client id", "oauth token")
commercial = client.channels.start_commercial(channel_id)
assert len(responses.calls) == 1
assert isinstance(commercial, dict)
assert commercial["duration"] == response["duration"]
@responses.activate
def test_reset_stream_key():
channel_id = example_channel["_id"]
responses.add(
responses.DELETE,
"{}channels/{}/stream_key".format(BASE_URL, channel_id),
<|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, Community, Follow, Subscription, Team, User, Video
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 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. | body=json.dumps(example_channel), |
Next line prediction: <|code_start|>
community = client.channels.get_community(channel_id)
assert len(responses.calls) == 1
assert isinstance(community, Community)
assert community.id == example_community["_id"]
assert community.name == example_community["name"]
@responses.activate
def test_set_community():
channel_id = example_channel["_id"]
community_id = example_community["_id"]
responses.add(
responses.PUT,
"{}channels/{}/community/{}".format(BASE_URL, channel_id, community_id),
status=204,
content_type="application/json",
)
client = TwitchClient("client id")
client.channels.set_community(channel_id, community_id)
assert len(responses.calls) == 1
@responses.activate
def test_delete_from_community():
channel_id = example_channel["_id"]
<|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, Community, Follow, Subscription, Team, User, Video)
and context including class names, function names, or small code snippets 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 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. | responses.add( |
Here is a snippet: <|code_start|>example_team = {
"_id": 10,
"name": "staff",
}
example_subscription = {
"_id": "67123294ed8305ce3a8ef09649d2237c5a300590",
"created_at": "2014-05-19T23:38:53Z",
"user": example_user,
}
example_video = {
"_id": "v106400740",
"description": "Protect your chat with AutoMod!",
"fps": {"1080p": 23.9767661758746},
}
example_community = {
"_id": "e9f17055-810f-4736-ba40-fba4ac541caa",
"name": "DallasTesterCommunity",
}
@responses.activate
def test_get():
responses.add(
responses.GET,
"{}channel".format(BASE_URL),
body=json.dumps(example_channel),
status=200,
<|code_end|>
. Write the next line using the 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, Community, Follow, Subscription, Team, User, Video
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 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 include functions, classes, or code. Output only the next line. | content_type="application/json", |
Using the snippet: <|code_start|> client = TwitchClient("client id")
community = client.channels.get_community(channel_id)
assert len(responses.calls) == 1
assert isinstance(community, Community)
assert community.id == example_community["_id"]
assert community.name == example_community["name"]
@responses.activate
def test_set_community():
channel_id = example_channel["_id"]
community_id = example_community["_id"]
responses.add(
responses.PUT,
"{}channels/{}/community/{}".format(BASE_URL, channel_id, community_id),
status=204,
content_type="application/json",
)
client = TwitchClient("client id")
client.channels.set_community(channel_id, community_id)
assert len(responses.calls) == 1
@responses.activate
def test_delete_from_community():
<|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, Community, Follow, Subscription, Team, User, 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/"
#
# 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. | channel_id = example_channel["_id"] |
Given the code snippet: <|code_start|>def test_get_editors():
channel_id = example_channel["_id"]
response = {"users": [example_user]}
responses.add(
responses.GET,
"{}channels/{}/editors".format(BASE_URL, channel_id),
body=json.dumps(response),
status=200,
content_type="application/json",
)
client = TwitchClient("client id", "oauth token")
users = client.channels.get_editors(channel_id)
assert len(responses.calls) == 1
assert len(users) == 1
user = users[0]
assert isinstance(user, User)
assert user.id == example_user["_id"]
assert user.name == example_user["name"]
@responses.activate
def test_get_followers():
channel_id = example_channel["_id"]
response = {
"_cursor": "1481675542963907000",
"_total": 41,
"follows": [example_follower],
<|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, Community, Follow, Subscription, Team, User, 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/"
#
# 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. | } |
Given the following code snippet before the placeholder: <|code_start|> responses.DELETE,
"{}feed/{}/posts/{}".format(BASE_URL, channel_id, post_id),
body=json.dumps(example_post),
status=200,
content_type="application/json",
)
client = TwitchClient("client id", "oauth token")
post = client.channel_feed.delete_post(channel_id, post_id)
assert len(responses.calls) == 1
assert isinstance(post, Post)
assert post.id == example_post["id"]
@responses.activate
def test_create_reaction_to_post():
channel_id = "1234"
post_id = example_post["id"]
response = {
"id": "24989127",
"emote_id": "25",
"user": {},
"created_at": "2016-11-29T15:51:12Z",
}
responses.add(
responses.POST,
"{}feed/{}/posts/{}/reactions".format(BASE_URL, channel_id, post_id),
body=json.dumps(response),
<|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 Comment, Post
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 Comment(TwitchObject):
# pass
#
# class Post(TwitchObject):
# pass
. Output only the next line. | status=200, |
Given snippet: <|code_start|> body=json.dumps(response),
status=200,
content_type="application/json",
)
client = TwitchClient("client id")
posts = client.channel_feed.get_posts(channel_id)
assert len(responses.calls) == 1
assert len(posts) == 1
post = posts[0]
assert isinstance(post, Post)
assert post.id == example_post["id"]
assert post.body == example_post["body"]
@responses.activate
@pytest.mark.parametrize("param,value", [("limit", 101), ("comments", 6)])
def test_get_posts_raises_if_wrong_params_are_passed_in(param, value):
client = TwitchClient("client id")
kwargs = {param: value}
with pytest.raises(TwitchAttributeException):
client.channel_feed.get_posts("1234", **kwargs)
@responses.activate
def test_get_post():
channel_id = "1234"
post_id = example_post["id"]
<|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 Comment, Post
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 Comment(TwitchObject):
# pass
#
# class Post(TwitchObject):
# pass
which might include code, classes, or functions. Output only the next line. | responses.add( |
Here is a snippet: <|code_start|> client = TwitchClient("client id", "oauth token")
response = client.channel_feed.delete_reaction_to_post(channel_id, post_id, "1234")
assert len(responses.calls) == 1
assert response["deleted"]
@responses.activate
def test_get_post_comments():
channel_id = "1234"
post_id = example_post["id"]
response = {
"_cursor": "1480651694954867000",
"_total": 1,
"comments": [example_comment],
}
responses.add(
responses.GET,
"{}feed/{}/posts/{}/comments".format(BASE_URL, channel_id, post_id),
body=json.dumps(response),
status=200,
content_type="application/json",
)
client = TwitchClient("client id")
comments = client.channel_feed.get_post_comments(channel_id, post_id)
assert len(responses.calls) == 1
<|code_end|>
. Write the next line using the 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 Comment, Post
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 Comment(TwitchObject):
# pass
#
# class Post(TwitchObject):
# pass
, which may include functions, classes, or code. Output only the next line. | assert len(comments) == 1 |
Based on the snippet: <|code_start|>
# Note: comment doesn't have id prefixed with _ for some reason
example_comment = {
"id": "132629",
"body": "Hey there! KappaHD",
"created_at": "2016-11-29T15:52:27Z",
}
# Note: post doesn't have id prefixed with _ for some reason
example_post = {
"id": "443228891479487861",
"body": "News feed post!",
"comments": {
"_cursor": "1480434747093939000",
"_total": 1,
"comments": [example_comment],
},
"created_at": "2016-11-18T16:51:01Z",
}
@responses.activate
def test_get_posts():
<|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 Comment, Post
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 Comment(TwitchObject):
# pass
#
# class Post(TwitchObject):
# pass
. Output only the next line. | channel_id = "1234" |
Continue the code snippet: <|code_start|>def test_delete_reaction_to_post():
channel_id = "1234"
post_id = example_post["id"]
body = {"deleted": True}
responses.add(
responses.DELETE,
"{}feed/{}/posts/{}/reactions".format(BASE_URL, channel_id, post_id),
body=json.dumps(body),
status=200,
content_type="application/json",
)
client = TwitchClient("client id", "oauth token")
response = client.channel_feed.delete_reaction_to_post(channel_id, post_id, "1234")
assert len(responses.calls) == 1
assert response["deleted"]
@responses.activate
def test_get_post_comments():
channel_id = "1234"
post_id = example_post["id"]
response = {
"_cursor": "1480651694954867000",
"_total": 1,
"comments": [example_comment],
}
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 Comment, Post
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 Comment(TwitchObject):
# pass
#
# class Post(TwitchObject):
# pass
. Output only the next line. | responses.GET, |
Predict the next line after this snippet: <|code_start|>example_team_response = {
"_id": 10,
"name": "staff",
}
example_all_response = {"teams": [example_team_response]}
@responses.activate
def test_get():
team_name = "spongebob"
responses.add(
responses.GET,
"{}teams/{}".format(BASE_URL, team_name),
body=json.dumps(example_team_response),
status=200,
content_type="application/json",
)
client = TwitchClient("client id", "oauth token")
team = client.teams.get(team_name)
assert len(responses.calls) == 1
assert isinstance(team, Team)
assert team.id == example_team_response["_id"]
assert team.name == example_team_response["name"]
@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
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Team
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 Team(TwitchObject):
# pass
. Output only the next line. | def test_get_all(): |
Given the following code snippet before the placeholder: <|code_start|> assert team.id == example_team_response["_id"]
assert team.name == example_team_response["name"]
@responses.activate
def test_get_all():
responses.add(
responses.GET,
"{}teams".format(BASE_URL),
body=json.dumps(example_all_response),
status=200,
content_type="application/json",
)
client = TwitchClient("client id")
teams = client.teams.get_all()
assert len(responses.calls) == 1
assert len(teams) == 1
team = teams[0]
assert isinstance(team, Team)
assert team.id == example_team_response["_id"]
assert team.name == example_team_response["name"]
@responses.activate
@pytest.mark.parametrize("param,value", [("limit", 101)])
def test_get_all_raises_if_wrong_params_are_passed_in(param, value):
client = TwitchClient("client id")
<|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 Team
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 Team(TwitchObject):
# pass
. Output only the next line. | kwargs = {param: value} |
Given the following code snippet before the placeholder: <|code_start|>
example_team_response = {
"_id": 10,
"name": "staff",
}
example_all_response = {"teams": [example_team_response]}
@responses.activate
<|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 Team
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 Team(TwitchObject):
# pass
. Output only the next line. | def test_get(): |
Next line prediction: <|code_start|>
example_team_response = {
"_id": 10,
"name": "staff",
}
example_all_response = {"teams": [example_team_response]}
@responses.activate
def test_get():
team_name = "spongebob"
responses.add(
responses.GET,
"{}teams/{}".format(BASE_URL, team_name),
body=json.dumps(example_team_response),
status=200,
<|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 Team)
and context including class names, function names, or small code snippets 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 Team(TwitchObject):
# pass
. Output only the next line. | content_type="application/json", |
Given snippet: <|code_start|> return Post.construct_from(response)
@oauth_required
def create_post(self, channel_id, content, share=None):
data = {"content": content}
params = {"share": share}
response = self._request_post(
"feed/{}/posts".format(channel_id), data, params=params
)
return Post.construct_from(response["post"])
@oauth_required
def delete_post(self, channel_id, post_id):
response = self._request_delete("feed/{}/posts/{}".format(channel_id, post_id))
return Post.construct_from(response)
@oauth_required
def create_reaction_to_post(self, channel_id, post_id, emote_id):
params = {"emote_id": emote_id}
url = "feed/{}/posts/{}/reactions".format(channel_id, post_id)
response = self._request_post(url, params=params)
return response
@oauth_required
def delete_reaction_to_post(self, channel_id, post_id, emote_id):
params = {"emote_id": emote_id}
url = "feed/{}/posts/{}/reactions".format(channel_id, post_id)
response = self._request_delete(url, params=params)
return response
<|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 Comment, Post
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 Comment(TwitchObject):
# pass
#
# class Post(TwitchObject):
# pass
which might include code, classes, or functions. Output only the next line. | def get_post_comments(self, channel_id, post_id, limit=10, cursor=None): |
Given snippet: <|code_start|>
class ChannelFeed(TwitchAPI):
def get_posts(self, channel_id, limit=10, cursor=None, comments=5):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
)
if comments > 5:
raise TwitchAttributeException(
"Maximum number of comments returned in one request is 5"
)
params = {"limit": limit, "cursor": cursor, "comments": comments}
response = self._request_get("feed/{}/posts".format(channel_id), params=params)
return [Post.construct_from(x) for x in response["posts"]]
def get_post(self, channel_id, post_id, comments=5):
<|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 Comment, Post
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 Comment(TwitchObject):
# pass
#
# class Post(TwitchObject):
# pass
which might include code, classes, or functions. Output only the next line. | if comments > 5: |
Using the snippet: <|code_start|>
class ChannelFeed(TwitchAPI):
def get_posts(self, channel_id, limit=10, cursor=None, comments=5):
if limit > 100:
raise TwitchAttributeException(
"Maximum number of objects returned in one request is 100"
)
<|code_end|>
, determine the next line of code. You have imports:
from twitch.api.base import TwitchAPI
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Comment, Post
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/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 Comment(TwitchObject):
# pass
#
# class Post(TwitchObject):
# pass
. Output only the next line. | if comments > 5: |
Given snippet: <|code_start|> def get_post_comments(self, channel_id, post_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,
}
url = "feed/{}/posts/{}/comments".format(channel_id, post_id)
response = self._request_get(url, params=params)
return [Comment.construct_from(x) for x in response["comments"]]
@oauth_required
def create_post_comment(self, channel_id, post_id, content):
data = {"content": content}
url = "feed/{}/posts/{}/comments".format(channel_id, post_id)
response = self._request_post(url, data)
return Comment.construct_from(response)
@oauth_required
def delete_post_comment(self, channel_id, post_id, comment_id):
url = "feed/{}/posts/{}/comments/{}".format(channel_id, post_id, comment_id)
response = self._request_delete(url)
return Comment.construct_from(response)
@oauth_required
def create_reaction_to_comment(self, channel_id, post_id, comment_id, emote_id):
params = {"emote_id": emote_id}
<|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 Comment, Post
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 Comment(TwitchObject):
# pass
#
# class Post(TwitchObject):
# pass
which might include code, classes, or functions. Output only the next line. | url = "feed/{}/posts/{}/comments/{}/reactions".format( |
Next line prediction: <|code_start|> @oauth_required
def get_emotes(self, user_id):
response = self._request_get("users/{}/emotes".format(user_id))
return response["emoticon_sets"]
@oauth_required
def check_subscribed_to_channel(self, user_id, channel_id):
response = self._request_get(
"users/{}/subscriptions/{}".format(user_id, channel_id)
)
return Subscription.construct_from(response)
def get_all_follows(
self, user_id, direction=DIRECTION_DESC, sort_by=USERS_SORT_BY_CREATED_AT
):
if direction not in DIRECTIONS:
raise TwitchAttributeException(
"Direction is not valid. Valid values are {}".format(DIRECTIONS)
)
if sort_by not in USERS_SORT_BY:
raise TwitchAttributeException(
"Sort by is not valid. Valid values are {}".format(USERS_SORT_BY)
)
offset = 0
params = {"limit": MAX_FOLLOWS_LIMIT, "direction": direction}
follows = []
while offset is not None:
params.update({"offset": offset})
response = self._request_get(
"users/{}/follows/channels".format(user_id), params=params
<|code_end|>
. Use current file imports:
(from twitch.api.base import TwitchAPI
from twitch.constants import (
DIRECTION_DESC,
DIRECTIONS,
MAX_FOLLOWS_LIMIT,
USERS_SORT_BY,
USERS_SORT_BY_CREATED_AT,
)
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Follow, Subscription, User, UserBlock)
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
# DIRECTION_DESC = "desc"
#
# DIRECTIONS = [DIRECTION_ASC, DIRECTION_DESC]
#
# MAX_FOLLOWS_LIMIT = 100
#
# USERS_SORT_BY = [
# USERS_SORT_BY_CREATED_AT,
# USERS_SORT_BY_LAST_BROADCAST,
# USERS_SORT_BY_LOGIN,
# ]
#
# USERS_SORT_BY_CREATED_AT = "created_at"
#
# 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 Follow(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class User(TwitchObject):
# pass
#
# class UserBlock(TwitchObject):
# pass
. Output only the next line. | ) |
Predict the next line for this snippet: <|code_start|>
class Users(TwitchAPI):
@oauth_required
def get(self):
response = self._request_get("user")
return User.construct_from(response)
<|code_end|>
with the help of current file imports:
from twitch.api.base import TwitchAPI
from twitch.constants import (
DIRECTION_DESC,
DIRECTIONS,
MAX_FOLLOWS_LIMIT,
USERS_SORT_BY,
USERS_SORT_BY_CREATED_AT,
)
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Follow, Subscription, User, UserBlock
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
# DIRECTION_DESC = "desc"
#
# DIRECTIONS = [DIRECTION_ASC, DIRECTION_DESC]
#
# MAX_FOLLOWS_LIMIT = 100
#
# USERS_SORT_BY = [
# USERS_SORT_BY_CREATED_AT,
# USERS_SORT_BY_LAST_BROADCAST,
# USERS_SORT_BY_LOGIN,
# ]
#
# USERS_SORT_BY_CREATED_AT = "created_at"
#
# 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 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. | def get_by_id(self, user_id): |
Here is a snippet: <|code_start|>
class Users(TwitchAPI):
@oauth_required
def get(self):
response = self._request_get("user")
return User.construct_from(response)
def get_by_id(self, user_id):
response = self._request_get("users/{}".format(user_id))
return User.construct_from(response)
@oauth_required
def get_emotes(self, user_id):
response = self._request_get("users/{}/emotes".format(user_id))
return response["emoticon_sets"]
@oauth_required
def check_subscribed_to_channel(self, user_id, channel_id):
response = self._request_get(
"users/{}/subscriptions/{}".format(user_id, channel_id)
<|code_end|>
. Write the next line using the current file imports:
from twitch.api.base import TwitchAPI
from twitch.constants import (
DIRECTION_DESC,
DIRECTIONS,
MAX_FOLLOWS_LIMIT,
USERS_SORT_BY,
USERS_SORT_BY_CREATED_AT,
)
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Follow, Subscription, User, UserBlock
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
# DIRECTION_DESC = "desc"
#
# DIRECTIONS = [DIRECTION_ASC, DIRECTION_DESC]
#
# MAX_FOLLOWS_LIMIT = 100
#
# USERS_SORT_BY = [
# USERS_SORT_BY_CREATED_AT,
# USERS_SORT_BY_LAST_BROADCAST,
# USERS_SORT_BY_LOGIN,
# ]
#
# USERS_SORT_BY_CREATED_AT = "created_at"
#
# 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 Follow(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class User(TwitchObject):
# pass
#
# class UserBlock(TwitchObject):
# pass
, which may include functions, classes, or code. Output only the next line. | ) |
Using the snippet: <|code_start|>
def get_by_id(self, user_id):
response = self._request_get("users/{}".format(user_id))
return User.construct_from(response)
@oauth_required
def get_emotes(self, user_id):
response = self._request_get("users/{}/emotes".format(user_id))
return response["emoticon_sets"]
@oauth_required
def check_subscribed_to_channel(self, user_id, channel_id):
response = self._request_get(
"users/{}/subscriptions/{}".format(user_id, channel_id)
)
return Subscription.construct_from(response)
def get_all_follows(
self, user_id, direction=DIRECTION_DESC, sort_by=USERS_SORT_BY_CREATED_AT
):
if direction not in DIRECTIONS:
raise TwitchAttributeException(
"Direction is not valid. Valid values are {}".format(DIRECTIONS)
)
if sort_by not in USERS_SORT_BY:
raise TwitchAttributeException(
"Sort by is not valid. Valid values are {}".format(USERS_SORT_BY)
)
offset = 0
params = {"limit": MAX_FOLLOWS_LIMIT, "direction": direction}
<|code_end|>
, determine the next line of code. You have imports:
from twitch.api.base import TwitchAPI
from twitch.constants import (
DIRECTION_DESC,
DIRECTIONS,
MAX_FOLLOWS_LIMIT,
USERS_SORT_BY,
USERS_SORT_BY_CREATED_AT,
)
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Follow, Subscription, User, UserBlock
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
# DIRECTION_DESC = "desc"
#
# DIRECTIONS = [DIRECTION_ASC, DIRECTION_DESC]
#
# MAX_FOLLOWS_LIMIT = 100
#
# USERS_SORT_BY = [
# USERS_SORT_BY_CREATED_AT,
# USERS_SORT_BY_LAST_BROADCAST,
# USERS_SORT_BY_LOGIN,
# ]
#
# USERS_SORT_BY_CREATED_AT = "created_at"
#
# 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 Follow(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class User(TwitchObject):
# pass
#
# class UserBlock(TwitchObject):
# pass
. Output only the next line. | follows = [] |
Given the code snippet: <|code_start|> params.update({"offset": offset})
response = self._request_get(
"users/{}/follows/channels".format(user_id), params=params
)
offset = response.get("_offset")
follows.extend(response["follows"])
return [Follow.construct_from(x) for x in follows]
def get_follows(
self,
user_id,
limit=25,
offset=0,
direction=DIRECTION_DESC,
sort_by=USERS_SORT_BY_CREATED_AT,
):
if limit > MAX_FOLLOWS_LIMIT:
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)
)
if sort_by not in USERS_SORT_BY:
raise TwitchAttributeException(
"Sort by is not valid. Valid values are {}".format(USERS_SORT_BY)
)
params = {"limit": limit, "offset": offset, "direction": direction}
response = self._request_get(
<|code_end|>
, generate the next line using the imports in this file:
from twitch.api.base import TwitchAPI
from twitch.constants import (
DIRECTION_DESC,
DIRECTIONS,
MAX_FOLLOWS_LIMIT,
USERS_SORT_BY,
USERS_SORT_BY_CREATED_AT,
)
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Follow, Subscription, User, UserBlock
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
# DIRECTION_DESC = "desc"
#
# DIRECTIONS = [DIRECTION_ASC, DIRECTION_DESC]
#
# MAX_FOLLOWS_LIMIT = 100
#
# USERS_SORT_BY = [
# USERS_SORT_BY_CREATED_AT,
# USERS_SORT_BY_LAST_BROADCAST,
# USERS_SORT_BY_LOGIN,
# ]
#
# USERS_SORT_BY_CREATED_AT = "created_at"
#
# 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 Follow(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class User(TwitchObject):
# pass
#
# class UserBlock(TwitchObject):
# pass
. Output only the next line. | "users/{}/follows/channels".format(user_id), params=params |
Given the code snippet: <|code_start|> response = self._request_get(
"users/{}/follows/channels".format(user_id), params=params
)
return [Follow.construct_from(x) for x in response["follows"]]
def check_follows_channel(self, user_id, channel_id):
response = self._request_get(
"users/{}/follows/channels/{}".format(user_id, channel_id)
)
return Follow.construct_from(response)
@oauth_required
def follow_channel(self, user_id, channel_id, notifications=False):
data = {"notifications": notifications}
response = self._request_put(
"users/{}/follows/channels/{}".format(user_id, channel_id), data
)
return Follow.construct_from(response)
@oauth_required
def unfollow_channel(self, user_id, channel_id):
self._request_delete("users/{}/follows/channels/{}".format(user_id, channel_id))
@oauth_required
def get_user_block_list(self, user_id, limit=25, offset=0):
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 (
DIRECTION_DESC,
DIRECTIONS,
MAX_FOLLOWS_LIMIT,
USERS_SORT_BY,
USERS_SORT_BY_CREATED_AT,
)
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Follow, Subscription, User, UserBlock
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
# DIRECTION_DESC = "desc"
#
# DIRECTIONS = [DIRECTION_ASC, DIRECTION_DESC]
#
# MAX_FOLLOWS_LIMIT = 100
#
# USERS_SORT_BY = [
# USERS_SORT_BY_CREATED_AT,
# USERS_SORT_BY_LAST_BROADCAST,
# USERS_SORT_BY_LOGIN,
# ]
#
# USERS_SORT_BY_CREATED_AT = "created_at"
#
# 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 Follow(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class User(TwitchObject):
# pass
#
# class UserBlock(TwitchObject):
# pass
. Output only the next line. | params = {"limit": limit, "offset": offset} |
Predict the next line for this snippet: <|code_start|> ):
if limit > MAX_FOLLOWS_LIMIT:
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)
)
if sort_by not in USERS_SORT_BY:
raise TwitchAttributeException(
"Sort by is not valid. Valid values are {}".format(USERS_SORT_BY)
)
params = {"limit": limit, "offset": offset, "direction": direction}
response = self._request_get(
"users/{}/follows/channels".format(user_id), params=params
)
return [Follow.construct_from(x) for x in response["follows"]]
def check_follows_channel(self, user_id, channel_id):
response = self._request_get(
"users/{}/follows/channels/{}".format(user_id, channel_id)
)
return Follow.construct_from(response)
@oauth_required
def follow_channel(self, user_id, channel_id, notifications=False):
data = {"notifications": notifications}
response = self._request_put(
"users/{}/follows/channels/{}".format(user_id, channel_id), data
<|code_end|>
with the help of current file imports:
from twitch.api.base import TwitchAPI
from twitch.constants import (
DIRECTION_DESC,
DIRECTIONS,
MAX_FOLLOWS_LIMIT,
USERS_SORT_BY,
USERS_SORT_BY_CREATED_AT,
)
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Follow, Subscription, User, UserBlock
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
# DIRECTION_DESC = "desc"
#
# DIRECTIONS = [DIRECTION_ASC, DIRECTION_DESC]
#
# MAX_FOLLOWS_LIMIT = 100
#
# USERS_SORT_BY = [
# USERS_SORT_BY_CREATED_AT,
# USERS_SORT_BY_LAST_BROADCAST,
# USERS_SORT_BY_LOGIN,
# ]
#
# USERS_SORT_BY_CREATED_AT = "created_at"
#
# 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 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. | ) |
Continue the code snippet: <|code_start|>
class Users(TwitchAPI):
@oauth_required
def get(self):
response = self._request_get("user")
return User.construct_from(response)
def get_by_id(self, user_id):
response = self._request_get("users/{}".format(user_id))
return User.construct_from(response)
@oauth_required
def get_emotes(self, user_id):
response = self._request_get("users/{}/emotes".format(user_id))
return response["emoticon_sets"]
@oauth_required
def check_subscribed_to_channel(self, user_id, channel_id):
<|code_end|>
. Use current file imports:
from twitch.api.base import TwitchAPI
from twitch.constants import (
DIRECTION_DESC,
DIRECTIONS,
MAX_FOLLOWS_LIMIT,
USERS_SORT_BY,
USERS_SORT_BY_CREATED_AT,
)
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Follow, Subscription, User, UserBlock
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
# DIRECTION_DESC = "desc"
#
# DIRECTIONS = [DIRECTION_ASC, DIRECTION_DESC]
#
# MAX_FOLLOWS_LIMIT = 100
#
# USERS_SORT_BY = [
# USERS_SORT_BY_CREATED_AT,
# USERS_SORT_BY_LAST_BROADCAST,
# USERS_SORT_BY_LOGIN,
# ]
#
# USERS_SORT_BY_CREATED_AT = "created_at"
#
# 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 Follow(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class User(TwitchObject):
# pass
#
# class UserBlock(TwitchObject):
# pass
. Output only the next line. | response = self._request_get( |
Predict the next line for this snippet: <|code_start|> response = self._request_get("users/{}".format(user_id))
return User.construct_from(response)
@oauth_required
def get_emotes(self, user_id):
response = self._request_get("users/{}/emotes".format(user_id))
return response["emoticon_sets"]
@oauth_required
def check_subscribed_to_channel(self, user_id, channel_id):
response = self._request_get(
"users/{}/subscriptions/{}".format(user_id, channel_id)
)
return Subscription.construct_from(response)
def get_all_follows(
self, user_id, direction=DIRECTION_DESC, sort_by=USERS_SORT_BY_CREATED_AT
):
if direction not in DIRECTIONS:
raise TwitchAttributeException(
"Direction is not valid. Valid values are {}".format(DIRECTIONS)
)
if sort_by not in USERS_SORT_BY:
raise TwitchAttributeException(
"Sort by is not valid. Valid values are {}".format(USERS_SORT_BY)
)
offset = 0
params = {"limit": MAX_FOLLOWS_LIMIT, "direction": direction}
follows = []
while offset is not None:
<|code_end|>
with the help of current file imports:
from twitch.api.base import TwitchAPI
from twitch.constants import (
DIRECTION_DESC,
DIRECTIONS,
MAX_FOLLOWS_LIMIT,
USERS_SORT_BY,
USERS_SORT_BY_CREATED_AT,
)
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Follow, Subscription, User, UserBlock
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
# DIRECTION_DESC = "desc"
#
# DIRECTIONS = [DIRECTION_ASC, DIRECTION_DESC]
#
# MAX_FOLLOWS_LIMIT = 100
#
# USERS_SORT_BY = [
# USERS_SORT_BY_CREATED_AT,
# USERS_SORT_BY_LAST_BROADCAST,
# USERS_SORT_BY_LOGIN,
# ]
#
# USERS_SORT_BY_CREATED_AT = "created_at"
#
# 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 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. | params.update({"offset": offset}) |
Using the snippet: <|code_start|> "Sort by is not valid. Valid values are {}".format(USERS_SORT_BY)
)
params = {"limit": limit, "offset": offset, "direction": direction}
response = self._request_get(
"users/{}/follows/channels".format(user_id), params=params
)
return [Follow.construct_from(x) for x in response["follows"]]
def check_follows_channel(self, user_id, channel_id):
response = self._request_get(
"users/{}/follows/channels/{}".format(user_id, channel_id)
)
return Follow.construct_from(response)
@oauth_required
def follow_channel(self, user_id, channel_id, notifications=False):
data = {"notifications": notifications}
response = self._request_put(
"users/{}/follows/channels/{}".format(user_id, channel_id), data
)
return Follow.construct_from(response)
@oauth_required
def unfollow_channel(self, user_id, channel_id):
self._request_delete("users/{}/follows/channels/{}".format(user_id, channel_id))
@oauth_required
def get_user_block_list(self, user_id, limit=25, offset=0):
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 (
DIRECTION_DESC,
DIRECTIONS,
MAX_FOLLOWS_LIMIT,
USERS_SORT_BY,
USERS_SORT_BY_CREATED_AT,
)
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Follow, Subscription, User, UserBlock
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
# DIRECTION_DESC = "desc"
#
# DIRECTIONS = [DIRECTION_ASC, DIRECTION_DESC]
#
# MAX_FOLLOWS_LIMIT = 100
#
# USERS_SORT_BY = [
# USERS_SORT_BY_CREATED_AT,
# USERS_SORT_BY_LAST_BROADCAST,
# USERS_SORT_BY_LOGIN,
# ]
#
# USERS_SORT_BY_CREATED_AT = "created_at"
#
# 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 Follow(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class User(TwitchObject):
# pass
#
# class UserBlock(TwitchObject):
# pass
. Output only the next line. | "Maximum number of objects returned in one request is 100" |
Next line prediction: <|code_start|> )
return Subscription.construct_from(response)
def get_all_follows(
self, user_id, direction=DIRECTION_DESC, sort_by=USERS_SORT_BY_CREATED_AT
):
if direction not in DIRECTIONS:
raise TwitchAttributeException(
"Direction is not valid. Valid values are {}".format(DIRECTIONS)
)
if sort_by not in USERS_SORT_BY:
raise TwitchAttributeException(
"Sort by is not valid. Valid values are {}".format(USERS_SORT_BY)
)
offset = 0
params = {"limit": MAX_FOLLOWS_LIMIT, "direction": direction}
follows = []
while offset is not None:
params.update({"offset": offset})
response = self._request_get(
"users/{}/follows/channels".format(user_id), params=params
)
offset = response.get("_offset")
follows.extend(response["follows"])
return [Follow.construct_from(x) for x in follows]
def get_follows(
self,
user_id,
limit=25,
<|code_end|>
. Use current file imports:
(from twitch.api.base import TwitchAPI
from twitch.constants import (
DIRECTION_DESC,
DIRECTIONS,
MAX_FOLLOWS_LIMIT,
USERS_SORT_BY,
USERS_SORT_BY_CREATED_AT,
)
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Follow, Subscription, User, UserBlock)
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
# DIRECTION_DESC = "desc"
#
# DIRECTIONS = [DIRECTION_ASC, DIRECTION_DESC]
#
# MAX_FOLLOWS_LIMIT = 100
#
# USERS_SORT_BY = [
# USERS_SORT_BY_CREATED_AT,
# USERS_SORT_BY_LAST_BROADCAST,
# USERS_SORT_BY_LOGIN,
# ]
#
# USERS_SORT_BY_CREATED_AT = "created_at"
#
# 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 Follow(TwitchObject):
# pass
#
# class Subscription(TwitchObject):
# pass
#
# class User(TwitchObject):
# pass
#
# class UserBlock(TwitchObject):
# pass
. Output only the next line. | offset=0, |
Given the code snippet: <|code_start|> response = self._request_get(
"users/{}/follows/channels".format(user_id), params=params
)
offset = response.get("_offset")
follows.extend(response["follows"])
return [Follow.construct_from(x) for x in follows]
def get_follows(
self,
user_id,
limit=25,
offset=0,
direction=DIRECTION_DESC,
sort_by=USERS_SORT_BY_CREATED_AT,
):
if limit > MAX_FOLLOWS_LIMIT:
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)
)
if sort_by not in USERS_SORT_BY:
raise TwitchAttributeException(
"Sort by is not valid. Valid values are {}".format(USERS_SORT_BY)
)
params = {"limit": limit, "offset": offset, "direction": direction}
response = self._request_get(
"users/{}/follows/channels".format(user_id), params=params
<|code_end|>
, generate the next line using the imports in this file:
from twitch.api.base import TwitchAPI
from twitch.constants import (
DIRECTION_DESC,
DIRECTIONS,
MAX_FOLLOWS_LIMIT,
USERS_SORT_BY,
USERS_SORT_BY_CREATED_AT,
)
from twitch.decorators import oauth_required
from twitch.exceptions import TwitchAttributeException
from twitch.resources import Follow, Subscription, User, UserBlock
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
# DIRECTION_DESC = "desc"
#
# DIRECTIONS = [DIRECTION_ASC, DIRECTION_DESC]
#
# MAX_FOLLOWS_LIMIT = 100
#
# USERS_SORT_BY = [
# USERS_SORT_BY_CREATED_AT,
# USERS_SORT_BY_LAST_BROADCAST,
# USERS_SORT_BY_LOGIN,
# ]
#
# USERS_SORT_BY_CREATED_AT = "created_at"
#
# 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 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|> self._params["after"] = self._cursor
response = self._request_get(self._path, params=self._params)
self._requests_count += 1
self._queue = [self._resource.construct_from(data) for data in response["data"]]
self._cursor = response["pagination"].get("cursor")
self._total = response.get("total")
return self._queue
@property
def cursor(self):
return self._cursor
@property
def total(self):
if not self._total:
raise TwitchNotProvidedException()
return self._total
class APIGet(TwitchAPIMixin):
def __init__(self, client_id, path, resource, oauth_token=None, params=None):
super(APIGet, self).__init__()
self._path = path
self._resource = resource
self._client_id = client_id
self._oauth_token = oauth_token
self._params = params
def fetch(self):
<|code_end|>
. Use current file imports:
import logging
import time
import requests
from requests import codes
from requests.compat import urljoin
from twitch.constants import BASE_HELIX_URL
from twitch.exceptions import TwitchNotProvidedException
and context (classes, functions, or code) from other files:
# Path: twitch/constants.py
# BASE_HELIX_URL = "https://api.twitch.tv/helix/"
#
# Path: twitch/exceptions.py
# class TwitchNotProvidedException(TwitchException):
# pass
. Output only the next line. | response = self._request_get(self._path, params=self._params) |
Given the code snippet: <|code_start|> if not self._queue and not self.next_page():
raise StopIteration()
return self._queue.pop(0)
# Python 2 compatibility.
next = __next__
def __getitem__(self, index):
return self._queue[index]
def next_page(self):
# Twitch stops returning a cursor when you're on the last page. So if we've made
# more than 1 request to their API and we don't get a cursor back, it means
# we're on the last page, so return whatever's left in the queue.
if self._requests_count > 0 and not self._cursor:
return self._queue
if self._cursor:
self._params["after"] = self._cursor
response = self._request_get(self._path, params=self._params)
self._requests_count += 1
self._queue = [self._resource.construct_from(data) for data in response["data"]]
self._cursor = response["pagination"].get("cursor")
self._total = response.get("total")
return self._queue
@property
def cursor(self):
<|code_end|>
, generate the next line using the imports in this file:
import logging
import time
import requests
from requests import codes
from requests.compat import urljoin
from twitch.constants import BASE_HELIX_URL
from twitch.exceptions import TwitchNotProvidedException
and context (functions, classes, or occasionally code) from other files:
# Path: twitch/constants.py
# BASE_HELIX_URL = "https://api.twitch.tv/helix/"
#
# Path: twitch/exceptions.py
# class TwitchNotProvidedException(TwitchException):
# pass
. Output only the next line. | return self._cursor |
Given the following code snippet before the placeholder: <|code_start|>
@pytest.mark.parametrize(
"prop",
[
("channel_feed"),
("channels"),
("chat"),
("collections"),
("communities"),
("games"),
("ingests"),
<|code_end|>
, predict the next line using imports from the current file:
import os
import pytest
from twitch import TwitchClient
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
. Output only the next line. | ("search"), |
Continue the code snippet: <|code_start|> responses.add(
responses.GET,
"{}chat/{}/badges".format(BASE_URL, channel_id),
body=json.dumps(response),
status=200,
content_type="application/json",
)
client = TwitchClient("client id")
badges = client.chat.get_badges_by_channel(channel_id)
assert len(responses.calls) == 1
assert isinstance(badges, dict)
assert badges["admin"] == response["admin"]
@responses.activate
def test_get_emoticons_by_set():
response = {"emoticon_sets": {"19151": [example_emote]}}
responses.add(
responses.GET,
"{}chat/emoticon_images".format(BASE_URL),
body=json.dumps(response),
status=200,
content_type="application/json",
)
client = TwitchClient("client id")
<|code_end|>
. Use current file imports:
import json
import responses
from twitch.client import TwitchClient
from twitch.constants import BASE_URL
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/"
. Output only the next line. | emoticon_sets = client.chat.get_emoticons_by_set() |
Predict the next line for this snippet: <|code_start|>
assert len(responses.calls) == 1
assert isinstance(badges, dict)
assert badges["admin"] == response["admin"]
@responses.activate
def test_get_emoticons_by_set():
response = {"emoticon_sets": {"19151": [example_emote]}}
responses.add(
responses.GET,
"{}chat/emoticon_images".format(BASE_URL),
body=json.dumps(response),
status=200,
content_type="application/json",
)
client = TwitchClient("client id")
emoticon_sets = client.chat.get_emoticons_by_set()
assert len(responses.calls) == 1
assert isinstance(emoticon_sets, dict)
assert emoticon_sets["emoticon_sets"] == response["emoticon_sets"]
assert emoticon_sets["emoticon_sets"]["19151"][0] == example_emote
@responses.activate
def test_get_all_emoticons():
response = {"emoticons": [example_emote]}
<|code_end|>
with the help of current file imports:
import json
import responses
from twitch.client import TwitchClient
from twitch.constants import BASE_URL
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/"
, which may contain function names, class names, or code. Output only the next line. | responses.add( |
Based on the snippet: <|code_start|>
example_clip = {
"broadcast_id": "25782478272",
"title": "cold ace",
<|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 Clip
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 Clip(TwitchObject):
# pass
. Output only the next line. | "tracking_id": "102382269", |
Given snippet: <|code_start|>
example_clips = {"clips": [example_clip]}
@responses.activate
def test_get_by_slug():
slug = "OpenUglySnoodVoteNay"
responses.add(
responses.GET,
"{}clips/{}".format(BASE_URL, slug),
body=json.dumps(example_clip),
status=200,
content_type="application/json",
)
client = TwitchClient("client id")
clip = client.clips.get_by_slug(slug)
assert isinstance(clip, Clip)
assert clip.broadcast_id == example_clip["broadcast_id"]
@responses.activate
def test_get_top():
params = {"limit": 1, "period": "month"}
responses.add(
responses.GET,
"{}clips/top".format(BASE_URL),
<|code_end|>
, continue by predicting the next line. Consider current file imports:
import json
import responses
from twitch.client import TwitchClient
from twitch.constants import BASE_URL
from twitch.resources import Clip
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/resources.py
# class Clip(TwitchObject):
# pass
which might include code, classes, or functions. Output only the next line. | body=json.dumps(example_clips), |
Next line prediction: <|code_start|>
@responses.activate
def test_get_by_slug():
slug = "OpenUglySnoodVoteNay"
responses.add(
responses.GET,
"{}clips/{}".format(BASE_URL, slug),
body=json.dumps(example_clip),
status=200,
content_type="application/json",
)
client = TwitchClient("client id")
clip = client.clips.get_by_slug(slug)
assert isinstance(clip, Clip)
assert clip.broadcast_id == example_clip["broadcast_id"]
@responses.activate
def test_get_top():
params = {"limit": 1, "period": "month"}
responses.add(
responses.GET,
"{}clips/top".format(BASE_URL),
body=json.dumps(example_clips),
status=200,
content_type="application/json",
<|code_end|>
. Use current file imports:
(import json
import responses
from twitch.client import TwitchClient
from twitch.constants import BASE_URL
from twitch.resources import Clip)
and context including class names, function names, or small code snippets 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 Clip(TwitchObject):
# pass
. Output only the next line. | ) |
Here is a snippet: <|code_start|> assert summary["viewers"] == response["viewers"]
@responses.activate
def test_get_featured():
responses.add(
responses.GET,
"{}streams/featured".format(BASE_URL),
body=json.dumps(example_featured_response),
status=200,
content_type="application/json",
)
client = TwitchClient("client id")
featured = client.streams.get_featured()
assert len(responses.calls) == 1
assert len(featured) == 1
feature = featured[0]
assert isinstance(feature, Featured)
assert feature.title == example_featured_response["featured"][0]["title"]
stream = feature.stream
assert isinstance(stream, Stream)
assert stream.id == example_stream_response["stream"]["_id"]
assert stream.game == example_stream_response["stream"]["game"]
@responses.activate
@pytest.mark.parametrize("param,value", [("limit", 101)])
<|code_end|>
. Write the next line using the 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, Featured, 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 Featured(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
, which may include functions, classes, or code. Output only the next line. | def test_get_featured_raises_if_wrong_params_are_passed_in(param, value): |
Given snippet: <|code_start|> responses.add(
responses.GET,
"{}streams/{}".format(BASE_URL, channel_id),
body=json.dumps({"stream": None}),
status=200,
content_type="application/json",
)
client = TwitchClient("client id")
stream = client.streams.get_stream_by_user(channel_id)
assert len(responses.calls) == 1
assert stream is None
@responses.activate
@pytest.mark.parametrize("param,value", [("stream_type", "abcd")])
def test_get_stream_by_user_raises_if_wrong_params_are_passed_in(param, value):
client = TwitchClient("client id")
kwargs = {param: value}
with pytest.raises(TwitchAttributeException):
client.streams.get_stream_by_user("1234", **kwargs)
@responses.activate
def test_get_live_streams():
responses.add(
responses.GET,
"{}streams".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, Featured, 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 Featured(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
which might include code, classes, or functions. Output only the next line. | body=json.dumps(example_streams_response), |
Predict the next line after this snippet: <|code_start|>
example_stream = {
"_id": 23932774784,
"game": "BATMAN - The Telltale Series",
"channel": {"_id": 7236692, "name": "dansgaming"},
}
example_stream_response = {"stream": example_stream}
example_streams_response = {"_total": 1295, "streams": [example_stream]}
example_featured_response = {
"featured": [
{
"title": "Bethesda Plays The Elder Scrolls: Legends | More Arena & Deckbuilding",
"stream": example_stream,
}
]
}
@responses.activate
def test_get_stream_by_user():
channel_id = 7236692
responses.add(
responses.GET,
"{}streams/{}".format(BASE_URL, channel_id),
body=json.dumps(example_stream_response),
status=200,
<|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, Featured, Stream
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 Featured(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
. Output only the next line. | content_type="application/json", |
Here is a snippet: <|code_start|> client.streams.get_stream_by_user("1234", **kwargs)
@responses.activate
def test_get_live_streams():
responses.add(
responses.GET,
"{}streams".format(BASE_URL),
body=json.dumps(example_streams_response),
status=200,
content_type="application/json",
)
client = TwitchClient("client id")
streams = client.streams.get_live_streams()
assert len(responses.calls) == 1
assert len(streams) == 1
stream = streams[0]
assert isinstance(stream, Stream)
assert stream.id == example_stream_response["stream"]["_id"]
assert stream.game == example_stream_response["stream"]["game"]
assert isinstance(stream.channel, Channel)
assert stream.channel.id == example_stream_response["stream"]["channel"]["_id"]
assert stream.channel.name == example_stream_response["stream"]["channel"]["name"]
@responses.activate
<|code_end|>
. Write the next line using the 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, Featured, 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 Featured(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
, which may include functions, classes, or code. Output only the next line. | @pytest.mark.parametrize("param,value", [("limit", 101)]) |
Based on the snippet: <|code_start|>@pytest.mark.parametrize("param,value", [("limit", 101)])
def test_get_live_streams_raises_if_wrong_params_are_passed_in(param, value):
client = TwitchClient("client id")
kwargs = {param: value}
with pytest.raises(TwitchAttributeException):
client.streams.get_live_streams(**kwargs)
@responses.activate
def test_get_summary():
response = {"channels": 1417, "viewers": 19973}
responses.add(
responses.GET,
"{}streams/summary".format(BASE_URL),
body=json.dumps(response),
status=200,
content_type="application/json",
)
client = TwitchClient("client id")
summary = client.streams.get_summary()
assert len(responses.calls) == 1
assert isinstance(summary, dict)
assert summary["channels"] == response["channels"]
assert summary["viewers"] == response["viewers"]
@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, Featured, Stream
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 Featured(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
. Output only the next line. | def test_get_featured(): |
Continue the code snippet: <|code_start|> assert len(responses.calls) == 1
assert isinstance(stream, Stream)
assert stream.id == example_stream_response["stream"]["_id"]
assert stream.game == example_stream_response["stream"]["game"]
assert isinstance(stream.channel, Channel)
assert stream.channel.id == example_stream_response["stream"]["channel"]["_id"]
assert stream.channel.name == example_stream_response["stream"]["channel"]["name"]
@responses.activate
def test_get_stream_by_user_returns_none_if_stream_is_offline():
channel_id = 7236692
responses.add(
responses.GET,
"{}streams/{}".format(BASE_URL, channel_id),
body=json.dumps({"stream": None}),
status=200,
content_type="application/json",
)
client = TwitchClient("client id")
stream = client.streams.get_stream_by_user(channel_id)
assert len(responses.calls) == 1
assert stream is None
@responses.activate
<|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, Featured, 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 Featured(TwitchObject):
# pass
#
# class Stream(TwitchObject):
# pass
. Output only the next line. | @pytest.mark.parametrize("param,value", [("stream_type", "abcd")]) |
Given the following code snippet before the placeholder: <|code_start|>
example_community = {
"_id": "e9f17055-810f-4736-ba40-fba4ac541caa",
"name": "DallasTesterCommunity",
}
example_user = {
"_id": "44322889",
"name": "dallas",
}
@responses.activate
def test_get_by_name():
responses.add(
responses.GET,
"{}communities".format(BASE_URL),
body=json.dumps(example_community),
status=200,
content_type="application/json",
)
client = TwitchClient("client id")
community = client.communities.get_by_name("spongebob")
assert len(responses.calls) == 1
assert isinstance(community, Community)
<|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 Community, User
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 Community(TwitchObject):
# pass
#
# class User(TwitchObject):
# pass
. Output only the next line. | assert community.id == example_community["_id"] |
Given the code snippet: <|code_start|> client = TwitchClient("client id", "oauth token")
client.communities.delete_avatar_image(community_id)
assert len(responses.calls) == 1
@responses.activate
def test_create_cover_image():
community_id = "abcd"
responses.add(
responses.POST,
"{}communities/{}/images/cover".format(BASE_URL, community_id),
status=204,
content_type="application/json",
)
client = TwitchClient("client id", "oauth token")
client.communities.create_cover_image(community_id, "imagecontent")
assert len(responses.calls) == 1
@responses.activate
def test_delete_cover_image():
community_id = "abcd"
responses.add(
responses.DELETE,
"{}communities/{}/images/cover".format(BASE_URL, community_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 Community, User
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 Community(TwitchObject):
# pass
#
# class User(TwitchObject):
# pass
. Output only the next line. | status=204, |
Given the code snippet: <|code_start|>@pytest.mark.parametrize("param,value", [("limit", 101)])
def test_get_timed_out_users_raises_if_wrong_params_are_passed_in(param, value):
client = TwitchClient("client id", "oauth token")
kwargs = {param: value}
with pytest.raises(TwitchAttributeException):
client.communities.get_timed_out_users("1234", **kwargs)
@responses.activate
def test_add_timed_out_user():
community_id = "abcd"
user_id = 12345
responses.add(
responses.PUT,
"{}communities/{}/timeouts/{}".format(BASE_URL, community_id, user_id),
status=204,
content_type="application/json",
)
client = TwitchClient("client id", "oauth token")
client.communities.add_timed_out_user(community_id, user_id, 5)
assert len(responses.calls) == 1
@responses.activate
def test_delete_timed_out_user():
community_id = "abcd"
user_id = 12345
<|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 Community, User
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 Community(TwitchObject):
# pass
#
# class User(TwitchObject):
# pass
. Output only the next line. | responses.add( |
Given the following code snippet before the placeholder: <|code_start|>@responses.activate
@pytest.mark.parametrize("param,value", [("limit", 101)])
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.communities.get_top(**kwargs)
@responses.activate
def test_get_banned_users():
community_id = "abcd"
response = {"_cursor": "", "banned_users": [example_user]}
responses.add(
responses.GET,
"{}communities/{}/bans".format(BASE_URL, community_id),
body=json.dumps(response),
status=200,
content_type="application/json",
)
client = TwitchClient("client id", "oauth token")
users = client.communities.get_banned_users(community_id)
assert len(responses.calls) == 1
assert len(users) == 1
user = users[0]
assert isinstance(user, User)
<|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 Community, User
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 Community(TwitchObject):
# pass
#
# class User(TwitchObject):
# pass
. Output only the next line. | assert user.id == example_user["_id"] |
Here is a snippet: <|code_start|> responses.DELETE,
"{}communities/{}/images/cover".format(BASE_URL, community_id),
status=204,
content_type="application/json",
)
client = TwitchClient("client id", "oauth token")
client.communities.delete_cover_image(community_id)
assert len(responses.calls) == 1
@responses.activate
def test_get_moderators():
community_id = "abcd"
response = {"moderators": [example_user]}
responses.add(
responses.GET,
"{}communities/{}/moderators".format(BASE_URL, community_id),
body=json.dumps(response),
status=200,
content_type="application/json",
)
client = TwitchClient("client id", "oauth token")
moderators = client.communities.get_moderators(community_id)
<|code_end|>
. Write the next line using the 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 Community, User
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 Community(TwitchObject):
# pass
#
# class User(TwitchObject):
# pass
, which may include functions, classes, or code. Output only the next line. | assert len(responses.calls) == 1 |
Predict the next line after this snippet: <|code_start|>
client.collections.create_thumbnail(collection_id, "1234")
assert len(responses.calls) == 1
@responses.activate
def test_delete():
collection_id = "abcd"
responses.add(
responses.DELETE,
"{}collections/{}".format(BASE_URL, collection_id),
status=204,
content_type="application/json",
)
client = TwitchClient("client id", "oauth client")
client.collections.delete(collection_id)
assert len(responses.calls) == 1
@responses.activate
def test_add_item():
collection_id = "abcd"
responses.add(
responses.PUT,
"{}collections/{}/items".format(BASE_URL, collection_id),
body=json.dumps(example_item),
<|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 Collection, Item
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 Collection(TwitchObject):
# pass
#
# class Item(TwitchObject):
# pass
. Output only the next line. | status=200, |
Given the following code snippet before the placeholder: <|code_start|>
assert len(responses.calls) == 1
@responses.activate
def test_add_item():
collection_id = "abcd"
responses.add(
responses.PUT,
"{}collections/{}/items".format(BASE_URL, collection_id),
body=json.dumps(example_item),
status=200,
content_type="application/json",
)
client = TwitchClient("client id", "oauth client")
item = client.collections.add_item(collection_id, "1234", "video")
assert len(responses.calls) == 1
assert isinstance(item, Item)
assert item.id == example_item["_id"]
assert item.title == example_item["title"]
@responses.activate
def test_delete_item():
collection_id = "abcd"
collection_item_id = "1234"
responses.add(
<|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 Collection, Item
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 Collection(TwitchObject):
# pass
#
# class Item(TwitchObject):
# pass
. Output only the next line. | responses.DELETE, |
Here is a snippet: <|code_start|> responses.add(
responses.GET,
"{}collections/{}/items".format(BASE_URL, collection_id),
body=json.dumps(response),
status=200,
content_type="application/json",
)
client = TwitchClient("client id", "oauth token")
items = client.collections.get(collection_id)
assert len(responses.calls) == 1
assert len(items) == 1
item = items[0]
assert isinstance(item, Item)
assert item.id == example_item["_id"]
assert item.title == example_item["title"]
@responses.activate
def test_get_by_channel():
channel_id = "abcd"
response = {"_cursor": None, "collections": [example_collection]}
responses.add(
responses.GET,
"{}channels/{}/collections".format(BASE_URL, channel_id),
body=json.dumps(response),
status=200,
content_type="application/json",
<|code_end|>
. Write the next line using the 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 Collection, Item
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 Collection(TwitchObject):
# pass
#
# class Item(TwitchObject):
# pass
, which may include functions, classes, or code. Output only the next line. | ) |
Given snippet: <|code_start|>
example_collection = {
"_id": "myIbIFkZphQSbQ",
"items_count": 3,
"updated_at": "2017-03-06T18:40:51.855Z",
}
example_item = {
"_id": "eyJ0eXBlIjoidmlkZW8iLCJpZCI6IjEyMjEzODk0OSJ9",
"item_id": "122138949",
"item_type": "video",
"published_at": "2017-02-14T22:27:54Z",
"title": "Fanboys Episode 1 w/ Gassy Mexican",
}
@responses.activate
def test_get_metadata():
collection_id = "abcd"
responses.add(
responses.GET,
"{}collections/{}".format(BASE_URL, collection_id),
body=json.dumps(example_collection),
status=200,
content_type="application/json",
)
client = TwitchClient("client id", "oauth token")
<|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 Collection, Item
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 Collection(TwitchObject):
# pass
#
# class Item(TwitchObject):
# pass
which might include code, classes, or functions. Output only the next line. | collection = client.collections.get_metadata(collection_id) |
Predict the next line for this snippet: <|code_start|> status=204,
content_type="application/json",
)
client = TwitchClient("client id", "oauth client")
client.collections.create_thumbnail(collection_id, "1234")
assert len(responses.calls) == 1
@responses.activate
def test_delete():
collection_id = "abcd"
responses.add(
responses.DELETE,
"{}collections/{}".format(BASE_URL, collection_id),
status=204,
content_type="application/json",
)
client = TwitchClient("client id", "oauth client")
client.collections.delete(collection_id)
assert len(responses.calls) == 1
@responses.activate
def test_add_item():
<|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 Collection, Item
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 Collection(TwitchObject):
# pass
#
# class Item(TwitchObject):
# pass
, which may contain function names, class names, or code. Output only the next line. | collection_id = "abcd" |
Given snippet: <|code_start|>
example_top_games_response = {
"_total": 1157,
"top": [
{
"channels": 953,
"viewers": 171708,
"game": {
"_id": 32399,
"box": {
"large": (
"https://static-cdn.jtvnw.net/ttv-boxart/"
"Counter-Strike:%20Global%20Offensive-272x380.jpg"
),
"medium": (
"https://static-cdn.jtvnw.net/ttv-boxart/"
"Counter-Strike:%20Global%20Offensive-136x190.jpg"
<|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 Game, TopGame
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 Game(TwitchObject):
# pass
#
# class TopGame(TwitchObject):
# pass
which might include code, classes, or functions. Output only the next line. | ), |
Given snippet: <|code_start|> "Counter-Strike:%20Global%20Offensive-60x36.jpg"
),
"template": (
"https://static-cdn.jtvnw.net/ttv-logoart/Counter-"
"Strike:%20Global%20Offensive-{width}x{height}.jpg"
),
},
"name": "Counter-Strike: Global Offensive",
"popularity": 170487,
},
}
],
}
@responses.activate
def test_get_top():
responses.add(
responses.GET,
"{}games/top".format(BASE_URL),
body=json.dumps(example_top_games_response),
status=200,
content_type="application/json",
)
client = TwitchClient("abcd")
games = client.games.get_top()
assert len(responses.calls) == 1
<|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 Game, TopGame
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 Game(TwitchObject):
# pass
#
# class TopGame(TwitchObject):
# pass
which might include code, classes, or functions. Output only the next line. | assert len(games) == 1 |
Predict the next line after this snippet: <|code_start|> "giantbomb_id": 36113,
"logo": {
"large": (
"https://static-cdn.jtvnw.net/ttv-logoart/"
"Counter-Strike:%20Global%20Offensive-240x144.jpg"
),
"medium": (
"https://static-cdn.jtvnw.net/ttv-logoart/"
"Counter-Strike:%20Global%20Offensive-120x72.jpg"
),
"small": (
"https://static-cdn.jtvnw.net/ttv-logoart/"
"Counter-Strike:%20Global%20Offensive-60x36.jpg"
),
"template": (
"https://static-cdn.jtvnw.net/ttv-logoart/Counter-"
"Strike:%20Global%20Offensive-{width}x{height}.jpg"
),
},
"name": "Counter-Strike: Global Offensive",
"popularity": 170487,
},
}
],
}
@responses.activate
def test_get_top():
responses.add(
<|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 Game, TopGame
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 Game(TwitchObject):
# pass
#
# class TopGame(TwitchObject):
# pass
. Output only the next line. | responses.GET, |
Predict the next line for this snippet: <|code_start|>
example_top_games_response = {
"_total": 1157,
"top": [
{
"channels": 953,
"viewers": 171708,
"game": {
"_id": 32399,
"box": {
"large": (
"https://static-cdn.jtvnw.net/ttv-boxart/"
"Counter-Strike:%20Global%20Offensive-272x380.jpg"
),
"medium": (
"https://static-cdn.jtvnw.net/ttv-boxart/"
"Counter-Strike:%20Global%20Offensive-136x190.jpg"
),
"small": (
"https://static-cdn.jtvnw.net/ttv-boxart/"
"Counter-Strike:%20Global%20Offensive-52x72.jpg"
),
"template": (
"https://static-cdn.jtvnw.net/ttv-boxart/Counter-St"
"rike:%20Global%20Offensive-{width}x{height}.jpg"
),
<|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 Game, TopGame
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 Game(TwitchObject):
# pass
#
# class TopGame(TwitchObject):
# pass
, which may contain function names, class names, or code. Output only the next line. | }, |
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
<|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. | ): |
Given snippet: <|code_start|> "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):
response = self._request_get("channels/{}/community".format(channel_id))
return Community.construct_from(response)
def set_community(self, channel_id, community_id):
self._request_put("channels/{}/community/{}".format(channel_id, community_id))
<|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. | def delete_from_community(self, channel_id): |
Predict the next line for 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|>
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. | response = self._request_get("channels/{}/community".format(channel_id)) |
Using the snippet: <|code_start|> )
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(
"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}
<|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,
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 (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,
# ]
#
# 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( |
Given the following code snippet before the placeholder: <|code_start|> 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(
"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
<|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. | ) |
Based on the snippet: <|code_start|> 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,
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|>
, 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. | ) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.