uid stringlengths 24 24 | split stringclasses 1
value | category stringclasses 2
values | content stringlengths 5 482k | signature stringlengths 1 14k | suffix stringlengths 1 482k | prefix stringlengths 9 14k | prefix_token_count int64 3 5.01k | prefix_token_budget int64 64 256 | element_token_count int64 1 292k | signature_token_count int64 1 5.01k | prefix_context_token_count int64 0 255 | repo stringlengths 7 112 | path stringlengths 4 208 | language stringclasses 1
value | name stringlengths 1 218 | qualname stringlengths 1 218 | start_line int64 1 26.7k | end_line int64 1 26.7k | signature_start_line int64 1 26.7k | signature_end_line int64 1 26.7k | source_hash stringlengths 40 40 | source_dataset stringclasses 1
value | source_split stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
3c8298ad1307fcbb23f73282 | train | function | def test_direct_with_a_missing_feature(features):
encoding = DirectStringEncoding(feature='not_class')
with pytest.raises(KeyError):
encoding(features)
| def test_direct_with_a_missing_feature(features):
| encoding = DirectStringEncoding(feature='not_class')
with pytest.raises(KeyError):
encoding(features)
| np.testing.assert_array_equal(values, ['a', 'b', 'c', 'd'])
def test_direct(features):
encoding = DirectStringEncoding(feature='class')
values = encoding(features)
np.testing.assert_array_equal(values, features['class'])
def test_direct_with_a_missing_feature(features):
| 63 | 64 | 31 | 9 | 54 | jojoelfe/napari | napari/layers/utils/_tests/test_string_encoding.py | Python | test_direct_with_a_missing_feature | test_direct_with_a_missing_feature | 106 | 109 | 106 | 106 | bbfa5fb484dbe013c53146b5dd3436d635299759 | bigcode/the-stack | train |
5e497bf04be09acee8e934f0 | train | function | def test_validate_from_direct_dict():
feature = 'class'
argument = {'feature': feature}
expected = DirectStringEncoding(feature=feature)
actual = StringEncoding.validate(argument)
assert actual == expected
| def test_validate_from_direct_dict():
| feature = 'class'
argument = {'feature': feature}
expected = DirectStringEncoding(feature=feature)
actual = StringEncoding.validate(argument)
assert actual == expected
| array = ['a', 'b', 'c']
default = 'd'
argument = {'array': array, 'default': default}
expected = ManualStringEncoding(array=array, default=default)
actual = StringEncoding.validate(argument)
assert actual == expected
def test_validate_from_direct_dict():
| 64 | 64 | 45 | 7 | 56 | jojoelfe/napari | napari/layers/utils/_tests/test_string_encoding.py | Python | test_validate_from_direct_dict | test_validate_from_direct_dict | 184 | 191 | 184 | 184 | f7f99ff2a92e6fbd9c9b588f9a9b2a74dac932f6 | bigcode/the-stack | train |
47c01c027da43d3b6f5af62c | train | function | def test_format_with_bad_string(features):
encoding = FormatStringEncoding(format='{class}: {confidence:.2f')
with pytest.raises(ValueError):
encoding(features)
| def test_format_with_bad_string(features):
| encoding = FormatStringEncoding(format='{class}: {confidence:.2f')
with pytest.raises(ValueError):
encoding(features)
| ):
encoding = FormatStringEncoding(format='{class}: {confidence:.2f}')
values = encoding(features)
np.testing.assert_array_equal(values, ['a: 0.50', 'b: 1.00', 'c: 0.25'])
def test_format_with_bad_string(features):
| 63 | 64 | 35 | 8 | 55 | jojoelfe/napari | napari/layers/utils/_tests/test_string_encoding.py | Python | test_format_with_bad_string | test_format_with_bad_string | 118 | 121 | 118 | 118 | 4edfc38ba76faa3a6d5bc1e2ed8006d998504108 | bigcode/the-stack | train |
5ee37ab1dd7090020367c462 | train | function | def test_direct(features):
encoding = DirectStringEncoding(feature='class')
values = encoding(features)
np.testing.assert_array_equal(values, features['class'])
| def test_direct(features):
| encoding = DirectStringEncoding(feature='class')
values = encoding(features)
np.testing.assert_array_equal(values, features['class'])
| )
array = ['a', 'b', 'c']
default = 'd'
encoding = ManualStringEncoding(array=array, default=default)
values = encoding(features)
np.testing.assert_array_equal(values, ['a', 'b', 'c', 'd'])
def test_direct(features):
| 63 | 64 | 33 | 5 | 58 | jojoelfe/napari | napari/layers/utils/_tests/test_string_encoding.py | Python | test_direct | test_direct | 100 | 103 | 100 | 100 | 3d7221b9019192219456644ceaacb2524f88e607 | bigcode/the-stack | train |
a82ae3a8455818907e85cf7c | train | function | def label_smoothed_nll_loss(lprobs, target, epsilon, ignore_index=None, reduce=True):
"""compute labeled smoothed nll loss
Returns:
loss: the actual loss to be optimized (after smoothing), with
shape (batch) if reduce is true else (batch, seq_len)
nll_loss: the NLL loss with shape (... | def label_smoothed_nll_loss(lprobs, target, epsilon, ignore_index=None, reduce=True):
| """compute labeled smoothed nll loss
Returns:
loss: the actual loss to be optimized (after smoothing), with
shape (batch) if reduce is true else (batch, seq_len)
nll_loss: the NLL loss with shape (batch) if reduce is true else
(batch, seq_len)
"""
if target.dim()... | the MIT license found in the
# LICENSE file in the root directory of this source tree.
import math
import os
import torch
import torch.nn as nn
import torch.nn.functional as F
from fairseq import metrics, utils
from fairseq.criterions import LegacyFairseqCriterion, FairseqCriterion, register_criterion
def label_smoo... | 91 | 91 | 305 | 22 | 68 | ProKil/sparse-text-prototype | sparse_prototype/lm_criterion.py | Python | label_smoothed_nll_loss | label_smoothed_nll_loss | 16 | 43 | 16 | 16 | e96254c52bacf96672a7283d0b33321d09006c11 | bigcode/the-stack | train |
e60c35c6235c1968e754350d | train | class | @register_criterion('lm_baseline')
class LMBaseline(LegacyFairseqCriterion):
def __init__(self, args, task):
super().__init__(args, task)
self.eps = args.label_smoothing
if args.write_loss_path is not None:
self.f_loss = open(os.path.join(args.save_dir, args.write_loss_path), '... | @register_criterion('lm_baseline')
class LMBaseline(LegacyFairseqCriterion):
| def __init__(self, args, task):
super().__init__(args, task)
self.eps = args.label_smoothing
if args.write_loss_path is not None:
self.f_loss = open(os.path.join(args.save_dir, args.write_loss_path), 'w')
else:
self.f_loss = None
@staticmethod
def ad... | _fill_(pad_mask, 0.)
nll_loss = nll_loss.squeeze(-1)
smooth_loss = smooth_loss.squeeze(-1)
# (batch, seq_len) --> (batch)
if reduce:
nll_loss = nll_loss.sum(-1)
smooth_loss = smooth_loss.sum(-1)
eps_i = epsilon / lprobs.size(-1)
loss = (1. - epsilon) * nll_loss + eps_i * smooth... | 255 | 256 | 940 | 21 | 234 | ProKil/sparse-text-prototype | sparse_prototype/lm_criterion.py | Python | LMBaseline | LMBaseline | 54 | 143 | 54 | 56 | d6696cf40c6d580c3e596726eba25f0296455a5c | bigcode/the-stack | train |
54655d03ba2a44e144a3b7c8 | train | function | def write_loss(ll_batch, sample, infer_ns, fout):
revert_order = sample['net_input']['revert_order']
id_list = sample['tgt_id'].index_select(0, revert_order).view(-1, infer_ns)[:, 0]
length_list = sample['net_input']['src_lengths'].index_select(0, revert_order).view(-1, infer_ns)[:, 0]
for id_, ntoken,... | def write_loss(ll_batch, sample, infer_ns, fout):
| revert_order = sample['net_input']['revert_order']
id_list = sample['tgt_id'].index_select(0, revert_order).view(-1, infer_ns)[:, 0]
length_list = sample['net_input']['src_lengths'].index_select(0, revert_order).view(-1, infer_ns)[:, 0]
for id_, ntoken, ll in zip(id_list, length_list, ll_batch):
... | smooth_loss = smooth_loss.sum(-1)
eps_i = epsilon / lprobs.size(-1)
loss = (1. - epsilon) * nll_loss + eps_i * smooth_loss
return loss, nll_loss
def write_loss(ll_batch, sample, infer_ns, fout):
| 64 | 64 | 125 | 13 | 50 | ProKil/sparse-text-prototype | sparse_prototype/lm_criterion.py | Python | write_loss | write_loss | 45 | 51 | 45 | 45 | 3a3e8039d14c6e53e2dbdc055c8b83b508117284 | bigcode/the-stack | train |
5b4a73c1078025dc29097c46 | train | class | class KnownValues(unittest.TestCase):
def test_r_outcore_eri(self):
n2c = mol.nao_2c()
numpy.random.seed(1)
mo = numpy.random.random((n2c,n2c)) + numpy.random.random((n2c,n2c))*1j
eriref = trans(eri0, [mo]*4)
ftmp = tempfile.NamedTemporaryFile()
ao2mo.kernel(mol, mo,... | class KnownValues(unittest.TestCase):
| def test_r_outcore_eri(self):
n2c = mol.nao_2c()
numpy.random.seed(1)
mo = numpy.random.random((n2c,n2c)) + numpy.random.random((n2c,n2c))*1j
eriref = trans(eri0, [mo]*4)
ftmp = tempfile.NamedTemporaryFile()
ao2mo.kernel(mol, mo, erifile=ftmp.name, intor='int2e_spino... | ole()
mol.verbose = 5
mol.output = '/dev/null'
mol.atom = [
["O" , (0. , 0. , 0.)],
[1 , (0. , -0.757 , 0.587)],
[1 , (0. , 0.757 , 0.587)]]
mol.basis = '631g'
mol.build()
eri0 = mol.intor('int2e_spinor')
def tearDownModule():
global mol, eri0
mol.stdout... | 256 | 256 | 1,225 | 7 | 248 | willwheelera/pyscf | pyscf/ao2mo/test/test_r_outcore.py | Python | KnownValues | KnownValues | 48 | 110 | 48 | 48 | 551693e6b836b12f2b2736148b3bc94aa10b6357 | bigcode/the-stack | train |
eaf4be622ae09d6a92f4a9af | train | function | def tearDownModule():
global mol, eri0
mol.stdout.close()
del mol, eri0
| def tearDownModule():
| global mol, eri0
mol.stdout.close()
del mol, eri0
| , -0.757 , 0.587)],
[1 , (0. , 0.757 , 0.587)]]
mol.basis = '631g'
mol.build()
eri0 = mol.intor('int2e_spinor')
def tearDownModule():
| 64 | 64 | 24 | 5 | 59 | willwheelera/pyscf | pyscf/ao2mo/test/test_r_outcore.py | Python | tearDownModule | tearDownModule | 36 | 39 | 36 | 36 | cfa30d1ea2f74abb14ea295d843ebd1bdb581ef9 | bigcode/the-stack | train |
9d74a6cab77be51fd08ddc57 | train | function | def setUpModule():
global mol, eri0
mol = gto.Mole()
mol.verbose = 5
mol.output = '/dev/null'
mol.atom = [
["O" , (0. , 0. , 0.)],
[1 , (0. , -0.757 , 0.587)],
[1 , (0. , 0.757 , 0.587)]]
mol.basis = '631g'
mol.build()
eri0 = mol.intor('int2e_spinor')
| def setUpModule():
| global mol, eri0
mol = gto.Mole()
mol.verbose = 5
mol.output = '/dev/null'
mol.atom = [
["O" , (0. , 0. , 0.)],
[1 , (0. , -0.757 , 0.587)],
[1 , (0. , 0.757 , 0.587)]]
mol.basis = '631g'
mol.build()
eri0 = mol.intor('int2e_spinor')
| OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import unittest
import tempfile
import numpy
from pyscf import lib
from pyscf import gto
from pyscf import ao2mo
def setUpModule():
| 64 | 64 | 125 | 5 | 58 | willwheelera/pyscf | pyscf/ao2mo/test/test_r_outcore.py | Python | setUpModule | setUpModule | 23 | 34 | 23 | 23 | a6b064ba9f0a9de5b005f86df03df6bfa697d389 | bigcode/the-stack | train |
54e67a51595cb8de67dcc33a | train | function | def trans(eri, mos):
eriref = lib.einsum('pjkl,pi->ijkl', eri , mos[0].conj())
eriref = lib.einsum('ipkl,pj->ijkl', eriref, mos[1])
eriref = lib.einsum('ijpl,pk->ijkl', eriref, mos[2].conj())
eriref = lib.einsum('ijkp,pl->ijkl', eriref, mos[3])
return eriref
| def trans(eri, mos):
| eriref = lib.einsum('pjkl,pi->ijkl', eri , mos[0].conj())
eriref = lib.einsum('ipkl,pj->ijkl', eriref, mos[1])
eriref = lib.einsum('ijpl,pk->ijkl', eriref, mos[2].conj())
eriref = lib.einsum('ijkp,pl->ijkl', eriref, mos[3])
return eriref
| 0.587)]]
mol.basis = '631g'
mol.build()
eri0 = mol.intor('int2e_spinor')
def tearDownModule():
global mol, eri0
mol.stdout.close()
del mol, eri0
def trans(eri, mos):
| 64 | 64 | 118 | 7 | 56 | willwheelera/pyscf | pyscf/ao2mo/test/test_r_outcore.py | Python | trans | trans | 41 | 46 | 41 | 41 | 5a62e586defc4f8d6688b80015c402b3428909f9 | bigcode/the-stack | train |
9ceece911714480e38fdc470 | train | function | def create_model(epsilon=0.01):
alpha[0]/alpha[1]
data={}
data['constraint_coeffs']=[
[current_prices[0],-(epsilon+alpha[0]/alpha[1])*current_prices[1],current_prices[0],-(epsilon+alpha[0]/alpha[1])*current_prices[1]],
[current_prices[0],-(alpha[0]/alpha[1]-epsilon)*current_prices[1],cu... | def create_model(epsilon=0.01):
| alpha[0]/alpha[1]
data={}
data['constraint_coeffs']=[
[current_prices[0],-(epsilon+alpha[0]/alpha[1])*current_prices[1],current_prices[0],-(epsilon+alpha[0]/alpha[1])*current_prices[1]],
[current_prices[0],-(alpha[0]/alpha[1]-epsilon)*current_prices[1],current_prices[0],-(alpha[0]/alpha[... | r = requests.get(url)
txt = r.text
cookie = r.cookies['B']
pattern = re.compile('.*"CrumbStore":\{"crumb":"(?P<crumb>[^"]+)"\}')
for line in txt.splitlines():
m = pattern.match(line)
if m is not None:
crumb = m.groupdict()['crumb']
return cookie,crumb
de... | 96 | 96 | 323 | 10 | 85 | hainingpan/inverse_volatility_caculation | obsolete/inverse_volatility.py | Python | create_model | create_model | 63 | 79 | 63 | 63 | c642d67e9f2dd12c6a92e02145ecaa3ddbae4735 | bigcode/the-stack | train |
c882f48f5964cf8715c3ae49 | train | function | def get_cookie():
url = 'https://finance.yahoo.com/quote/VOO/history?p=VOO'
r = requests.get(url)
txt = r.text
cookie = r.cookies['B']
pattern = re.compile('.*"CrumbStore":\{"crumb":"(?P<crumb>[^"]+)"\}')
for line in txt.splitlines():
m = pattern.match(line)
if m is not ... | def get_cookie():
| url = 'https://finance.yahoo.com/quote/VOO/history?p=VOO'
r = requests.get(url)
txt = r.text
cookie = r.cookies['B']
pattern = re.compile('.*"CrumbStore":\{"crumb":"(?P<crumb>[^"]+)"\}')
for line in txt.splitlines():
m = pattern.match(line)
if m is not None:
... | recent trading day is {}".format(date.today(), most_recent_date)
return np.std(volatilities_in_window, ddof = 1) * np.sqrt(num_trading_days_per_year), prices[0] / prices[window_size] - 1.0, prices[0]
def get_cookie():
| 63 | 64 | 111 | 4 | 59 | hainingpan/inverse_volatility_caculation | obsolete/inverse_volatility.py | Python | get_cookie | get_cookie | 51 | 61 | 51 | 51 | 0e606605006cb2a8db663691e258fba5ccb70d25 | bigcode/the-stack | train |
63abadeb5228d01fe3571083 | train | function | def get_volatility_and_performance(symbol,cookie,crumb):
download_url = "https://query1.finance.yahoo.com/v7/finance/download/{}?period1={}&period2={}&interval=1d&events=history&crumb={}".format(symbol, start_timestamp, end_timestamp,crumb)
lines = requests.get(download_url, cookies={'B': cookie}).text.strip(... | def get_volatility_and_performance(symbol,cookie,crumb):
| download_url = "https://query1.finance.yahoo.com/v7/finance/download/{}?period1={}&period2={}&interval=1d&events=history&crumb={}".format(symbol, start_timestamp, end_timestamp,crumb)
lines = requests.get(download_url, cookies={'B': cookie}).text.strip().split('\n')
# print(cookie)
# print(crumb)
# pr... | s)):
symbols[i] = symbols[i].strip().upper()
num_trading_days_per_year = 252
window_size = 20
date_format = "%Y-%m-%d"
end_timestamp = int(time.time())
start_timestamp = int(end_timestamp - (1.4 * (window_size + 1) + 4) * 86400)
def get_volatility_and_performance(symbol,cookie,crumb):
| 88 | 88 | 296 | 13 | 75 | hainingpan/inverse_volatility_caculation | obsolete/inverse_volatility.py | Python | get_volatility_and_performance | get_volatility_and_performance | 28 | 48 | 28 | 28 | 072002d0dc1f0087c1a95b8d94647138b9be5fdc | bigcode/the-stack | train |
242bc11a3505d0ea89747b7f | train | class | class PyText:
def __init__(self, master):
#This section of code creates our window and sizes it at startup:
master.title("Untitled - Quill")
master.geometry("1200x700")
font_specs = ("Monoid", 8)
self.master = master
self.filename = None
s... | class PyText:
| def __init__(self, master):
#This section of code creates our window and sizes it at startup:
master.title("Untitled - Quill")
master.geometry("1200x700")
font_specs = ("Monoid", 8)
self.master = master
self.filename = None
self.textarea = ... | youtube, credit for the basic outline of this program goes to him and his PyText Editor!
import tkinter as tk
from tkinter import filedialog
class Menubar:
def __init__(self,parent):
font_specs = ("Monoid", 8)
menubar = tk.Menu(parent.master, font=font_specs)
parent.master.config(men... | 256 | 256 | 14,173 | 4 | 252 | wildflower-42/Quill | Quill.py | Python | PyText | PyText | 22 | 103 | 22 | 22 | c5b1a8c66983659bd2d76d8bea0d752ebd434fc2 | bigcode/the-stack | train |
28393c804da727a8bf62a1dd | train | class | class Menubar:
def __init__(self,parent):
font_specs = ("Monoid", 8)
menubar = tk.Menu(parent.master, font=font_specs)
parent.master.config(menu=menubar)
#This section of code creates all the options for our first menubar:
file_dropdown = tk.Menu(menubar, font=font_spec... | class Menubar:
| def __init__(self,parent):
font_specs = ("Monoid", 8)
menubar = tk.Menu(parent.master, font=font_specs)
parent.master.config(menu=menubar)
#This section of code creates all the options for our first menubar:
file_dropdown = tk.Menu(menubar, font=font_specs,tearoff=0,bg="... | "notepad" or apple's "TextEdit"
#Disclaimer, this program was created in part by following a tutorial posted by pymike00 on youtube, credit for the basic outline of this program goes to him and his PyText Editor!
import tkinter as tk
from tkinter import filedialog
class Menubar:
| 64 | 64 | 211 | 4 | 59 | wildflower-42/Quill | Quill.py | Python | Menubar | Menubar | 5 | 20 | 5 | 5 | 0342d0015d762330f56e10f4894f4cd47dc9da76 | bigcode/the-stack | train |
cf46a0f854f9c7116f9ad801 | train | class | @pulumi.input_type
class ProximityPlacementGroupArgs:
def __init__(__self__, *,
resource_group_name: pulumi.Input[str],
colocation_status: Optional[pulumi.Input['InstanceViewStatusArgs']] = None,
location: Optional[pulumi.Input[str]] = None,
proxim... | @pulumi.input_type
class ProximityPlacementGroupArgs:
| def __init__(__self__, *,
resource_group_name: pulumi.Input[str],
colocation_status: Optional[pulumi.Input['InstanceViewStatusArgs']] = None,
location: Optional[pulumi.Input[str]] = None,
proximity_placement_group_name: Optional[pulumi.Input[str]] ... | # coding=utf-8
# *** WARNING: this file was generated by the Pulumi SDK Generator. ***
# *** Do not edit by hand unless you're certain you know what you are doing! ***
import warnings
import pulumi
import pulumi.runtime
from typing import Any, Mapping, Optional, Sequence, Union, overload
from ... import _utilities
fro... | 122 | 256 | 1,102 | 13 | 109 | polivbr/pulumi-azure-native | sdk/python/pulumi_azure_native/compute/v20191201/proximity_placement_group.py | Python | ProximityPlacementGroupArgs | ProximityPlacementGroupArgs | 16 | 116 | 16 | 17 | c9ff18975958d627b257c21ed1550f40c5d255eb | bigcode/the-stack | train |
792632c984cf8d45b617e5e4 | train | class | class ProximityPlacementGroup(pulumi.CustomResource):
@overload
def __init__(__self__,
resource_name: str,
opts: Optional[pulumi.ResourceOptions] = None,
colocation_status: Optional[pulumi.Input[pulumi.InputType['InstanceViewStatusArgs']]] = None,
... | class ProximityPlacementGroup(pulumi.CustomResource):
@overload
| def __init__(__self__,
resource_name: str,
opts: Optional[pulumi.ResourceOptions] = None,
colocation_status: Optional[pulumi.Input[pulumi.InputType['InstanceViewStatusArgs']]] = None,
location: Optional[pulumi.Input[str]] = None,
p... | _placement_group_type(self) -> Optional[pulumi.Input[Union[str, 'ProximityPlacementGroupType']]]:
"""
Specifies the type of the proximity placement group. <br><br> Possible values are: <br><br> **Standard** : Co-locate resources within an Azure region or Availability Zone. <br><br> **Ultra** : For futur... | 256 | 256 | 2,433 | 16 | 240 | polivbr/pulumi-azure-native | sdk/python/pulumi_azure_native/compute/v20191201/proximity_placement_group.py | Python | ProximityPlacementGroup | ProximityPlacementGroup | 119 | 303 | 119 | 120 | baa8c8186131fa989799eb3281ef6a5433d57a35 | bigcode/the-stack | train |
a6ba086047121b5c8993ea77 | train | class | class HirschbergAlgorithm:
'''
Hirschberg’s algorithm uses Θ(m +n) space.
- Each recursive call uses Θ(m) space to compute f(·, n / 2) and g(·, n / 2).
- Only Θ(1) space needs to be maintained per recursive call.
- Number of recursive calls ≤ n. ▪
s
Pseudocode: https://en.wikipedia.org/wiki/... | class HirschbergAlgorithm:
| '''
Hirschberg’s algorithm uses Θ(m +n) space.
- Each recursive call uses Θ(m) space to compute f(·, n / 2) and g(·, n / 2).
- Only Θ(1) space needs to be maintained per recursive call.
- Number of recursive calls ≤ n. ▪
s
Pseudocode: https://en.wikipedia.org/wiki/Hirschberg's_algorithm
... | import numpy as np
from typing import Tuple
from NeedlemanWunschAlgorithm import NeedlemanWunschAlgorithm
from ScoringSystem import ScoringSystem
class HirschbergAlgorithm:
| 37 | 217 | 724 | 5 | 31 | micmarty/dna-sequence-analyzer | HirschbergAlgorithm.py | Python | HirschbergAlgorithm | HirschbergAlgorithm | 6 | 78 | 6 | 6 | 7dc390fd4313c481bf0c03ab6a57e8118a69ddbf | bigcode/the-stack | train |
441a5040ec6ccdac19e7f674 | train | function | @pytest.fixture(params=REQUEST_PARSERS)
def parser(loop, protocol, request):
"""Parser implementations"""
return request.param(protocol, loop,
max_line_size=8190,
max_headers=32768,
max_field_size=8190)
| @pytest.fixture(params=REQUEST_PARSERS)
def parser(loop, protocol, request):
| """Parser implementations"""
return request.param(protocol, loop,
max_line_size=8190,
max_headers=32768,
max_field_size=8190)
| REQUEST_PARSERS.append(HttpRequestParserC)
RESPONSE_PARSERS.append(HttpResponseParserC)
except ImportError: # pragma: no cover
pass
@pytest.fixture
def protocol():
return mock.Mock()
@pytest.fixture(params=REQUEST_PARSERS)
def parser(loop, protocol, request):
| 64 | 64 | 53 | 17 | 47 | Semnodime/aiohttp | tests/test_http_parser.py | Python | parser | parser | 38 | 44 | 38 | 39 | e45649d980fab18f48aaef43aca207bd5f709e6e | bigcode/the-stack | train |
3143955b976f9e271f67995a | train | function | def test_http_request_chunked_payload(parser):
text = (b'GET /test HTTP/1.1\r\n'
b'transfer-encoding: chunked\r\n\r\n')
msg, payload = parser.feed_data(text)[0][0]
assert msg.chunked
assert not payload.is_eof()
assert isinstance(payload, streams.StreamReader)
parser.feed_data(b'4\r... | def test_http_request_chunked_payload(parser):
| text = (b'GET /test HTTP/1.1\r\n'
b'transfer-encoding: chunked\r\n\r\n')
msg, payload = parser.feed_data(text)[0][0]
assert msg.chunked
assert not payload.is_eof()
assert isinstance(payload, streams.StreamReader)
parser.feed_data(b'4\r\ndata\r\n4\r\nline\r\n0\r\n\r\n')
assert ... | 'HTTP/1.1 9999 test\r\n\r\n')
def test_http_response_parser_code_not_int(response):
with pytest.raises(http_exceptions.BadHttpMessage):
response.feed_data(b'HTTP/1.1 ttt test\r\n\r\n')
def test_http_request_chunked_payload(parser):
| 64 | 64 | 144 | 9 | 55 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_http_request_chunked_payload | test_http_request_chunked_payload | 648 | 661 | 648 | 648 | bb1ddb8229f88452a989228ec882909eec1ee147 | bigcode/the-stack | train |
861d3a9d3cf95d21f4de0c07 | train | function | def test_invalid_name(parser):
text = (b'GET /test HTTP/1.1\r\n'
b'test[]: line\r\n\r\n')
with pytest.raises(http_exceptions.BadHttpMessage):
parser.feed_data(text)
| def test_invalid_name(parser):
| text = (b'GET /test HTTP/1.1\r\n'
b'test[]: line\r\n\r\n')
with pytest.raises(http_exceptions.BadHttpMessage):
parser.feed_data(text)
| Message):
parser.feed_data(text)
def test_invalid_header(parser):
text = (b'GET /test HTTP/1.1\r\n'
b'test line\r\n\r\n')
with pytest.raises(http_exceptions.BadHttpMessage):
parser.feed_data(text)
def test_invalid_name(parser):
| 64 | 64 | 52 | 6 | 58 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_invalid_name | test_invalid_name | 359 | 364 | 359 | 359 | ef49c89bfd4464d0b2c525315fb4a962773c6703 | bigcode/the-stack | train |
168d97d69727b61bf325dd6a | train | function | def test_http_request_parser(parser):
text = b'GET /path HTTP/1.1\r\n\r\n'
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert msg.method == 'GET'
assert msg.path == '/path'
assert msg.version == (1, 1)
assert msg.headers == CIMultiDict()
assert msg.raw_headers ... | def test_http_request_parser(parser):
| text = b'GET /path HTTP/1.1\r\n\r\n'
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert msg.method == 'GET'
assert msg.path == '/path'
assert msg.version == (1, 1)
assert msg.headers == CIMultiDict()
assert msg.raw_headers == ()
assert not msg.should_close
... | assert msg.raw_headers == ((b'data', b'test ' + value),)
assert not msg.should_close
assert msg.compression is None
assert not msg.upgrade
assert not msg.chunked
assert msg.url == URL('/test')
def test_http_request_parser(parser):
| 64 | 64 | 127 | 7 | 57 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_http_request_parser | test_http_request_parser | 458 | 472 | 458 | 458 | 9bd50d8fda71201056e5780bfa4c621ef97cbdbb | bigcode/the-stack | train |
12e0f8f1b06e8bcf45fee4c0 | train | function | def test_parse_headers(parser):
text = b'''GET /test HTTP/1.1\r
test: line\r
continue\r
test2: data\r
\r
'''
messages, upgrade, tail = parser.feed_data(text)
assert len(messages) == 1
msg = messages[0][0]
assert list(msg.headers.items()) == [('test', 'line continue'),
... | def test_parse_headers(parser):
| text = b'''GET /test HTTP/1.1\r
test: line\r
continue\r
test2: data\r
\r
'''
messages, upgrade, tail = parser.feed_data(text)
assert len(messages) == 1
msg = messages[0][0]
assert list(msg.headers.items()) == [('test', 'line continue'),
('test2', 'data')]
... | max_line_size=8190,
max_headers=32768,
max_field_size=8190)
@pytest.fixture(params=RESPONSE_PARSERS)
def response_cls(request):
"""Parser implementations"""
return request.param
@pytest.fixture
def stream():
return mock.Mock()
def test_parse_headers(par... | 64 | 64 | 140 | 6 | 58 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_parse_headers | test_parse_headers | 73 | 90 | 73 | 73 | 7459f41c45af420663e6998436924bd877498071 | bigcode/the-stack | train |
ce3df176b6a927fbf2a92f48 | train | function | @pytest.mark.parametrize('size', [40965, 8191])
def test_http_request_max_status_line(parser, size):
path = b't' * (size - 5)
match = ("400, message='Got more than 8190 bytes \\({}\\) when reading"
.format(size))
with pytest.raises(http_exceptions.LineTooLong, match=match):
parser.feed_... | @pytest.mark.parametrize('size', [40965, 8191])
def test_http_request_max_status_line(parser, size):
| path = b't' * (size - 5)
match = ("400, message='Got more than 8190 bytes \\({}\\) when reading"
.format(size))
with pytest.raises(http_exceptions.LineTooLong, match=match):
parser.feed_data(
b'GET /path' + path + b' HTTP/1.1\r\n\r\n')
| \n')
def test_http_request_parser_bad_version(parser):
with pytest.raises(http_exceptions.BadHttpMessage):
parser.feed_data(b'GET //get HT/11\r\n\r\n')
@pytest.mark.parametrize('size', [40965, 8191])
def test_http_request_max_status_line(parser, size):
| 64 | 64 | 107 | 25 | 39 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_http_request_max_status_line | test_http_request_max_status_line | 551 | 558 | 551 | 552 | 6c32bce85fc77df09ef0ff01ebffea48e14d03d2 | bigcode/the-stack | train |
3988d05990e0a2ddcd2f03ac | train | function | def test_http_request_parser_two_slashes(parser):
text = b'GET //path HTTP/1.1\r\n\r\n'
msg = parser.feed_data(text)[0][0][0]
assert msg.method == 'GET'
assert msg.path == '//path'
assert msg.version == (1, 1)
assert not msg.should_close
assert msg.compression is None
assert not msg.upg... | def test_http_request_parser_two_slashes(parser):
| text = b'GET //path HTTP/1.1\r\n\r\n'
msg = parser.feed_data(text)[0][0][0]
assert msg.method == 'GET'
assert msg.path == '//path'
assert msg.version == (1, 1)
assert not msg.should_close
assert msg.compression is None
assert not msg.upgrade
assert not msg.chunked
| ((b'x-test', 'тест'.encode('cp1251')),)
assert not msg.should_close
assert msg.compression is None
assert not msg.upgrade
assert not msg.chunked
assert msg.url == URL('/path')
def test_http_request_parser_two_slashes(parser):
| 64 | 64 | 98 | 10 | 54 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_http_request_parser_two_slashes | test_http_request_parser_two_slashes | 528 | 538 | 528 | 528 | 0d531061a0b73cfbe9ab3fc8d673a889a2053ad6 | bigcode/the-stack | train |
df5befbb735b2fdb4c85f4b2 | train | function | def test_conn_other_1_0(parser):
text = (b'GET /test HTTP/1.0\r\n'
b'connection: test\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert msg.should_close
| def test_conn_other_1_0(parser):
| text = (b'GET /test HTTP/1.0\r\n'
b'connection: test\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert msg.should_close
| b'GET /test HTTP/1.1\r\n'
b'connection: keep-alive\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert not msg.should_close
def test_conn_other_1_0(parser):
| 64 | 64 | 65 | 10 | 53 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_conn_other_1_0 | test_conn_other_1_0 | 241 | 246 | 241 | 241 | 2ed834c84007fa24c1c57eb734059f766754d938 | bigcode/the-stack | train |
3f36bd0454c2593c3f3732b6 | train | function | def test_parse_chunked_payload_chunk_extension(parser):
text = (b'GET /test HTTP/1.1\r\n'
b'transfer-encoding: chunked\r\n\r\n')
msg, payload = parser.feed_data(text)[0][0]
parser.feed_data(
b'4;test\r\ndata\r\n4\r\nline\r\n0\r\ntest: test\r\n\r\n')
assert b'dataline' == b''.join(d... | def test_parse_chunked_payload_chunk_extension(parser):
| text = (b'GET /test HTTP/1.1\r\n'
b'transfer-encoding: chunked\r\n\r\n')
msg, payload = parser.feed_data(text)[0][0]
parser.feed_data(
b'4;test\r\ndata\r\n4\r\nline\r\n0\r\ntest: test\r\n\r\n')
assert b'dataline' == b''.join(d for d in payload._buffer)
assert [4, 8] == payload.... | _eof()
parser.feed_data(b'\r\n')
assert b'dataline' == b''.join(d for d in payload._buffer)
assert [4, 8] == payload._http_chunk_splits
assert payload.is_eof()
def test_parse_chunked_payload_chunk_extension(parser):
| 64 | 64 | 132 | 10 | 54 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_parse_chunked_payload_chunk_extension | test_parse_chunked_payload_chunk_extension | 709 | 719 | 709 | 709 | 064740f2daa7ff7149a03a5fde59f5827b7daa86 | bigcode/the-stack | train |
666ce0dbfbadc8fe7674cce0 | train | function | def test_conn_keep_alive_1_1(parser):
text = (b'GET /test HTTP/1.1\r\n'
b'connection: keep-alive\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert not msg.should_close
| def test_conn_keep_alive_1_1(parser):
| text = (b'GET /test HTTP/1.1\r\n'
b'connection: keep-alive\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert not msg.should_close
| 'GET /test HTTP/1.0\r\n'
b'connection: keep-alive\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert not msg.should_close
def test_conn_keep_alive_1_1(parser):
| 64 | 64 | 69 | 11 | 52 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_conn_keep_alive_1_1 | test_conn_keep_alive_1_1 | 233 | 238 | 233 | 233 | 2c215ce7aac65602b0b83a3dc2eb2b7432f3fbdf | bigcode/the-stack | train |
3f3fbe3ddc1713f035b38f80 | train | function | def test_conn_other_1_1(parser):
text = (b'GET /test HTTP/1.1\r\n'
b'connection: test\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert not msg.should_close
| def test_conn_other_1_1(parser):
| text = (b'GET /test HTTP/1.1\r\n'
b'connection: test\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert not msg.should_close
| text = (b'GET /test HTTP/1.0\r\n'
b'connection: test\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert msg.should_close
def test_conn_other_1_1(parser):
| 64 | 64 | 66 | 10 | 53 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_conn_other_1_1 | test_conn_other_1_1 | 249 | 254 | 249 | 249 | 2bb1550553ead44278a540a255510981477116f8 | bigcode/the-stack | train |
83118731a95ae94d70ce3afd | train | function | def _test_parse_no_length_or_te_on_post(loop, protocol, request_cls):
parser = request_cls(protocol, loop, readall=True)
text = b'POST /test HTTP/1.1\r\n\r\n'
msg, payload = parser.feed_data(text)[0][0]
assert payload.is_eof()
| def _test_parse_no_length_or_te_on_post(loop, protocol, request_cls):
| parser = request_cls(protocol, loop, readall=True)
text = b'POST /test HTTP/1.1\r\n\r\n'
msg, payload = parser.feed_data(text)[0][0]
assert payload.is_eof()
| \r\n\r\n')
assert b'dataline' == b''.join(d for d in payload._buffer)
assert [4, 8] == payload._http_chunk_splits
assert payload.is_eof()
def _test_parse_no_length_or_te_on_post(loop, protocol, request_cls):
| 64 | 64 | 69 | 17 | 47 | Semnodime/aiohttp | tests/test_http_parser.py | Python | _test_parse_no_length_or_te_on_post | _test_parse_no_length_or_te_on_post | 722 | 727 | 722 | 722 | 55c727b11e8694eb4987369c128b4dda5f70e721 | bigcode/the-stack | train |
321333c69ba79c619fa72224 | train | function | def test_url_parse_non_strict_mode(parser):
payload = 'GET /test/тест HTTP/1.1\r\n\r\n'.encode('utf-8')
messages, upgrade, tail = parser.feed_data(payload)
assert len(messages) == 1
msg, payload = messages[0]
assert msg.method == 'GET'
assert msg.path == '/test/тест'
assert msg.version == ... | def test_url_parse_non_strict_mode(parser):
| payload = 'GET /test/тест HTTP/1.1\r\n\r\n'.encode('utf-8')
messages, upgrade, tail = parser.feed_data(payload)
assert len(messages) == 1
msg, payload = messages[0]
assert msg.method == 'GET'
assert msg.path == '/test/тест'
assert msg.version == (1, 1)
assert payload.is_eof()
| \n')
assert len(messages) == 1
msg, payload = messages[0]
assert msg.method == 'GET'
assert msg.path == '/test'
assert msg.version == (1, 1)
assert payload.is_eof()
def test_url_parse_non_strict_mode(parser):
| 64 | 64 | 103 | 10 | 54 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_url_parse_non_strict_mode | test_url_parse_non_strict_mode | 773 | 783 | 773 | 773 | a7805ee7e3c665af50a480c8e0ef08e92ced060c | bigcode/the-stack | train |
143b04c7f3d894aecee30e6d | train | function | @pytest.fixture(params=REQUEST_PARSERS)
def request_cls(request):
"""Request Parser class"""
return request.param
| @pytest.fixture(params=REQUEST_PARSERS)
def request_cls(request):
| """Request Parser class"""
return request.param
| =REQUEST_PARSERS)
def parser(loop, protocol, request):
"""Parser implementations"""
return request.param(protocol, loop,
max_line_size=8190,
max_headers=32768,
max_field_size=8190)
@pytest.fixture(params=REQUEST_PARSERS)
def request_cls(... | 64 | 64 | 25 | 14 | 50 | Semnodime/aiohttp | tests/test_http_parser.py | Python | request_cls | request_cls | 47 | 50 | 47 | 48 | 9ebf8d00748187d23c4bad9c7dd24205ce557143 | bigcode/the-stack | train |
faf6f57f288165b97845cc3f | train | function | def test_http_response_parser_code_above_999(response):
with pytest.raises(http_exceptions.BadHttpMessage):
response.feed_data(b'HTTP/1.1 9999 test\r\n\r\n')
| def test_http_response_parser_code_above_999(response):
| with pytest.raises(http_exceptions.BadHttpMessage):
response.feed_data(b'HTTP/1.1 9999 test\r\n\r\n')
| 1\r\n\r\n')
def test_http_response_parser_code_under_100(response):
msg = response.feed_data(b'HTTP/1.1 99 test\r\n\r\n')[0][0][0]
assert msg.code == 99
def test_http_response_parser_code_above_999(response):
| 64 | 64 | 43 | 12 | 51 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_http_response_parser_code_above_999 | test_http_response_parser_code_above_999 | 638 | 640 | 638 | 638 | 48d97b4a4912491e4fdcdde41f6a69030bba8faa | bigcode/the-stack | train |
a2bbc103b486875d7178f76a | train | function | def test_headers_connect(parser):
text = (b'CONNECT www.google.com HTTP/1.1\r\n'
b'content-length: 0\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg, payload = messages[0]
assert upgrade
assert isinstance(payload, streams.StreamReader)
| def test_headers_connect(parser):
| text = (b'CONNECT www.google.com HTTP/1.1\r\n'
b'content-length: 0\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg, payload = messages[0]
assert upgrade
assert isinstance(payload, streams.StreamReader)
| text = (b'GET /test HTTP/1.1\r\n'
b'content-encoding: compress\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert msg.compression is None
def test_headers_connect(parser):
| 64 | 64 | 71 | 6 | 57 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_headers_connect | test_headers_connect | 319 | 325 | 319 | 319 | 4df3414645d6c1b04e38ad8dd36cf1128ee94920 | bigcode/the-stack | train |
fcd58789ae8ff1e63603ec5b | train | function | def test_http_response_parser_utf8(response):
text = 'HTTP/1.1 200 Ok\r\nx-test:тест\r\n\r\n'.encode('utf-8')
messages, upgraded, tail = response.feed_data(text)
assert len(messages) == 1
msg = messages[0][0]
assert msg.version == (1, 1)
assert msg.code == 200
assert msg.reason == 'Ok'
... | def test_http_response_parser_utf8(response):
| text = 'HTTP/1.1 200 Ok\r\nx-test:тест\r\n\r\n'.encode('utf-8')
messages, upgraded, tail = response.feed_data(text)
assert len(messages) == 1
msg = messages[0][0]
assert msg.version == (1, 1)
assert msg.code == 200
assert msg.reason == 'Ok'
assert msg.headers == CIMultiDict([('X-TEST',... | .headers == CIMultiDict()
assert msg.raw_headers == ()
assert not msg.should_close
assert msg.compression is None
assert not msg.upgrade
assert not msg.chunked
assert msg.url == URL('/path' + path.decode())
def test_http_response_parser_utf8(response):
| 64 | 64 | 147 | 9 | 55 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_http_response_parser_utf8 | test_http_response_parser_utf8 | 579 | 592 | 579 | 579 | 3bf12d8496f674c12e3d2ac6b083c4cd8f50604e | bigcode/the-stack | train |
e46cd1315e1c88d9cdc23df5 | train | function | @pytest.fixture(params=RESPONSE_PARSERS)
def response_cls(request):
"""Parser implementations"""
return request.param
| @pytest.fixture(params=RESPONSE_PARSERS)
def response_cls(request):
| """Parser implementations"""
return request.param
| SPONSE_PARSERS)
def response(loop, protocol, request):
"""Parser implementations"""
return request.param(protocol, loop,
max_line_size=8190,
max_headers=32768,
max_field_size=8190)
@pytest.fixture(params=RESPONSE_PARSERS)
def response_cl... | 64 | 64 | 25 | 15 | 49 | Semnodime/aiohttp | tests/test_http_parser.py | Python | response_cls | response_cls | 62 | 65 | 62 | 63 | 918e6ba957d6ebfedf8a4b4eb80feaeea73532da | bigcode/the-stack | train |
133dc8334546af665b6e015f | train | function | def test_partial_url(parser):
messages, upgrade, tail = parser.feed_data(b'GET /te')
assert len(messages) == 0
messages, upgrade, tail = parser.feed_data(b'st HTTP/1.1\r\n\r\n')
assert len(messages) == 1
msg, payload = messages[0]
assert msg.method == 'GET'
assert msg.path == '/test'
a... | def test_partial_url(parser):
| messages, upgrade, tail = parser.feed_data(b'GET /te')
assert len(messages) == 0
messages, upgrade, tail = parser.feed_data(b'st HTTP/1.1\r\n\r\n')
assert len(messages) == 1
msg, payload = messages[0]
assert msg.method == 'GET'
assert msg.path == '/test'
assert msg.version == (1, 1)
... | == b''.join(d for d in payload._buffer)
def test_parse_no_length_payload(parser):
text = b'PUT / HTTP/1.1\r\n\r\n'
msg, payload = parser.feed_data(text)[0][0]
assert payload.is_eof()
def test_partial_url(parser):
| 64 | 64 | 106 | 6 | 58 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_partial_url | test_partial_url | 759 | 770 | 759 | 759 | 28ef8a1dc7cd4cc7a79f95d2672967827e43732d | bigcode/the-stack | train |
379ca0ed781de7336db9c7be | train | function | def test_headers_split_field(parser):
text1 = b'GET /test HTTP/1.1\r\n'
text2 = b't'
text3 = b'es'
text4 = b't: value\r\n\r\n'
messages, upgrade, tail = parser.feed_data(text1)
messages, upgrade, tail = parser.feed_data(text2)
messages, upgrade, tail = parser.feed_data(text3)
assert len... | def test_headers_split_field(parser):
| text1 = b'GET /test HTTP/1.1\r\n'
text2 = b't'
text3 = b'es'
text4 = b't: value\r\n\r\n'
messages, upgrade, tail = parser.feed_data(text1)
messages, upgrade, tail = parser.feed_data(text2)
messages, upgrade, tail = parser.feed_data(text3)
assert len(messages) == 0
messages, upgrade,... | ][0]
assert list(msg.headers.items()) == [('test', 'line continue')]
assert msg.raw_headers == ((b'test', b'line continue'),)
assert not msg.should_close
assert msg.compression is None
assert not msg.upgrade
def test_headers_split_field(parser):
| 64 | 64 | 181 | 7 | 56 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_headers_split_field | test_headers_split_field | 157 | 175 | 157 | 157 | 8605e622bf24416d66ea7e98f40c9da7d9b6262f | bigcode/the-stack | train |
640833f81f70b9203895473f | train | function | def test_headers_content_length_err_2(parser):
text = (b'GET /test HTTP/1.1\r\n'
b'content-length: -1\r\n\r\n')
with pytest.raises(http_exceptions.BadHttpMessage):
parser.feed_data(text)
| def test_headers_content_length_err_2(parser):
| text = (b'GET /test HTTP/1.1\r\n'
b'content-length: -1\r\n\r\n')
with pytest.raises(http_exceptions.BadHttpMessage):
parser.feed_data(text)
| _headers_content_length_err_1(parser):
text = (b'GET /test HTTP/1.1\r\n'
b'content-length: line\r\n\r\n')
with pytest.raises(http_exceptions.BadHttpMessage):
parser.feed_data(text)
def test_headers_content_length_err_2(parser):
| 64 | 64 | 57 | 10 | 54 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_headers_content_length_err_2 | test_headers_content_length_err_2 | 344 | 349 | 344 | 344 | 355cfc4c5538c83ed82fc2dea0cff13fda048542 | bigcode/the-stack | train |
230b715571c7c586a4a4ac15 | train | function | def test_compression_deflate(parser):
text = (b'GET /test HTTP/1.1\r\n'
b'content-encoding: deflate\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert msg.compression == 'deflate'
| def test_compression_deflate(parser):
| text = (b'GET /test HTTP/1.1\r\n'
b'content-encoding: deflate\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert msg.compression == 'deflate'
| (b'GET /test HTTP/1.1\r\n'
b'content-encoding: \r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert msg.compression is None
def test_compression_deflate(parser):
| 64 | 64 | 70 | 8 | 55 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_compression_deflate | test_compression_deflate | 286 | 291 | 286 | 286 | 71602d9a4bdd00ca2e5627a2b83f256cdc40fe80 | bigcode/the-stack | train |
9376b8fdf26a64552100f042 | train | function | @pytest.fixture(params=RESPONSE_PARSERS)
def response(loop, protocol, request):
"""Parser implementations"""
return request.param(protocol, loop,
max_line_size=8190,
max_headers=32768,
max_field_size=8190)
| @pytest.fixture(params=RESPONSE_PARSERS)
def response(loop, protocol, request):
| """Parser implementations"""
return request.param(protocol, loop,
max_line_size=8190,
max_headers=32768,
max_field_size=8190)
| _line_size=8190,
max_headers=32768,
max_field_size=8190)
@pytest.fixture(params=REQUEST_PARSERS)
def request_cls(request):
"""Request Parser class"""
return request.param
@pytest.fixture(params=RESPONSE_PARSERS)
def response(loop, protocol, request):
| 64 | 64 | 54 | 18 | 45 | Semnodime/aiohttp | tests/test_http_parser.py | Python | response | response | 53 | 59 | 53 | 54 | 09ff6b31fa1f49ac373c3836d5010b738e260a47 | bigcode/the-stack | train |
c95e17d085e1cba4cdd24390 | train | function | def test_max_header_value_size_under_limit(parser):
value = b'A' * 8190
text = (b'GET /test HTTP/1.1\r\n'
b'data:' + value + b'\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert msg.method == 'GET'
assert msg.path == '/test'
assert msg.versio... | def test_max_header_value_size_under_limit(parser):
| value = b'A' * 8190
text = (b'GET /test HTTP/1.1\r\n'
b'data:' + value + b'\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert msg.method == 'GET'
assert msg.path == '/test'
assert msg.version == (1, 1)
assert msg.headers == CIMultiDict({'... | '\r\n\r\n')
match = ("400, message='Got more than 8190 bytes \\({}\\) when reading"
.format(size))
with pytest.raises(http_exceptions.LineTooLong, match=match):
parser.feed_data(text)
def test_max_header_value_size_under_limit(parser):
| 64 | 64 | 168 | 10 | 54 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_max_header_value_size_under_limit | test_max_header_value_size_under_limit | 408 | 424 | 408 | 408 | 3107830460b601704c359dc9e36db83c89165e28 | bigcode/the-stack | train |
decd311998ca74a5110bd4cc | train | function | def test_compression_unknown(parser):
text = (b'GET /test HTTP/1.1\r\n'
b'content-encoding: compress\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert msg.compression is None
| def test_compression_unknown(parser):
| text = (b'GET /test HTTP/1.1\r\n'
b'content-encoding: compress\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert msg.compression is None
| (b'GET /test HTTP/1.1\r\n'
b'content-encoding: br\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert msg.compression == 'br'
def test_compression_unknown(parser):
| 64 | 64 | 66 | 7 | 57 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_compression_unknown | test_compression_unknown | 311 | 316 | 311 | 311 | c1b801dfb72c5bd7b54288e941b8be24dfa5c431 | bigcode/the-stack | train |
937fbb26cd80f5f06b619ccd | train | function | def test_max_header_field_size_under_limit(parser):
name = b't' * 8190
text = (b'GET /test HTTP/1.1\r\n' + name + b':data\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert msg.method == 'GET'
assert msg.path == '/test'
assert msg.version == (1, 1)
as... | def test_max_header_field_size_under_limit(parser):
| name = b't' * 8190
text = (b'GET /test HTTP/1.1\r\n' + name + b':data\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert msg.method == 'GET'
assert msg.path == '/test'
assert msg.version == (1, 1)
assert msg.headers == CIMultiDict({name.decode(): 'dat... | data\r\n\r\n')
match = ("400, message='Got more than 8190 bytes \\({}\\) when reading"
.format(size))
with pytest.raises(http_exceptions.LineTooLong, match=match):
parser.feed_data(text)
def test_max_header_field_size_under_limit(parser):
| 64 | 64 | 164 | 10 | 54 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_max_header_field_size_under_limit | test_max_header_field_size_under_limit | 378 | 393 | 378 | 378 | cd36c9aa42112eebdfbb6e1e41d905b92adc521b | bigcode/the-stack | train |
e75fa7ecb6b104bd0f09bac8 | train | function | def test_compression_gzip(parser):
text = (b'GET /test HTTP/1.1\r\n'
b'content-encoding: gzip\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert msg.compression == 'gzip'
| def test_compression_gzip(parser):
| text = (b'GET /test HTTP/1.1\r\n'
b'content-encoding: gzip\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert msg.compression == 'gzip'
| GET /test HTTP/1.1\r\n'
b'content-encoding: deflate\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert msg.compression == 'deflate'
def test_compression_gzip(parser):
| 64 | 64 | 68 | 8 | 56 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_compression_gzip | test_compression_gzip | 294 | 299 | 294 | 294 | 7bd804b45a419b0562541f4396316bb278cafa97 | bigcode/the-stack | train |
9e3972935938f82000fe2b6c | train | function | def test_http_response_parser_no_reason(response):
msg = response.feed_data(b'HTTP/1.1 200\r\n\r\n')[0][0][0]
assert msg.version == (1, 1)
assert msg.code == 200
assert not msg.reason
| def test_http_response_parser_no_reason(response):
| msg = response.feed_data(b'HTTP/1.1 200\r\n\r\n')[0][0][0]
assert msg.version == (1, 1)
assert msg.code == 200
assert not msg.reason
| 1)
assert msg.code == 200
assert msg.reason == reason.decode()
def test_http_response_parser_bad_version(response):
with pytest.raises(http_exceptions.BadHttpMessage):
response.feed_data(b'HT/11 200 Ok\r\n\r\n')
def test_http_response_parser_no_reason(response):
| 64 | 64 | 60 | 9 | 55 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_http_response_parser_no_reason | test_http_response_parser_no_reason | 620 | 625 | 620 | 620 | ff0a69294f5e805420ad9850a095bdb844eb0603 | bigcode/the-stack | train |
8ce6e2988203ab0be147c441 | train | function | def test_parse(parser):
text = b'GET /test HTTP/1.1\r\n\r\n'
messages, upgrade, tail = parser.feed_data(text)
assert len(messages) == 1
msg, _ = messages[0]
assert msg.compression is None
assert not msg.upgrade
assert msg.method == 'GET'
assert msg.path == '/test'
assert msg.version ... | def test_parse(parser):
| text = b'GET /test HTTP/1.1\r\n\r\n'
messages, upgrade, tail = parser.feed_data(text)
assert len(messages) == 1
msg, _ = messages[0]
assert msg.compression is None
assert not msg.upgrade
assert msg.method == 'GET'
assert msg.path == '/test'
assert msg.version == (1, 1)
| continue'),
('test2', 'data')]
assert msg.raw_headers == ((b'test', b'line continue'),
(b'test2', b'data'))
assert not msg.should_close
assert msg.compression is None
assert not msg.upgrade
def test_parse(parser):
| 64 | 64 | 95 | 5 | 58 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_parse | test_parse | 93 | 102 | 93 | 93 | c627d93be7ef3b0082d3df105bf8f47fb40275ea | bigcode/the-stack | train |
eecf2fd1f79dffc5f8ad8057 | train | function | def test_request_chunked(parser):
text = (b'GET /test HTTP/1.1\r\n'
b'transfer-encoding: chunked\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg, payload = messages[0]
assert msg.chunked
assert not upgrade
assert isinstance(payload, streams.StreamReader)
| def test_request_chunked(parser):
| text = (b'GET /test HTTP/1.1\r\n'
b'transfer-encoding: chunked\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg, payload = messages[0]
assert msg.chunked
assert not upgrade
assert isinstance(payload, streams.StreamReader)
| ):
text = (b'GET /test HTTP/1.1\r\n'
b'connection: test\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert not msg.should_close
def test_request_chunked(parser):
| 64 | 64 | 80 | 7 | 56 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_request_chunked | test_request_chunked | 257 | 264 | 257 | 257 | 1a57afbabe9843c56827fdb1a3643e4d95f2f50b | bigcode/the-stack | train |
be7b8ca127e1e9d461bdc7e5 | train | function | def test_parse_payload_response_without_body(loop, protocol, response_cls):
parser = response_cls(protocol, loop, response_with_body=False)
text = (b'HTTP/1.1 200 Ok\r\n'
b'content-length: 10\r\n\r\n')
msg, payload = parser.feed_data(text)[0][0]
assert payload.is_eof()
| def test_parse_payload_response_without_body(loop, protocol, response_cls):
| parser = response_cls(protocol, loop, response_with_body=False)
text = (b'HTTP/1.1 200 Ok\r\n'
b'content-length: 10\r\n\r\n')
msg, payload = parser.feed_data(text)[0][0]
assert payload.is_eof()
| = request_cls(protocol, loop, readall=True)
text = b'POST /test HTTP/1.1\r\n\r\n'
msg, payload = parser.feed_data(text)[0][0]
assert payload.is_eof()
def test_parse_payload_response_without_body(loop, protocol, response_cls):
| 64 | 64 | 79 | 14 | 50 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_parse_payload_response_without_body | test_parse_payload_response_without_body | 730 | 736 | 730 | 730 | 51739ead1c38815ce3f0f950edc3a312c028b3a2 | bigcode/the-stack | train |
85867e614a318b4ae5b48477 | train | function | def test_http_request_parser_non_utf8(parser):
text = 'GET /path HTTP/1.1\r\nx-test:тест\r\n\r\n'.encode('cp1251')
msg = parser.feed_data(text)[0][0][0]
assert msg.method == 'GET'
assert msg.path == '/path'
assert msg.version == (1, 1)
assert msg.headers == CIMultiDict([('X-TEST', 'тест'.encode... | def test_http_request_parser_non_utf8(parser):
| text = 'GET /path HTTP/1.1\r\nx-test:тест\r\n\r\n'.encode('cp1251')
msg = parser.feed_data(text)[0][0][0]
assert msg.method == 'GET'
assert msg.path == '/path'
assert msg.version == (1, 1)
assert msg.headers == CIMultiDict([('X-TEST', 'тест'.encode('cp1251')
... | ((b'x-test', 'тест'.encode('utf-8')),)
assert not msg.should_close
assert msg.compression is None
assert not msg.upgrade
assert not msg.chunked
assert msg.url == URL('/path')
def test_http_request_parser_non_utf8(parser):
| 64 | 64 | 178 | 10 | 54 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_http_request_parser_non_utf8 | test_http_request_parser_non_utf8 | 511 | 525 | 511 | 511 | e814cee04f9f37beeb9631b0902ecc0a3cd67216 | bigcode/the-stack | train |
d505968b5585604b9c0bb3bb | train | function | def test_parse_length_payload(response):
text = (b'HTTP/1.1 200 Ok\r\n'
b'content-length: 4\r\n\r\n')
msg, payload = response.feed_data(text)[0][0]
assert not payload.is_eof()
response.feed_data(b'da')
response.feed_data(b't')
response.feed_data(b'aHT')
assert payload.is_eof()
... | def test_parse_length_payload(response):
| text = (b'HTTP/1.1 200 Ok\r\n'
b'content-length: 4\r\n\r\n')
msg, payload = response.feed_data(text)[0][0]
assert not payload.is_eof()
response.feed_data(b'da')
response.feed_data(b't')
response.feed_data(b'aHT')
assert payload.is_eof()
assert b'data' == b''.join(d for d in... | , response_with_body=False)
text = (b'HTTP/1.1 200 Ok\r\n'
b'content-length: 10\r\n\r\n')
msg, payload = parser.feed_data(text)[0][0]
assert payload.is_eof()
def test_parse_length_payload(response):
| 64 | 64 | 107 | 7 | 57 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_parse_length_payload | test_parse_length_payload | 739 | 750 | 739 | 739 | 78370cb3bf13ab5f41896bd240610f93b7046bf7 | bigcode/the-stack | train |
479f70cdb8afbea1d4976d40 | train | function | def test_http_response_parser_bad_version(response):
with pytest.raises(http_exceptions.BadHttpMessage):
response.feed_data(b'HT/11 200 Ok\r\n\r\n')
| def test_http_response_parser_bad_version(response):
| with pytest.raises(http_exceptions.BadHttpMessage):
response.feed_data(b'HT/11 200 Ok\r\n\r\n')
| 'HTTP/1.1 200 ' + reason + b'\r\n\r\n')
msg = messages[0][0]
assert msg.version == (1, 1)
assert msg.code == 200
assert msg.reason == reason.decode()
def test_http_response_parser_bad_version(response):
| 64 | 64 | 37 | 9 | 55 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_http_response_parser_bad_version | test_http_response_parser_bad_version | 615 | 617 | 615 | 615 | 8192001e48486952165b3aab5acb7a0a0b2393bb | bigcode/the-stack | train |
11188eb6c174d93979d54642 | train | function | def test_http_request_chunked_payload_and_next_message(parser):
text = (b'GET /test HTTP/1.1\r\n'
b'transfer-encoding: chunked\r\n\r\n')
msg, payload = parser.feed_data(text)[0][0]
messages, upgraded, tail = parser.feed_data(
b'4\r\ndata\r\n4\r\nline\r\n0\r\n\r\n'
b'POST /test2 ... | def test_http_request_chunked_payload_and_next_message(parser):
| text = (b'GET /test HTTP/1.1\r\n'
b'transfer-encoding: chunked\r\n\r\n')
msg, payload = parser.feed_data(text)[0][0]
messages, upgraded, tail = parser.feed_data(
b'4\r\ndata\r\n4\r\nline\r\n0\r\n\r\n'
b'POST /test2 HTTP/1.1\r\n'
b'transfer-encoding: chunked\r\n\r\n')
... | \nline\r\n0\r\n\r\n')
assert b'dataline' == b''.join(d for d in payload._buffer)
assert [4, 8] == payload._http_chunk_splits
assert payload.is_eof()
def test_http_request_chunked_payload_and_next_message(parser):
| 64 | 64 | 207 | 12 | 52 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_http_request_chunked_payload_and_next_message | test_http_request_chunked_payload_and_next_message | 664 | 683 | 664 | 664 | ecb12dfbdbc9c6e8462881125cab6c1574dac681 | bigcode/the-stack | train |
8b87a1642122cfb915bd039c | train | class | class TestDeflateBuffer:
def test_feed_data(self, stream):
buf = aiohttp.FlowControlDataQueue(stream)
dbuf = DeflateBuffer(buf, 'deflate')
dbuf.decompressor = mock.Mock()
dbuf.decompressor.decompress.return_value = b'line'
dbuf.feed_data(b'data', 4)
assert [b'line'... | class TestDeflateBuffer:
| def test_feed_data(self, stream):
buf = aiohttp.FlowControlDataQueue(stream)
dbuf = DeflateBuffer(buf, 'deflate')
dbuf.decompressor = mock.Mock()
dbuf.decompressor.decompress.return_value = b'line'
dbuf.feed_data(b'data', 4)
assert [b'line'] == list(d for d, _ in bu... | (d for d, _ in out._buffer)
assert out.is_eof()
def test_http_payload_parser_length_zero(self, stream):
out = aiohttp.FlowControlDataQueue(stream)
p = HttpPayloadParser(out, length=0)
assert p.done
assert out.is_eof()
@pytest.mark.skipif(brotli is None, reason="brotli i... | 181 | 181 | 606 | 6 | 175 | Semnodime/aiohttp | tests/test_http_parser.py | Python | TestDeflateBuffer | TestDeflateBuffer | 871 | 943 | 871 | 872 | 292926157bd3e1be6d83e30e8453d46709578c34 | bigcode/the-stack | train |
e31710d4fb799559082bad49 | train | function | def test_headers_content_length_err_1(parser):
text = (b'GET /test HTTP/1.1\r\n'
b'content-length: line\r\n\r\n')
with pytest.raises(http_exceptions.BadHttpMessage):
parser.feed_data(text)
| def test_headers_content_length_err_1(parser):
| text = (b'GET /test HTTP/1.1\r\n'
b'content-length: line\r\n\r\n')
with pytest.raises(http_exceptions.BadHttpMessage):
parser.feed_data(text)
| (parser):
text = (b'GET /test HTTP/1.1\r\n'
b'SEC-WEBSOCKET-KEY1: line\r\n\r\n')
with pytest.raises(http_exceptions.BadHttpMessage):
parser.feed_data(text)
def test_headers_content_length_err_1(parser):
| 64 | 64 | 56 | 10 | 54 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_headers_content_length_err_1 | test_headers_content_length_err_1 | 336 | 341 | 336 | 336 | cb40da221b0c0b6b49a4d97b3b14af3f142de8fa | bigcode/the-stack | train |
0bc857fc25df5f2b14ae0e17 | train | function | def test_parse_headers_multi(parser):
text = (b'GET /test HTTP/1.1\r\n'
b'Set-Cookie: c1=cookie1\r\n'
b'Set-Cookie: c2=cookie2\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
assert len(messages) == 1
msg = messages[0][0]
assert list(msg.headers.items()) == [('Se... | def test_parse_headers_multi(parser):
| text = (b'GET /test HTTP/1.1\r\n'
b'Set-Cookie: c1=cookie1\r\n'
b'Set-Cookie: c2=cookie2\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
assert len(messages) == 1
msg = messages[0][0]
assert list(msg.headers.items()) == [('Set-Cookie', 'c1=cookie1'),
... | messages[0][0]
assert list(msg.headers.items()) == [('test', 'value')]
assert msg.raw_headers == ((b'test', b'value'),)
assert not msg.should_close
assert msg.compression is None
assert not msg.upgrade
def test_parse_headers_multi(parser):
| 64 | 64 | 171 | 7 | 56 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_parse_headers_multi | test_parse_headers_multi | 178 | 192 | 178 | 178 | 266947ea5a40149c6bf60399e85427094cf0a5bf | bigcode/the-stack | train |
04276738ed5c1cf9ac6a798f | train | function | def test_http_request_max_status_line_under_limit(parser):
path = b't' * (8190 - 5)
messages, upgraded, tail = parser.feed_data(
b'GET /path' + path + b' HTTP/1.1\r\n\r\n')
msg = messages[0][0]
assert msg.method == 'GET'
assert msg.path == '/path' + path.decode()
assert msg.version == (... | def test_http_request_max_status_line_under_limit(parser):
| path = b't' * (8190 - 5)
messages, upgraded, tail = parser.feed_data(
b'GET /path' + path + b' HTTP/1.1\r\n\r\n')
msg = messages[0][0]
assert msg.method == 'GET'
assert msg.path == '/path' + path.decode()
assert msg.version == (1, 1)
assert msg.headers == CIMultiDict()
assert ms... | ({}\\) when reading"
.format(size))
with pytest.raises(http_exceptions.LineTooLong, match=match):
parser.feed_data(
b'GET /path' + path + b' HTTP/1.1\r\n\r\n')
def test_http_request_max_status_line_under_limit(parser):
| 64 | 64 | 156 | 11 | 53 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_http_request_max_status_line_under_limit | test_http_request_max_status_line_under_limit | 561 | 576 | 561 | 561 | 2262b933ddb110c93c514e6782516f90566bb5fc | bigcode/the-stack | train |
99a0b5a6a75f26f30982560a | train | function | @pytest.mark.parametrize('size', [40960, 8191])
def test_max_header_value_size(parser, size):
name = b't' * size
text = (b'GET /test HTTP/1.1\r\n'
b'data:' + name + b'\r\n\r\n')
match = ("400, message='Got more than 8190 bytes \\({}\\) when reading"
.format(size))
with pytest.r... | @pytest.mark.parametrize('size', [40960, 8191])
def test_max_header_value_size(parser, size):
| name = b't' * size
text = (b'GET /test HTTP/1.1\r\n'
b'data:' + name + b'\r\n\r\n')
match = ("400, message='Got more than 8190 bytes \\({}\\) when reading"
.format(size))
with pytest.raises(http_exceptions.LineTooLong, match=match):
parser.feed_data(text)
| '),)
assert not msg.should_close
assert msg.compression is None
assert not msg.upgrade
assert not msg.chunked
assert msg.url == URL('/test')
@pytest.mark.parametrize('size', [40960, 8191])
def test_max_header_value_size(parser, size):
| 64 | 64 | 113 | 24 | 40 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_max_header_value_size | test_max_header_value_size | 396 | 405 | 396 | 397 | 9b244e07be409767e76c6cae3a03a7b8c630bca4 | bigcode/the-stack | train |
0e2a4024ebe5808c18aa2e45 | train | function | def test_conn_close(parser):
text = (b'GET /test HTTP/1.1\r\n'
b'connection: close\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert msg.should_close
| def test_conn_close(parser):
| text = (b'GET /test HTTP/1.1\r\n'
b'connection: close\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert msg.should_close
| _close
def test_conn_default_1_1(parser):
text = b'GET /test HTTP/1.1\r\n\r\n'
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert not msg.should_close
def test_conn_close(parser):
| 64 | 64 | 61 | 6 | 57 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_conn_close | test_conn_close | 209 | 214 | 209 | 209 | 47d425bf6f2d8a78cfbf88b25a7c509f5b5d46df | bigcode/the-stack | train |
46dff519a89e1b75d21de429 | train | function | def test_invalid_header(parser):
text = (b'GET /test HTTP/1.1\r\n'
b'test line\r\n\r\n')
with pytest.raises(http_exceptions.BadHttpMessage):
parser.feed_data(text)
| def test_invalid_header(parser):
| text = (b'GET /test HTTP/1.1\r\n'
b'test line\r\n\r\n')
with pytest.raises(http_exceptions.BadHttpMessage):
parser.feed_data(text)
| )
def test_headers_content_length_err_2(parser):
text = (b'GET /test HTTP/1.1\r\n'
b'content-length: -1\r\n\r\n')
with pytest.raises(http_exceptions.BadHttpMessage):
parser.feed_data(text)
def test_invalid_header(parser):
| 64 | 64 | 50 | 6 | 58 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_invalid_header | test_invalid_header | 352 | 356 | 352 | 352 | a2fa0644ad4ddd4cca1a71c2b153a16f713072b9 | bigcode/the-stack | train |
71d0aec2ae298679100e156b | train | function | def test_conn_close_1_0(parser):
text = (b'GET /test HTTP/1.0\r\n'
b'connection: close\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert msg.should_close
| def test_conn_close_1_0(parser):
| text = (b'GET /test HTTP/1.0\r\n'
b'connection: close\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert msg.should_close
| text = (b'GET /test HTTP/1.1\r\n'
b'connection: close\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert msg.should_close
def test_conn_close_1_0(parser):
| 64 | 64 | 65 | 10 | 53 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_conn_close_1_0 | test_conn_close_1_0 | 217 | 222 | 217 | 217 | f38bb44c8384abfeae10b75f7cd27f6ff5b70b05 | bigcode/the-stack | train |
f169f8042b22d3d30d6f7390 | train | function | def test_parse_no_length_payload(parser):
text = b'PUT / HTTP/1.1\r\n\r\n'
msg, payload = parser.feed_data(text)[0][0]
assert payload.is_eof()
| def test_parse_no_length_payload(parser):
| text = b'PUT / HTTP/1.1\r\n\r\n'
msg, payload = parser.feed_data(text)[0][0]
assert payload.is_eof()
| assert not payload.is_eof()
response.feed_data(b'da')
response.feed_data(b't')
response.feed_data(b'aHT')
assert payload.is_eof()
assert b'data' == b''.join(d for d in payload._buffer)
def test_parse_no_length_payload(parser):
| 64 | 64 | 46 | 8 | 56 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_parse_no_length_payload | test_parse_no_length_payload | 753 | 756 | 753 | 753 | f4f771ef79e787cc5524c6eacd3ec9959201a8a5 | bigcode/the-stack | train |
73542a3eda0cdcce5e9656d9 | train | function | def test_http_response_parser_code_under_100(response):
msg = response.feed_data(b'HTTP/1.1 99 test\r\n\r\n')[0][0][0]
assert msg.code == 99
| def test_http_response_parser_code_under_100(response):
| msg = response.feed_data(b'HTTP/1.1 99 test\r\n\r\n')[0][0][0]
assert msg.code == 99
| 1, 1)
assert msg.code == 200
assert not msg.reason
def test_http_response_parser_bad(response):
with pytest.raises(http_exceptions.BadHttpMessage):
response.feed_data(b'HTT/1\r\n\r\n')
def test_http_response_parser_code_under_100(response):
| 64 | 64 | 46 | 11 | 53 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_http_response_parser_code_under_100 | test_http_response_parser_code_under_100 | 633 | 635 | 633 | 633 | d1a876190effd2cd1138d9f3cada8c07abdfcc33 | bigcode/the-stack | train |
6e632393e66791c009a386ce | train | function | def test_conn_upgrade(parser):
text = (b'GET /test HTTP/1.1\r\n'
b'connection: upgrade\r\n'
b'upgrade: websocket\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert not msg.should_close
assert msg.upgrade
assert upgrade
| def test_conn_upgrade(parser):
| text = (b'GET /test HTTP/1.1\r\n'
b'connection: upgrade\r\n'
b'upgrade: websocket\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert not msg.should_close
assert msg.upgrade
assert upgrade
| \n'
b'transfer-encoding: chunked\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg, payload = messages[0]
assert msg.chunked
assert not upgrade
assert isinstance(payload, streams.StreamReader)
def test_conn_upgrade(parser):
| 64 | 64 | 81 | 6 | 58 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_conn_upgrade | test_conn_upgrade | 267 | 275 | 267 | 267 | 0130d7090b6b3b4346b83d37624671eff2b2b53f | bigcode/the-stack | train |
bb9ead14e66cb520d4c23beb | train | class | class TestParsePayload:
def test_parse_eof_payload(self, stream):
out = aiohttp.FlowControlDataQueue(stream)
p = HttpPayloadParser(out, readall=True)
p.feed_data(b'data')
p.feed_eof()
assert out.is_eof()
assert [(bytearray(b'data'), 4)] == list(out._buffer)
def... | class TestParsePayload:
| def test_parse_eof_payload(self, stream):
out = aiohttp.FlowControlDataQueue(stream)
p = HttpPayloadParser(out, readall=True)
p.feed_data(b'data')
p.feed_eof()
assert out.is_eof()
assert [(bytearray(b'data'), 4)] == list(out._buffer)
def test_parse_no_body(self,... | payload.is_eof()
def test_partial_url(parser):
messages, upgrade, tail = parser.feed_data(b'GET /te')
assert len(messages) == 0
messages, upgrade, tail = parser.feed_data(b'st HTTP/1.1\r\n\r\n')
assert len(messages) == 1
msg, payload = messages[0]
assert msg.method == 'GET'
assert msg.p... | 219 | 219 | 731 | 5 | 214 | Semnodime/aiohttp | tests/test_http_parser.py | Python | TestParsePayload | TestParsePayload | 786 | 868 | 786 | 787 | 6112d788349ce0e06c118be8bffe44e4b60eb2ed | bigcode/the-stack | train |
25937e0a73407fb69afd3c5e | train | function | @pytest.fixture
def protocol():
return mock.Mock()
| @pytest.fixture
def protocol():
| return mock.Mock()
| ParserPy]
try:
from aiohttp.http_parser import HttpRequestParserC, HttpResponseParserC
REQUEST_PARSERS.append(HttpRequestParserC)
RESPONSE_PARSERS.append(HttpResponseParserC)
except ImportError: # pragma: no cover
pass
@pytest.fixture
def protocol():
| 64 | 64 | 11 | 6 | 57 | Semnodime/aiohttp | tests/test_http_parser.py | Python | protocol | protocol | 33 | 35 | 33 | 34 | 20fc5622550708fc763deb680057b403d492ff2d | bigcode/the-stack | train |
8a50e90f9d7b717e33b4b267 | train | function | def test_http_response_parser_bad(response):
with pytest.raises(http_exceptions.BadHttpMessage):
response.feed_data(b'HTT/1\r\n\r\n')
| def test_http_response_parser_bad(response):
| with pytest.raises(http_exceptions.BadHttpMessage):
response.feed_data(b'HTT/1\r\n\r\n')
| _parser_no_reason(response):
msg = response.feed_data(b'HTTP/1.1 200\r\n\r\n')[0][0][0]
assert msg.version == (1, 1)
assert msg.code == 200
assert not msg.reason
def test_http_response_parser_bad(response):
| 64 | 64 | 34 | 8 | 55 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_http_response_parser_bad | test_http_response_parser_bad | 628 | 630 | 628 | 628 | 366502719f36b3918bf7aa29fb03b449b5153480 | bigcode/the-stack | train |
828eeef2a1f8d5835e060f93 | train | function | def test_http_response_parser_status_line_under_limit(response):
reason = b'O' * 8190
messages, upgraded, tail = response.feed_data(
b'HTTP/1.1 200 ' + reason + b'\r\n\r\n')
msg = messages[0][0]
assert msg.version == (1, 1)
assert msg.code == 200
assert msg.reason == reason.decode()
| def test_http_response_parser_status_line_under_limit(response):
| reason = b'O' * 8190
messages, upgraded, tail = response.feed_data(
b'HTTP/1.1 200 ' + reason + b'\r\n\r\n')
msg = messages[0][0]
assert msg.version == (1, 1)
assert msg.code == 200
assert msg.reason == reason.decode()
| ({}\\) when reading"
.format(size))
with pytest.raises(http_exceptions.LineTooLong, match=match):
response.feed_data(
b'HTTP/1.1 200 Ok' + reason + b'\r\n\r\n')
def test_http_response_parser_status_line_under_limit(response):
| 64 | 64 | 90 | 11 | 53 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_http_response_parser_status_line_under_limit | test_http_response_parser_status_line_under_limit | 605 | 612 | 605 | 605 | d7404002f1ac847b4675ae9ab7fb8feea6dcb15a | bigcode/the-stack | train |
44f32556be4e1ca67fca0aea | train | function | def test_http_request_bad_status_line(parser):
text = b'getpath \r\n\r\n'
with pytest.raises(http_exceptions.BadStatusLine):
parser.feed_data(text)
| def test_http_request_bad_status_line(parser):
| text = b'getpath \r\n\r\n'
with pytest.raises(http_exceptions.BadStatusLine):
parser.feed_data(text)
| )
assert msg.headers == CIMultiDict()
assert msg.raw_headers == ()
assert not msg.should_close
assert msg.compression is None
assert not msg.upgrade
assert not msg.chunked
assert msg.url == URL('/path')
def test_http_request_bad_status_line(parser):
| 64 | 64 | 39 | 9 | 55 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_http_request_bad_status_line | test_http_request_bad_status_line | 475 | 478 | 475 | 475 | 9f2c2a0242b25eb36b8a2bb5f40bf73e149670e9 | bigcode/the-stack | train |
925ec9646f9ed1aa6b4a68ca | train | function | def test_parse_delayed(parser):
text = b'GET /test HTTP/1.1\r\n'
messages, upgrade, tail = parser.feed_data(text)
assert len(messages) == 0
assert not upgrade
messages, upgrade, tail = parser.feed_data(b'\r\n')
assert len(messages) == 1
msg = messages[0][0]
assert msg.method == 'GET'
| def test_parse_delayed(parser):
| text = b'GET /test HTTP/1.1\r\n'
messages, upgrade, tail = parser.feed_data(text)
assert len(messages) == 0
assert not upgrade
messages, upgrade, tail = parser.feed_data(b'\r\n')
assert len(messages) == 1
msg = messages[0][0]
assert msg.method == 'GET'
| Content-Length: 4\r\n\r\nbody'
messages, upgrade, tail = parser.feed_data(text)
assert len(messages) == 1
_, payload = messages[0]
body = await payload.read(4)
assert body == b'body'
def test_parse_delayed(parser):
| 64 | 64 | 90 | 7 | 57 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_parse_delayed | test_parse_delayed | 123 | 132 | 123 | 123 | 1fe92ff84797005e17eb50f6f2b98e32010caa08 | bigcode/the-stack | train |
ee5c141d275114eebf663cb1 | train | function | async def test_parse_body_with_CRLF(parser):
text = b'\r\nGET /test HTTP/1.1\r\nContent-Length: 4\r\n\r\nbody'
messages, upgrade, tail = parser.feed_data(text)
assert len(messages) == 1
_, payload = messages[0]
body = await payload.read(4)
assert body == b'body'
| async def test_parse_body_with_CRLF(parser):
| text = b'\r\nGET /test HTTP/1.1\r\nContent-Length: 4\r\n\r\nbody'
messages, upgrade, tail = parser.feed_data(text)
assert len(messages) == 1
_, payload = messages[0]
body = await payload.read(4)
assert body == b'body'
| 4\r\n\r\nbody'
messages, upgrade, tail = parser.feed_data(text)
assert len(messages) == 1
_, payload = messages[0]
body = await payload.read(4)
assert body == b'body'
async def test_parse_body_with_CRLF(parser):
| 64 | 64 | 84 | 10 | 54 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_parse_body_with_CRLF | test_parse_body_with_CRLF | 114 | 120 | 114 | 114 | ddd2211f23f4214c45893d28909df16bfd03ad66 | bigcode/the-stack | train |
fb95bb9eb371f1337710bf4c | train | function | @pytest.mark.parametrize('size', [40960, 8191])
def test_max_header_field_size(parser, size):
name = b't' * size
text = (b'GET /test HTTP/1.1\r\n' + name + b':data\r\n\r\n')
match = ("400, message='Got more than 8190 bytes \\({}\\) when reading"
.format(size))
with pytest.raises(http_excep... | @pytest.mark.parametrize('size', [40960, 8191])
def test_max_header_field_size(parser, size):
| name = b't' * size
text = (b'GET /test HTTP/1.1\r\n' + name + b':data\r\n\r\n')
match = ("400, message='Got more than 8190 bytes \\({}\\) when reading"
.format(size))
with pytest.raises(http_exceptions.LineTooLong, match=match):
parser.feed_data(text)
| GET /test HTTP/1.1\r\n'
b'test[]: line\r\n\r\n')
with pytest.raises(http_exceptions.BadHttpMessage):
parser.feed_data(text)
@pytest.mark.parametrize('size', [40960, 8191])
def test_max_header_field_size(parser, size):
| 64 | 64 | 109 | 24 | 40 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_max_header_field_size | test_max_header_field_size | 367 | 375 | 367 | 368 | df9fe4494ea6081b78161f1b5c1f683e1f247347 | bigcode/the-stack | train |
cb82eea91023907483655941 | train | function | async def test_parse_body(parser):
text = b'GET /test HTTP/1.1\r\nContent-Length: 4\r\n\r\nbody'
messages, upgrade, tail = parser.feed_data(text)
assert len(messages) == 1
_, payload = messages[0]
body = await payload.read(4)
assert body == b'body'
| async def test_parse_body(parser):
| text = b'GET /test HTTP/1.1\r\nContent-Length: 4\r\n\r\nbody'
messages, upgrade, tail = parser.feed_data(text)
assert len(messages) == 1
_, payload = messages[0]
body = await payload.read(4)
assert body == b'body'
| (messages) == 1
msg, _ = messages[0]
assert msg.compression is None
assert not msg.upgrade
assert msg.method == 'GET'
assert msg.path == '/test'
assert msg.version == (1, 1)
async def test_parse_body(parser):
| 64 | 64 | 79 | 7 | 57 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_parse_body | test_parse_body | 105 | 111 | 105 | 105 | 88172c688128e5c674631edb887d8b29f8cc4aff | bigcode/the-stack | train |
59b4f283249e2d4524f6eb77 | train | function | @pytest.mark.skipif(brotli is None, reason="brotli is not installed")
def test_compression_brotli(parser):
text = (b'GET /test HTTP/1.1\r\n'
b'content-encoding: br\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert msg.compression == 'br'
| @pytest.mark.skipif(brotli is None, reason="brotli is not installed")
def test_compression_brotli(parser):
| text = (b'GET /test HTTP/1.1\r\n'
b'content-encoding: br\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert msg.compression == 'br'
| : gzip\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert msg.compression == 'gzip'
@pytest.mark.skipif(brotli is None, reason="brotli is not installed")
def test_compression_brotli(parser):
| 64 | 64 | 87 | 27 | 37 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_compression_brotli | test_compression_brotli | 302 | 308 | 302 | 303 | 30a59bd0e3e1bf8b13463ea38577022170349cca | bigcode/the-stack | train |
528428c263325cbe1a21c1df | train | function | def test_http_request_upgrade(parser):
text = (b'GET /test HTTP/1.1\r\n'
b'connection: upgrade\r\n'
b'upgrade: websocket\r\n\r\n'
b'some raw data')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert not msg.should_close
assert msg.upgrade... | def test_http_request_upgrade(parser):
| text = (b'GET /test HTTP/1.1\r\n'
b'connection: upgrade\r\n'
b'upgrade: websocket\r\n\r\n'
b'some raw data')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert not msg.should_close
assert msg.upgrade
assert upgrade
assert tail == ... | grade
assert not msg.chunked
assert msg.url == URL('/path')
def test_http_request_bad_status_line(parser):
text = b'getpath \r\n\r\n'
with pytest.raises(http_exceptions.BadStatusLine):
parser.feed_data(text)
def test_http_request_upgrade(parser):
| 64 | 64 | 99 | 7 | 57 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_http_request_upgrade | test_http_request_upgrade | 481 | 491 | 481 | 481 | 52b0dd3a29b4c09456c8beb51ce4c44bcc95f7fe | bigcode/the-stack | train |
7d87f5dd4f3d1081534ecbb2 | train | function | def test_conn_default_1_0(parser):
text = b'GET /test HTTP/1.0\r\n\r\n'
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert msg.should_close
| def test_conn_default_1_0(parser):
| text = b'GET /test HTTP/1.0\r\n\r\n'
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert msg.should_close
| 2')]
assert msg.raw_headers == ((b'Set-Cookie', b'c1=cookie1'),
(b'Set-Cookie', b'c2=cookie2'))
assert not msg.should_close
assert msg.compression is None
def test_conn_default_1_0(parser):
| 64 | 64 | 55 | 10 | 53 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_conn_default_1_0 | test_conn_default_1_0 | 195 | 199 | 195 | 195 | 27ff9f3dbecf0e9b5e23ac6abc7dd61b7dc3f78c | bigcode/the-stack | train |
20010f6178331b77517feea5 | train | function | def test_conn_default_1_1(parser):
text = b'GET /test HTTP/1.1\r\n\r\n'
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert not msg.should_close
| def test_conn_default_1_1(parser):
| text = b'GET /test HTTP/1.1\r\n\r\n'
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert not msg.should_close
| test_conn_default_1_0(parser):
text = b'GET /test HTTP/1.0\r\n\r\n'
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert msg.should_close
def test_conn_default_1_1(parser):
| 64 | 64 | 56 | 10 | 53 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_conn_default_1_1 | test_conn_default_1_1 | 202 | 206 | 202 | 202 | e8084bd38a162531c69c92c0a7b4fd620a0b1d8f | bigcode/the-stack | train |
9254d3dd39b92b7076bf48a6 | train | function | def test_http_response_parser_code_not_int(response):
with pytest.raises(http_exceptions.BadHttpMessage):
response.feed_data(b'HTTP/1.1 ttt test\r\n\r\n')
| def test_http_response_parser_code_not_int(response):
| with pytest.raises(http_exceptions.BadHttpMessage):
response.feed_data(b'HTTP/1.1 ttt test\r\n\r\n')
| ][0]
assert msg.code == 99
def test_http_response_parser_code_above_999(response):
with pytest.raises(http_exceptions.BadHttpMessage):
response.feed_data(b'HTTP/1.1 9999 test\r\n\r\n')
def test_http_response_parser_code_not_int(response):
| 64 | 64 | 40 | 10 | 54 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_http_response_parser_code_not_int | test_http_response_parser_code_not_int | 643 | 645 | 643 | 643 | f517fd0b134cb1b0f3a1502e8ba1f73df9d486fb | bigcode/the-stack | train |
c60674538c3370b8dd723833 | train | function | @pytest.mark.parametrize('size', [40962, 8191])
def test_http_response_parser_bad_status_line_too_long(response, size):
reason = b't' * (size - 2)
match = ("400, message='Got more than 8190 bytes \\({}\\) when reading"
.format(size))
with pytest.raises(http_exceptions.LineTooLong, match=match):... | @pytest.mark.parametrize('size', [40962, 8191])
def test_http_response_parser_bad_status_line_too_long(response, size):
| reason = b't' * (size - 2)
match = ("400, message='Got more than 8190 bytes \\({}\\) when reading"
.format(size))
with pytest.raises(http_exceptions.LineTooLong, match=match):
response.feed_data(
b'HTTP/1.1 200 Ok' + reason + b'\r\n\r\n')
| ест')])
assert msg.raw_headers == ((b'x-test', 'тест'.encode('utf-8')),)
assert not upgraded
assert not tail
@pytest.mark.parametrize('size', [40962, 8191])
def test_http_response_parser_bad_status_line_too_long(response, size):
| 64 | 64 | 111 | 29 | 34 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_http_response_parser_bad_status_line_too_long | test_http_response_parser_bad_status_line_too_long | 595 | 602 | 595 | 596 | 5ce08bb840e0d85d4110840f5f8e03cec0c6da8a | bigcode/the-stack | train |
04d39c4ebef97b0b47d84233 | train | function | def test_headers_old_websocket_key1(parser):
text = (b'GET /test HTTP/1.1\r\n'
b'SEC-WEBSOCKET-KEY1: line\r\n\r\n')
with pytest.raises(http_exceptions.BadHttpMessage):
parser.feed_data(text)
| def test_headers_old_websocket_key1(parser):
| text = (b'GET /test HTTP/1.1\r\n'
b'SEC-WEBSOCKET-KEY1: line\r\n\r\n')
with pytest.raises(http_exceptions.BadHttpMessage):
parser.feed_data(text)
| /1.1\r\n'
b'content-length: 0\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg, payload = messages[0]
assert upgrade
assert isinstance(payload, streams.StreamReader)
def test_headers_old_websocket_key1(parser):
| 64 | 64 | 62 | 10 | 54 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_headers_old_websocket_key1 | test_headers_old_websocket_key1 | 328 | 333 | 328 | 328 | 51a69a910636e1f55773313c6897830d924c3733 | bigcode/the-stack | train |
1da00ec678ffadd6f5f00000 | train | function | def test_headers_multi_feed(parser):
text1 = b'GET /test HTTP/1.1\r\n'
text2 = b'test: line\r'
text3 = b'\n continue\r\n\r\n'
messages, upgrade, tail = parser.feed_data(text1)
assert len(messages) == 0
messages, upgrade, tail = parser.feed_data(text2)
assert len(messages) == 0
message... | def test_headers_multi_feed(parser):
| text1 = b'GET /test HTTP/1.1\r\n'
text2 = b'test: line\r'
text3 = b'\n continue\r\n\r\n'
messages, upgrade, tail = parser.feed_data(text1)
assert len(messages) == 0
messages, upgrade, tail = parser.feed_data(text2)
assert len(messages) == 0
messages, upgrade, tail = parser.feed_data(t... | (text)
assert len(messages) == 0
assert not upgrade
messages, upgrade, tail = parser.feed_data(b'\r\n')
assert len(messages) == 1
msg = messages[0][0]
assert msg.method == 'GET'
def test_headers_multi_feed(parser):
| 64 | 64 | 177 | 7 | 57 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_headers_multi_feed | test_headers_multi_feed | 135 | 154 | 135 | 135 | 59696d26f3af8e4bb4a40210d84b111d5c04c817 | bigcode/the-stack | train |
1a9b2ebafc881c50cd1d2aca | train | function | def test_http_request_parser_bad_method(parser):
with pytest.raises(http_exceptions.BadStatusLine):
parser.feed_data(b'=":<G>(e),[T];?" /get HTTP/1.1\r\n\r\n')
| def test_http_request_parser_bad_method(parser):
| with pytest.raises(http_exceptions.BadStatusLine):
parser.feed_data(b'=":<G>(e),[T];?" /get HTTP/1.1\r\n\r\n')
| assert msg.method == 'GET'
assert msg.path == '//path'
assert msg.version == (1, 1)
assert not msg.should_close
assert msg.compression is None
assert not msg.upgrade
assert not msg.chunked
def test_http_request_parser_bad_method(parser):
| 64 | 64 | 48 | 9 | 54 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_http_request_parser_bad_method | test_http_request_parser_bad_method | 541 | 543 | 541 | 541 | 2fbf3364c6d100d8ea633faca0348d30731ccf0c | bigcode/the-stack | train |
88afd1046936a3ecc28e77f7 | train | function | def test_http_request_parser_utf8(parser):
text = 'GET /path HTTP/1.1\r\nx-test:тест\r\n\r\n'.encode('utf-8')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert msg.method == 'GET'
assert msg.path == '/path'
assert msg.version == (1, 1)
assert msg.headers == CIMult... | def test_http_request_parser_utf8(parser):
| text = 'GET /path HTTP/1.1\r\nx-test:тест\r\n\r\n'.encode('utf-8')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert msg.method == 'GET'
assert msg.path == '/path'
assert msg.version == (1, 1)
assert msg.headers == CIMultiDict([('X-TEST', 'тест')])
assert msg.... | b'some raw data')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert not msg.should_close
assert msg.upgrade
assert upgrade
assert tail == b'some raw data'
def test_http_request_parser_utf8(parser):
| 64 | 64 | 166 | 9 | 55 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_http_request_parser_utf8 | test_http_request_parser_utf8 | 494 | 508 | 494 | 494 | 430f6e5397946b256f397ba5574f83cf09336529 | bigcode/the-stack | train |
b211b36b41dd6721bb56c30f | train | function | def test_max_header_value_size_continuation_under_limit(parser):
value = b'A' * 8185
text = (b'GET /test HTTP/1.1\r\n'
b'data: test\r\n ' + value + b'\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert msg.method == 'GET'
assert msg.path == '/test... | def test_max_header_value_size_continuation_under_limit(parser):
| value = b'A' * 8185
text = (b'GET /test HTTP/1.1\r\n'
b'data: test\r\n ' + value + b'\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert msg.method == 'GET'
assert msg.path == '/test'
assert msg.version == (1, 1)
assert msg.headers == CIMu... | \r\n')
match = ("400, message='Got more than 8190 bytes \\({}\\) when reading"
.format(size))
with pytest.raises(http_exceptions.LineTooLong, match=match):
parser.feed_data(text)
def test_max_header_value_size_continuation_under_limit(parser):
| 64 | 64 | 184 | 13 | 51 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_max_header_value_size_continuation_under_limit | test_max_header_value_size_continuation_under_limit | 439 | 455 | 439 | 439 | 96f106e443593539b9d2fb41e6fcc8aa1b4e056b | bigcode/the-stack | train |
74c0a370ded5792beed5e689 | train | function | def test_http_request_chunked_payload_chunks(parser):
text = (b'GET /test HTTP/1.1\r\n'
b'transfer-encoding: chunked\r\n\r\n')
msg, payload = parser.feed_data(text)[0][0]
parser.feed_data(b'4\r\ndata\r')
parser.feed_data(b'\n4')
parser.feed_data(b'\r')
parser.feed_data(b'\n')
pa... | def test_http_request_chunked_payload_chunks(parser):
| text = (b'GET /test HTTP/1.1\r\n'
b'transfer-encoding: chunked\r\n\r\n')
msg, payload = parser.feed_data(text)[0][0]
parser.feed_data(b'4\r\ndata\r')
parser.feed_data(b'\n4')
parser.feed_data(b'\r')
parser.feed_data(b'\n')
parser.feed_data(b'li')
parser.feed_data(b'ne\r\n0\r... | _chunk_splits
assert payload.is_eof()
assert len(messages) == 1
msg2, payload2 = messages[0]
assert msg2.method == 'POST'
assert msg2.chunked
assert not payload2.is_eof()
def test_http_request_chunked_payload_chunks(parser):
| 66 | 66 | 220 | 10 | 56 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_http_request_chunked_payload_chunks | test_http_request_chunked_payload_chunks | 686 | 706 | 686 | 686 | 431ddf3698683fbdd1de636eb650beec71e2b0b3 | bigcode/the-stack | train |
3292e9adc5ff743d6485b27a | train | function | def test_compression_empty(parser):
text = (b'GET /test HTTP/1.1\r\n'
b'content-encoding: \r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert msg.compression is None
| def test_compression_empty(parser):
| text = (b'GET /test HTTP/1.1\r\n'
b'content-encoding: \r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert msg.compression is None
| b'connection: upgrade\r\n'
b'upgrade: websocket\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert not msg.should_close
assert msg.upgrade
assert upgrade
def test_compression_empty(parser):
| 64 | 64 | 66 | 7 | 56 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_compression_empty | test_compression_empty | 278 | 283 | 278 | 278 | 68c84a927c1da30fd2df78b301ac99d65d97d9ca | bigcode/the-stack | train |
61fb8e89c2d98227cb11bf32 | train | function | def test_conn_keep_alive_1_0(parser):
text = (b'GET /test HTTP/1.0\r\n'
b'connection: keep-alive\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert not msg.should_close
| def test_conn_keep_alive_1_0(parser):
| text = (b'GET /test HTTP/1.0\r\n'
b'connection: keep-alive\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert not msg.should_close
| = (b'GET /test HTTP/1.0\r\n'
b'connection: close\r\n\r\n')
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert msg.should_close
def test_conn_keep_alive_1_0(parser):
| 64 | 64 | 69 | 11 | 52 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_conn_keep_alive_1_0 | test_conn_keep_alive_1_0 | 225 | 230 | 225 | 225 | 96dc5cb963c563919742814630f9284ff6bbb8ad | bigcode/the-stack | train |
7d527ed3dcac534092c715e7 | train | function | def test_http_request_parser_bad_version(parser):
with pytest.raises(http_exceptions.BadHttpMessage):
parser.feed_data(b'GET //get HT/11\r\n\r\n')
| def test_http_request_parser_bad_version(parser):
| with pytest.raises(http_exceptions.BadHttpMessage):
parser.feed_data(b'GET //get HT/11\r\n\r\n')
| assert not msg.chunked
def test_http_request_parser_bad_method(parser):
with pytest.raises(http_exceptions.BadStatusLine):
parser.feed_data(b'=":<G>(e),[T];?" /get HTTP/1.1\r\n\r\n')
def test_http_request_parser_bad_version(parser):
| 64 | 64 | 37 | 9 | 55 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_http_request_parser_bad_version | test_http_request_parser_bad_version | 546 | 548 | 546 | 546 | 60d78062c3afbaa4fe40c4e108fac12c816a72cf | bigcode/the-stack | train |
1d814ca5b6df084b19372dd6 | train | function | @pytest.mark.parametrize('size', [40965, 8191])
def test_max_header_value_size_continuation(parser, size):
name = b'T' * (size - 5)
text = (b'GET /test HTTP/1.1\r\n'
b'data: test\r\n ' + name + b'\r\n\r\n')
match = ("400, message='Got more than 8190 bytes \\({}\\) when reading"
.fo... | @pytest.mark.parametrize('size', [40965, 8191])
def test_max_header_value_size_continuation(parser, size):
| name = b'T' * (size - 5)
text = (b'GET /test HTTP/1.1\r\n'
b'data: test\r\n ' + name + b'\r\n\r\n')
match = ("400, message='Got more than 8190 bytes \\({}\\) when reading"
.format(size))
with pytest.raises(http_exceptions.LineTooLong, match=match):
parser.feed_data(text... | assert not msg.should_close
assert msg.compression is None
assert not msg.upgrade
assert not msg.chunked
assert msg.url == URL('/test')
@pytest.mark.parametrize('size', [40965, 8191])
def test_max_header_value_size_continuation(parser, size):
| 64 | 64 | 124 | 27 | 37 | Semnodime/aiohttp | tests/test_http_parser.py | Python | test_max_header_value_size_continuation | test_max_header_value_size_continuation | 427 | 436 | 427 | 428 | 922b6c754068d3bc76371f8054837dd2a56d4940 | bigcode/the-stack | train |
aeba11ec5d77f4522a9c50a5 | train | function | @pytest.fixture
def stream():
return mock.Mock()
| @pytest.fixture
def stream():
| return mock.Mock()
| implementations"""
return request.param(protocol, loop,
max_line_size=8190,
max_headers=32768,
max_field_size=8190)
@pytest.fixture(params=RESPONSE_PARSERS)
def response_cls(request):
"""Parser implementations"""
return request.pa... | 64 | 64 | 11 | 6 | 57 | Semnodime/aiohttp | tests/test_http_parser.py | Python | stream | stream | 68 | 70 | 68 | 69 | b97e0eaa14db1ba7860a41a10b72aab6b0db5584 | bigcode/the-stack | train |
3fed57926a909b216d48ec8d | train | function | def _iter_sqlalchemy_engine(engine, query, *args, **kwargs):
return _iter_sqlalchemy_connection(engine.contextual_connect(), query,
*args, **kwargs)
| def _iter_sqlalchemy_engine(engine, query, *args, **kwargs):
| return _iter_sqlalchemy_connection(engine.contextual_connect(), query,
*args, **kwargs)
| in cursor.description]
yield tuple(hdr)
if first_row is None:
raise StopIteration
yield first_row
for row in it:
yield row # don't wrap, return whatever the database engine returns
def _iter_sqlalchemy_engine(engine, query, *args, **kwargs):
| 64 | 64 | 37 | 16 | 47 | thatneat/petl | petl/io/db.py | Python | _iter_sqlalchemy_engine | _iter_sqlalchemy_engine | 181 | 183 | 181 | 181 | f77d034868aa7b08fc2c0805eef7eb82b2aa11cd | bigcode/the-stack | train |
4aacc020beb7a289ccb405c0 | train | function | def _todb_dbapi_cursor(table, cursor, tablename, schema=None, commit=True,
truncate=False):
# sanitise table name
tablename = _quote(tablename)
if schema is not None:
tablename = _quote(schema) + '.' + tablename
debug('tablename: %r', tablename)
# sanitise field name... | def _todb_dbapi_cursor(table, cursor, tablename, schema=None, commit=True,
truncate=False):
# sanitise table name
| tablename = _quote(tablename)
if schema is not None:
tablename = _quote(schema) + '.' + tablename
debug('tablename: %r', tablename)
# sanitise field names
it = iter(table)
hdr = next(it)
flds = list(map(text_type, hdr))
colnames = [_quote(n) for n in flds]
debug('column name... | .close()
cursor = mkcurs()
insertcolnames = ', '.join(colnames)
insertquery = SQL_INSERT_QUERY % (tablename, insertcolnames, placeholders)
debug('insert data via query %r' % insertquery)
cursor.executemany(insertquery, it)
cursor.close()
if commit:
debug('commit transaction')
... | 110 | 110 | 367 | 31 | 79 | thatneat/petl | petl/io/db.py | Python | _todb_dbapi_cursor | _todb_dbapi_cursor | 492 | 534 | 492 | 495 | bdca08db2f9ad205addeaafc9517d52916fd4d2c | bigcode/the-stack | train |
330cb9c99d28077462bb76fe | train | function | def appenddb(table, dbo, tablename, schema=None, commit=True):
"""
Load data into an existing database table via a DB-API 2.0
connection or cursor. As :func:`petl.io.db.todb` except that the database
table will be appended, i.e., the new data will be inserted into the
table, and any existing rows wi... | def appenddb(table, dbo, tablename, schema=None, commit=True):
| """
Load data into an existing database table via a DB-API 2.0
connection or cursor. As :func:`petl.io.db.todb` except that the database
table will be appended, i.e., the new data will be inserted into the
table, and any existing rows will remain.
"""
needs_closing = False
# convenien... | alchemy_session(table, session, tablename, schema=None,
commit=True, truncate=False):
_todb_sqlalchemy_connection(table, session.connection(), tablename,
schema=schema, commit=commit,
truncate=truncate)
def appenddb(table,... | 64 | 64 | 172 | 16 | 48 | thatneat/petl | petl/io/db.py | Python | appenddb | appenddb | 605 | 628 | 605 | 605 | 2b0a3171f13908dd6a56950b31da965af90562a5 | bigcode/the-stack | train |
04e8820eedc70849de547558 | train | function | def _iter_sqlalchemy_connection(connection, query, *args, **kwargs):
debug('connection: %r', connection)
results = connection.execute(query, *args, **kwargs)
hdr = results.keys()
yield tuple(hdr)
for row in results:
yield row
| def _iter_sqlalchemy_connection(connection, query, *args, **kwargs):
| debug('connection: %r', connection)
results = connection.execute(query, *args, **kwargs)
hdr = results.keys()
yield tuple(hdr)
for row in results:
yield row
| # don't wrap, return whatever the database engine returns
def _iter_sqlalchemy_engine(engine, query, *args, **kwargs):
return _iter_sqlalchemy_connection(engine.contextual_connect(), query,
*args, **kwargs)
def _iter_sqlalchemy_connection(connection, query, *args, **kwargs)... | 64 | 64 | 61 | 16 | 48 | thatneat/petl | petl/io/db.py | Python | _iter_sqlalchemy_connection | _iter_sqlalchemy_connection | 186 | 192 | 186 | 186 | d802704f9df33430db1a35fa8b7d473d1f65d301 | bigcode/the-stack | train |
45eb597a0722cd19a0aea14b | train | function | def _todb_sqlalchemy_session(table, session, tablename, schema=None,
commit=True, truncate=False):
_todb_sqlalchemy_connection(table, session.connection(), tablename,
schema=schema, commit=commit,
truncate=truncate)
| def _todb_sqlalchemy_session(table, session, tablename, schema=None,
commit=True, truncate=False):
| _todb_sqlalchemy_connection(table, session.connection(), tablename,
schema=schema, commit=commit,
truncate=truncate)
| .execute(insertquery, row)
# finish up
if commit:
debug('commit transaction')
trans.commit()
# N.B., don't close connection, leave that to the application
def _todb_sqlalchemy_session(table, session, tablename, schema=None,
commit=True, truncate=False):
| 64 | 64 | 53 | 24 | 39 | thatneat/petl | petl/io/db.py | Python | _todb_sqlalchemy_session | _todb_sqlalchemy_session | 597 | 602 | 597 | 599 | 0c8a31cd526c994183fb93f8e8a0762f82600eaa | bigcode/the-stack | train |
ff5e9e392491b9ea10fc4775 | train | function | def _todb_sqlalchemy_connection(table, connection, tablename, schema=None,
commit=True, truncate=False):
debug('connection: %r', connection)
# sanitise table name
tablename = _quote(tablename)
if schema is not None:
tablename = _quote(schema) + '.' + tablename
... | def _todb_sqlalchemy_connection(table, connection, tablename, schema=None,
commit=True, truncate=False):
| debug('connection: %r', connection)
# sanitise table name
tablename = _quote(tablename)
if schema is not None:
tablename = _quote(schema) + '.' + tablename
debug('tablename: %r', tablename)
# sanitise field names
it = iter(table)
hdr = next(it)
flds = list(map(text_type, hd... | .executemany(insertquery, it)
# N.B., don't close the cursor, leave that to the application
if commit:
debug('commit transaction')
connection.commit()
def _todb_sqlalchemy_engine(table, engine, tablename, schema=None, commit=True,
truncate=False):
_todb_sqlal... | 116 | 116 | 387 | 24 | 92 | thatneat/petl | petl/io/db.py | Python | _todb_sqlalchemy_connection | _todb_sqlalchemy_connection | 544 | 592 | 544 | 546 | 9297e394af51ec41b2a9c88af190c0ee75658b7d | bigcode/the-stack | train |
27bf2c3ce73d135eebf0e104 | train | function | def _iter_dbapi_mkcurs(mkcurs, query, *args, **kwargs):
cursor = mkcurs()
try:
for row in _iter_dbapi_cursor(cursor, query, *args, **kwargs):
yield row
finally:
cursor.close()
| def _iter_dbapi_mkcurs(mkcurs, query, *args, **kwargs):
| cursor = mkcurs()
try:
for row in _iter_dbapi_cursor(cursor, query, *args, **kwargs):
yield row
finally:
cursor.close()
| of duck...
else:
raise ArgumentError('unsupported database object type: %r' % self.dbo)
return _iter(self.dbo, self.query, *self.args, **self.kwargs)
def _iter_dbapi_mkcurs(mkcurs, query, *args, **kwargs):
| 64 | 64 | 60 | 20 | 44 | thatneat/petl | petl/io/db.py | Python | _iter_dbapi_mkcurs | _iter_dbapi_mkcurs | 144 | 150 | 144 | 144 | c8a7b663fa4ff341327db372e77dc3aad1342563 | bigcode/the-stack | train |
58b08ca263980ef89015b3fe | train | function | def _iter_dbapi_connection(connection, query, *args, **kwargs):
cursor = connection.cursor()
try:
for row in _iter_dbapi_cursor(cursor, query, *args, **kwargs):
yield row
finally:
cursor.close()
| def _iter_dbapi_connection(connection, query, *args, **kwargs):
| cursor = connection.cursor()
try:
for row in _iter_dbapi_cursor(cursor, query, *args, **kwargs):
yield row
finally:
cursor.close()
| query, *args, **kwargs):
cursor = mkcurs()
try:
for row in _iter_dbapi_cursor(cursor, query, *args, **kwargs):
yield row
finally:
cursor.close()
def _iter_dbapi_connection(connection, query, *args, **kwargs):
| 64 | 64 | 55 | 16 | 48 | thatneat/petl | petl/io/db.py | Python | _iter_dbapi_connection | _iter_dbapi_connection | 153 | 159 | 153 | 153 | b23c4cc53e8889b941b6c1775f9589ec79c56213 | bigcode/the-stack | train |
74c45369ca6800df6b625441 | train | function | def _todb_dbapi_connection(table, connection, tablename, schema=None,
commit=True, truncate=False):
# sanitise table name
tablename = _quote(tablename)
if schema is not None:
tablename = _quote(schema) + '.' + tablename
debug('tablename: %r', tablename)
# sanitis... | def _todb_dbapi_connection(table, connection, tablename, schema=None,
commit=True, truncate=False):
# sanitise table name
| tablename = _quote(tablename)
if schema is not None:
tablename = _quote(schema) + '.' + tablename
debug('tablename: %r', tablename)
# sanitise field names
it = iter(table)
hdr = next(it)
flds = list(map(text_type, hdr))
colnames = [_quote(n) for n in flds]
debug('column name... | tablename, schema=schema, commit=commit,
truncate=truncate)
# some other sort of duck...
else:
raise ArgumentError('unsupported database object type: %r' % dbo)
SQL_TRUNCATE_QUERY = 'DELETE FROM %s'
SQL_INSERT_QUERY = 'INSERT INTO %s (%s) VALUES (%s)'
def _todb_dbapi_conne... | 102 | 103 | 346 | 31 | 71 | thatneat/petl | petl/io/db.py | Python | _todb_dbapi_connection | _todb_dbapi_connection | 397 | 441 | 397 | 400 | 77f11400716a1f3047957e976e6c3857a295e3c9 | bigcode/the-stack | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.