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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
02589b9714df8269c2c30577 | train | function | def test_empty_response():
c = Connection(CLIENT)
c.send(Request(method="GET", target="/", headers=[("Host", "a")]))
c.receive_data(b"\r\n")
with pytest.raises(RemoteProtocolError):
c.next_event()
| def test_empty_response():
| c = Connection(CLIENT)
c.send(Request(method="GET", target="/", headers=[("Host", "a")]))
c.receive_data(b"\r\n")
with pytest.raises(RemoteProtocolError):
c.next_event()
| connection", b"close")]))
# This used to raise IndexError
def test_empty_request():
c = Connection(SERVER)
c.receive_data(b"\r\n")
with pytest.raises(RemoteProtocolError):
c.next_event()
# This used to raise IndexError
def test_empty_response():
| 64 | 64 | 55 | 5 | 58 | Kludex/h11 | h11/tests/test_connection.py | Python | test_empty_response | test_empty_response | 979 | 984 | 979 | 979 | e7e6a90f4711c388e60929440708a432af8a94ca | bigcode/the-stack | train |
cdf1016507da4b0f809cb717 | train | function | def test_automatic_transfer_encoding_in_response():
# Check that in responses, the user can specify either Transfer-Encoding:
# chunked or no framing at all, and in both cases we automatically select
# the right option depending on whether the peer speaks HTTP/1.0 or
# HTTP/1.1
for user_headers in [... | def test_automatic_transfer_encoding_in_response():
# Check that in responses, the user can specify either Transfer-Encoding:
# chunked or no framing at all, and in both cases we automatically select
# the right option depending on whether the peer speaks HTTP/1.0 or
# HTTP/1.1
| for user_headers in [
[("Transfer-Encoding", "chunked")],
[],
# In fact, this even works if Content-Length is set,
# because if both are set then Transfer-Encoding wins
[("Transfer-Encoding", "chunked"), ("Content-Length", "100")],
]:
p = ConnectionPair()
... | == [Data(data=b"234567890"), EndOfMessage()]
assert c.their_state is MUST_CLOSE
assert receive_and_get(c, b"") == [ConnectionClosed()]
def test_automatic_transfer_encoding_in_response():
# Check that in responses, the user can specify either Transfer-Encoding:
# chunked or no framing at all, and in bot... | 107 | 108 | 362 | 68 | 39 | Kludex/h11 | h11/tests/test_connection.py | Python | test_automatic_transfer_encoding_in_response | test_automatic_transfer_encoding_in_response | 270 | 308 | 270 | 274 | a51b8bcff3cb6a29348cef2cc2d30127a8951530 | bigcode/the-stack | train |
47d3c1c00105608ddf87684b | train | function | def test_protocol_switch():
for (req, deny, accept) in [
(
Request(
method="CONNECT",
target="example.com:443",
headers=[("Host", "foo"), ("Content-Length", "1")],
),
Response(status_code=404, headers=[(b"transfer-encoding",... | def test_protocol_switch():
| for (req, deny, accept) in [
(
Request(
method="CONNECT",
target="example.com:443",
headers=[("Host", "foo"), ("Content-Length", "1")],
),
Response(status_code=404, headers=[(b"transfer-encoding", b"chunked")]),
... | _event() is PAUSED
c.send(Response(status_code=200, headers=[]))
c.send(EndOfMessage())
c.start_next_cycle()
assert get_all_events(c) == [
Request(method="GET", target="/3", headers=[("Host", "a.com")]),
EndOfMessage(),
]
# Doesn't pause this time, no trailing data
assert c.... | 256 | 256 | 1,087 | 5 | 251 | Kludex/h11 | h11/tests/test_connection.py | Python | test_protocol_switch | test_protocol_switch | 569 | 691 | 569 | 569 | bfb2743f2f94a61082d5cb60e5cc68e54b7170f4 | bigcode/the-stack | train |
8571273cc03507312ab5d400 | train | function | def test_close_different_states():
req = [
Request(method="GET", target="/foo", headers=[("Host", "a")]),
EndOfMessage(),
]
resp = [
Response(status_code=200, headers=[(b"transfer-encoding", b"chunked")]),
EndOfMessage(),
]
# Client before request
p = ConnectionP... | def test_close_different_states():
| req = [
Request(method="GET", target="/foo", headers=[("Host", "a")]),
EndOfMessage(),
]
resp = [
Response(status_code=200, headers=[(b"transfer-encoding", b"chunked")]),
EndOfMessage(),
]
# Client before request
p = ConnectionPair()
p.send(CLIENT, Connection... | assert conn.their_state is CLOSED
# But trying to receive new data on a closed connection is a
# RuntimeError (not ProtocolError, because the problem here isn't
# violation of HTTP, it's violation of physics)
p = setup()
with pytest.raises(RuntimeError):
p.conn[who_s... | 140 | 140 | 469 | 7 | 133 | Kludex/h11 | h11/tests/test_connection.py | Python | test_close_different_states | test_close_different_states | 735 | 796 | 735 | 735 | 1875b0ddcee5200be6e74459307435645ae12e7b | bigcode/the-stack | train |
b294228061dbc281f8c1820e | train | function | def test_server_talking_to_http10_client():
c = Connection(SERVER)
# No content-length, so no body
# NB: no host header
assert receive_and_get(c, b"GET / HTTP/1.0\r\n\r\n") == [
Request(method="GET", target="/", headers=[], http_version="1.0"),
EndOfMessage(),
]
assert c.their_st... | def test_server_talking_to_http10_client():
| c = Connection(SERVER)
# No content-length, so no body
# NB: no host header
assert receive_and_get(c, b"GET / HTTP/1.0\r\n\r\n") == [
Request(method="GET", target="/", headers=[], http_version="1.0"),
EndOfMessage(),
]
assert c.their_state is MUST_CLOSE
# We automatically Co... | .0", reason=b"OK")
]
assert c.our_state is MUST_CLOSE
assert receive_and_get(c, b"12345") == [Data(data=b"12345")]
assert receive_and_get(c, b"67890") == [Data(data=b"67890")]
assert receive_and_get(c, b"") == [EndOfMessage(), ConnectionClosed()]
assert c.their_state is CLOSED
def test_server_ta... | 100 | 100 | 336 | 10 | 89 | Kludex/h11 | h11/tests/test_connection.py | Python | test_server_talking_to_http10_client | test_server_talking_to_http10_client | 233 | 267 | 233 | 233 | c65085426356b88032038b7cc75e338bcf2e47b3 | bigcode/the-stack | train |
daea17238f9cf9d9732b9963 | train | function | @pytest.mark.parametrize(
"data",
[
b"\x00",
b"\x20",
b"\x16\x03\x03\x00\x31", # Typical start of a TLS Server Hello
],
)
def test_early_detection_of_invalid_response(data):
c = Connection(CLIENT)
# Early detection should occur before even receiving a `\r\n`
c.receive_da... | @pytest.mark.parametrize(
"data",
[
b"\x00",
b"\x20",
b"\x16\x03\x03\x00\x31", # Typical start of a TLS Server Hello
],
)
def test_early_detection_of_invalid_response(data):
| c = Connection(CLIENT)
# Early detection should occur before even receiving a `\r\n`
c.receive_data(data)
with pytest.raises(RemoteProtocolError):
c.next_event()
| c.next_event()
@pytest.mark.parametrize(
"data",
[
b"\x00",
b"\x20",
b"\x16\x03\x03\x00\x31", # Typical start of a TLS Server Hello
],
)
def test_early_detection_of_invalid_response(data):
| 64 | 64 | 101 | 59 | 5 | Kludex/h11 | h11/tests/test_connection.py | Python | test_early_detection_of_invalid_response | test_early_detection_of_invalid_response | 1,003 | 1,016 | 1,003 | 1,011 | c461b96915b5af5d2b7f2945f3d14818a2b4fd05 | bigcode/the-stack | train |
226e95e8eeefc1a791ce3e07 | train | function | def test_client_talking_to_http10_server():
c = Connection(CLIENT)
c.send(Request(method="GET", target="/", headers=[("Host", "example.com")]))
c.send(EndOfMessage())
assert c.our_state is DONE
# No content-length, so Http10 framing for body
assert receive_and_get(c, b"HTTP/1.0 200 OK\r\n\r\n") ... | def test_client_talking_to_http10_server():
| c = Connection(CLIENT)
c.send(Request(method="GET", target="/", headers=[("Host", "example.com")]))
c.send(EndOfMessage())
assert c.our_state is DONE
# No content-length, so Http10 framing for body
assert receive_and_get(c, b"HTTP/1.0 200 OK\r\n\r\n") == [
Response(status_code=200, heade... | =b"hello", chunk_start=True, chunk_end=True)
conn.receive_data(b"\r\n")
assert conn.next_event() == NEED_DATA
conn.receive_data(b"0\r\n\r\n")
assert conn.next_event() == EndOfMessage()
def test_client_talking_to_http10_server():
| 64 | 64 | 195 | 10 | 54 | Kludex/h11 | h11/tests/test_connection.py | Python | test_client_talking_to_http10_server | test_client_talking_to_http10_server | 217 | 230 | 217 | 217 | ae8f27e3d23af80eba02f47fb02f5703890fa065 | bigcode/the-stack | train |
dc4a226785d62a489bda29c6 | train | function | def test_errors():
# After a receive error, you can't receive
for role in [CLIENT, SERVER]:
c = Connection(our_role=role)
c.receive_data(b"gibberish\r\n\r\n")
with pytest.raises(RemoteProtocolError):
c.next_event()
# Now any attempt to receive continues to raise
... | def test_errors():
# After a receive error, you can't receive
| for role in [CLIENT, SERVER]:
c = Connection(our_role=role)
c.receive_data(b"gibberish\r\n\r\n")
with pytest.raises(RemoteProtocolError):
c.next_event()
# Now any attempt to receive continues to raise
assert c.their_state is ERROR
assert c.our_state is not... | (Response(status_code=200, headers=headers))
return c, c.send_with_data_passthrough(Data(data=placeholder))
c, data = setup(("Content-Length", "10"), "1.1")
assert data == [placeholder]
# Raises an error if the connection object doesn't think we've sent
# exactly 10 bytes
c.send(EndOfMessag... | 181 | 181 | 606 | 15 | 165 | Kludex/h11 | h11/tests/test_connection.py | Python | test_errors | test_errors | 877 | 944 | 877 | 878 | 9b28b22e8a139b2707dcba6f0aa2412483796f6d | bigcode/the-stack | train |
6dc50cf426bb8ee7865e23c9 | train | function | def test_close_simple():
# Just immediately closing a new connection without anything having
# happened yet.
for (who_shot_first, who_shot_second) in [(CLIENT, SERVER), (SERVER, CLIENT)]:
def setup():
p = ConnectionPair()
p.send(who_shot_first, ConnectionClosed())
... | def test_close_simple():
# Just immediately closing a new connection without anything having
# happened yet.
| for (who_shot_first, who_shot_second) in [(CLIENT, SERVER), (SERVER, CLIENT)]:
def setup():
p = ConnectionPair()
p.send(who_shot_first, ConnectionClosed())
for conn in p.conns:
assert conn.states == {
who_shot_first: CLOSED,
... | switching protocols, or while waiting for a
# protocol switch
p = setup()
with pytest.raises(LocalProtocolError):
p.conn[CLIENT].send(
Request(method="GET", target="/", headers=[("Host", "a")])
)
p = setup()
p.send(SERVER, accept)
... | 111 | 112 | 376 | 22 | 89 | Kludex/h11 | h11/tests/test_connection.py | Python | test_close_simple | test_close_simple | 694 | 732 | 694 | 696 | 51d1368ea743fbabca04e38543bbd15c460c1617 | bigcode/the-stack | train |
c07261820ba41100cd3eff82 | train | function | def test_pipelined_close():
c = Connection(SERVER)
# 2 requests then a close
c.receive_data(
b"GET /1 HTTP/1.1\r\nHost: a.com\r\nContent-Length: 5\r\n\r\n"
b"12345"
b"GET /2 HTTP/1.1\r\nHost: a.com\r\nContent-Length: 5\r\n\r\n"
b"67890"
)
c.receive_data(b"")
asser... | def test_pipelined_close():
| c = Connection(SERVER)
# 2 requests then a close
c.receive_data(
b"GET /1 HTTP/1.1\r\nHost: a.com\r\nContent-Length: 5\r\n\r\n"
b"12345"
b"GET /2 HTTP/1.1\r\nHost: a.com\r\nContent-Length: 5\r\n\r\n"
b"67890"
)
c.receive_data(b"")
assert get_all_events(c) == [
... | ="GET", target="/", headers=[("Host", "a"), ("Content-Length", "10")]
),
)
with pytest.raises(LocalProtocolError):
p.conn[CLIENT].send(ConnectionClosed())
p.conn[SERVER].receive_data(b"")
with pytest.raises(RemoteProtocolError):
p.conn[SERVER].next_event()
# Receive several req... | 102 | 102 | 341 | 7 | 94 | Kludex/h11 | h11/tests/test_connection.py | Python | test_pipelined_close | test_pipelined_close | 801 | 840 | 801 | 801 | 923b1b6042bacb36b812909badac260e2ecd0b6d | bigcode/the-stack | train |
b49bc48d7e7ac00c16bbcbc5 | train | function | def test_automagic_connection_close_handling():
p = ConnectionPair()
# If the user explicitly sets Connection: close, then we notice and
# respect it
p.send(
CLIENT,
[
Request(
method="GET",
target="/",
headers=[("Host", "exampl... | def test_automagic_connection_close_handling():
| p = ConnectionPair()
# If the user explicitly sets Connection: close, then we notice and
# respect it
p.send(
CLIENT,
[
Request(
method="GET",
target="/",
headers=[("Host", "example.com"), ("Connection", "close")],
)... | c.send(Response(status_code=200, headers=user_headers))
== b"HTTP/1.1 200 \r\nConnection: close\r\n\r\n"
)
assert c.send(Data(data=b"12345")) == b"12345"
def test_automagic_connection_close_handling():
| 64 | 64 | 212 | 10 | 54 | Kludex/h11 | h11/tests/test_connection.py | Python | test_automagic_connection_close_handling | test_automagic_connection_close_handling | 311 | 340 | 311 | 311 | d79b4abe48cee130836a70eb3fc577559dc1fec9 | bigcode/the-stack | train |
e616b9c576bd188e1646f26d | train | function | def test_pipelining():
# Client doesn't support pipelining, so we have to do this by hand
c = Connection(SERVER)
assert c.next_event() is NEED_DATA
# 3 requests all bunched up
c.receive_data(
b"GET /1 HTTP/1.1\r\nHost: a.com\r\nContent-Length: 5\r\n\r\n"
b"12345"
b"GET /2 HTT... | def test_pipelining():
# Client doesn't support pipelining, so we have to do this by hand
| c = Connection(SERVER)
assert c.next_event() is NEED_DATA
# 3 requests all bunched up
c.receive_data(
b"GET /1 HTTP/1.1\r\nHost: a.com\r\nContent-Length: 5\r\n\r\n"
b"12345"
b"GET /2 HTTP/1.1\r\nHost: a.com\r\nContent-Length: 5\r\n\r\n"
b"67890"
b"GET /3 HTTP/1.1\... | ")]), EndOfMessage()],
)
p.send(
SERVER,
[
Response(status_code=200, headers=[(b"transfer-encoding", b"chunked")]),
EndOfMessage(),
],
)
for conn in p.conns:
assert conn.states == {CLIENT: DONE, SERVER: DONE}
conn.start_next_cycle()
p.... | 177 | 177 | 592 | 24 | 153 | Kludex/h11 | h11/tests/test_connection.py | Python | test_pipelining | test_pipelining | 497 | 566 | 497 | 498 | 785fb56a90cae230d4510d8bc1b5c3a817858c76 | bigcode/the-stack | train |
81a91b0d2721e6cdbe29b22c | train | function | def test_special_exceptions_for_lost_connection_in_message_body():
c = Connection(SERVER)
c.receive_data(
b"POST / HTTP/1.1\r\n" b"Host: example.com\r\n" b"Content-Length: 100\r\n\r\n"
)
assert type(c.next_event()) is Request
assert c.next_event() is NEED_DATA
c.receive_data(b"12345")
... | def test_special_exceptions_for_lost_connection_in_message_body():
| c = Connection(SERVER)
c.receive_data(
b"POST / HTTP/1.1\r\n" b"Host: example.com\r\n" b"Content-Length: 100\r\n\r\n"
)
assert type(c.next_event()) is Request
assert c.next_event() is NEED_DATA
c.receive_data(b"12345")
assert c.next_event() == Data(data=b"12345")
c.receive_data(b... | 1")
assert (
c.send(
Response(
status_code=200,
headers=[
("Content-Length", "100"),
("Transfer-Encoding", "chunked"),
],
)
)
== b"HTTP/... | 87 | 87 | 291 | 13 | 74 | Kludex/h11 | h11/tests/test_connection.py | Python | test_special_exceptions_for_lost_connection_in_message_body | test_special_exceptions_for_lost_connection_in_message_body | 1,065 | 1,093 | 1,065 | 1,065 | 7cbffc03b593d3d7fd9f7f708b37e9297e8374fc | bigcode/the-stack | train |
ade9c48fd79f8d1b7f4f7500 | train | function | def test_Connection_basics_and_content_length():
with pytest.raises(ValueError):
Connection("CLIENT")
p = ConnectionPair()
assert p.conn[CLIENT].our_role is CLIENT
assert p.conn[CLIENT].their_role is SERVER
assert p.conn[SERVER].our_role is SERVER
assert p.conn[SERVER].their_role is CLI... | def test_Connection_basics_and_content_length():
| with pytest.raises(ValueError):
Connection("CLIENT")
p = ConnectionPair()
assert p.conn[CLIENT].our_role is CLIENT
assert p.conn[CLIENT].their_role is SERVER
assert p.conn[SERVER].our_role is SERVER
assert p.conn[SERVER].their_role is CLIENT
data = p.send(
CLIENT,
R... | r) == ("content-length", (0,))
# Transfer-encoding
for kwargs in [{"te": True}, {"cl": 100, "te": True}]:
for meth, r in [(None, req(**kwargs)), (b"GET", resp(**kwargs))]:
assert _body_framing(meth, r) == ("chunked", ())
# Content-Length
for meth, r in [(None, req(cl=100)), (b"GET... | 187 | 188 | 627 | 10 | 177 | Kludex/h11 | h11/tests/test_connection.py | Python | test_Connection_basics_and_content_length | test_Connection_basics_and_content_length | 80 | 144 | 80 | 80 | 70fb9f421fb18b6c04c1b3f6245b3e7518e0d98d | bigcode/the-stack | train |
ff0d684bef91ca6e5a33ea04 | train | function | def test_100_continue():
def setup():
p = ConnectionPair()
p.send(
CLIENT,
Request(
method="GET",
target="/",
headers=[
("Host", "example.com"),
("Content-Length", "100"),
... | def test_100_continue():
| def setup():
p = ConnectionPair()
p.send(
CLIENT,
Request(
method="GET",
target="/",
headers=[
("Host", "example.com"),
("Content-Length", "100"),
("Expect", "100-conti... | back
p.send(
SERVER,
# no header here...
[Response(status_code=204, headers=[]), EndOfMessage()],
# ...but oh look, it arrived anyway
expect=[
Response(status_code=204, headers=[("connection", "close")]),
EndOfMessage(),
],
)
for conn ... | 99 | 99 | 331 | 6 | 93 | Kludex/h11 | h11/tests/test_connection.py | Python | test_100_continue | test_100_continue | 343 | 385 | 343 | 343 | 6a37ab3d16a762a6bac464181a0c71d4932988c3 | bigcode/the-stack | train |
5709970e6299083387950821 | train | function | def test__keep_alive():
assert _keep_alive(
Request(method="GET", target="/", headers=[("Host", "Example.com")])
)
assert not _keep_alive(
Request(
method="GET",
target="/",
headers=[("Host", "Example.com"), ("Connection", "close")],
)
)
as... | def test__keep_alive():
| assert _keep_alive(
Request(method="GET", target="/", headers=[("Host", "Example.com")])
)
assert not _keep_alive(
Request(
method="GET",
target="/",
headers=[("Host", "Example.com"), ("Connection", "close")],
)
)
assert not _keep_alive(
... | pytest
from .._connection import _body_framing, _keep_alive, Connection, NEED_DATA, PAUSED
from .._events import *
from .._state import *
from .._util import LocalProtocolError, RemoteProtocolError
from .helpers import ConnectionPair, get_all_events, receive_and_get
def test__keep_alive():
| 71 | 71 | 237 | 6 | 64 | Kludex/h11 | h11/tests/test_connection.py | Python | test__keep_alive | test__keep_alive | 10 | 37 | 10 | 10 | 5b40fdde6de28c92e68da60d4fbc0d871d0e7e92 | bigcode/the-stack | train |
ffff209b1d24954f4a5c81ad | train | function | @pytest.mark.parametrize(
"data",
[
b"\x00",
b"\x20",
b"\x16\x03\x01\x00\xa5", # Typical start of a TLS Client Hello
],
)
def test_early_detection_of_invalid_request(data):
c = Connection(SERVER)
# Early detection should occur before even receiving a `\r\n`
c.receive_dat... | @pytest.mark.parametrize(
"data",
[
b"\x00",
b"\x20",
b"\x16\x03\x01\x00\xa5", # Typical start of a TLS Client Hello
],
)
def test_early_detection_of_invalid_request(data):
| c = Connection(SERVER)
# Early detection should occur before even receiving a `\r\n`
c.receive_data(data)
with pytest.raises(RemoteProtocolError):
c.next_event()
| c.next_event()
@pytest.mark.parametrize(
"data",
[
b"\x00",
b"\x20",
b"\x16\x03\x01\x00\xa5", # Typical start of a TLS Client Hello
],
)
def test_early_detection_of_invalid_request(data):
| 64 | 64 | 101 | 59 | 5 | Kludex/h11 | h11/tests/test_connection.py | Python | test_early_detection_of_invalid_request | test_early_detection_of_invalid_request | 987 | 1,000 | 987 | 995 | 23a6bf202bc35929be099f9eb1ec07c36a2f0e37 | bigcode/the-stack | train |
29811bd67a9238f375388f9f | train | function | def test_idle_receive_nothing():
# At one point this incorrectly raised an error
for role in [CLIENT, SERVER]:
c = Connection(role)
assert c.next_event() is NEED_DATA
| def test_idle_receive_nothing():
# At one point this incorrectly raised an error
| for role in [CLIENT, SERVER]:
c = Connection(role)
assert c.next_event() is NEED_DATA
| _state is ERROR
assert c.their_state is not ERROR
# This is idempotent
c.send_failed()
assert c.our_state is ERROR
assert c.their_state is not ERROR
def test_idle_receive_nothing():
# At one point this incorrectly raised an error
| 64 | 64 | 43 | 18 | 45 | Kludex/h11 | h11/tests/test_connection.py | Python | test_idle_receive_nothing | test_idle_receive_nothing | 947 | 951 | 947 | 948 | 47666046bbaf1f48117830ffdb3789f57e6ab0ef | bigcode/the-stack | train |
48fef1a97e10ee8e2fc4683c | train | function | def test_reuse_simple():
p = ConnectionPair()
p.send(
CLIENT,
[Request(method="GET", target="/", headers=[("Host", "a")]), EndOfMessage()],
)
p.send(
SERVER,
[
Response(status_code=200, headers=[(b"transfer-encoding", b"chunked")]),
EndOfMessage(),... | def test_reuse_simple():
| p = ConnectionPair()
p.send(
CLIENT,
[Request(method="GET", target="/", headers=[("Host", "a")]), EndOfMessage()],
)
p.send(
SERVER,
[
Response(status_code=200, headers=[(b"transfer-encoding", b"chunked")]),
EndOfMessage(),
],
)
for... | is *still* way too large, then *that's* a
# problem:
c.send(Response(status_code=200, headers=[]))
c.send(EndOfMessage())
c.start_next_cycle()
with pytest.raises(RemoteProtocolError):
c.next_event()
def test_reuse_simple():
| 64 | 64 | 189 | 6 | 58 | Kludex/h11 | h11/tests/test_connection.py | Python | test_reuse_simple | test_reuse_simple | 464 | 494 | 464 | 464 | c9e1a9c3a0aa05af91e5aebddb8768757065102b | bigcode/the-stack | train |
40f3fc103a98f8e2cb5d66d6 | train | function | def test_chunked():
p = ConnectionPair()
p.send(
CLIENT,
Request(
method="GET",
target="/",
headers=[("Host", "example.com"), ("Transfer-Encoding", "chunked")],
),
)
data = p.send(CLIENT, Data(data=b"1234567890", chunk_start=True, chunk_end=Tr... | def test_chunked():
| p = ConnectionPair()
p.send(
CLIENT,
Request(
method="GET",
target="/",
headers=[("Host", "example.com"), ("Transfer-Encoding", "chunked")],
),
)
data = p.send(CLIENT, Data(data=b"1234567890", chunk_start=True, chunk_end=True))
assert data... | 4567890"
data = p.send(SERVER, Data(data=b"1"), expect=[Data(data=b"1"), EndOfMessage()])
assert data == b"1"
data = p.send(SERVER, EndOfMessage(), expect=[])
assert data == b""
for conn in p.conns:
assert conn.states == {CLIENT: DONE, SERVER: DONE}
def test_chunked():
| 87 | 87 | 290 | 5 | 82 | Kludex/h11 | h11/tests/test_connection.py | Python | test_chunked | test_chunked | 147 | 175 | 147 | 147 | dcb35d3a7b536d2d3b3c395f23b9653add0489be | bigcode/the-stack | train |
ca0502a698a1f817a573939d | train | function | def test__body_framing():
def headers(cl, te):
headers = []
if cl is not None:
headers.append(("Content-Length", str(cl)))
if te:
headers.append(("Transfer-Encoding", "chunked"))
return headers
def resp(status_code=200, cl=None, te=False):
return ... | def test__body_framing():
| def headers(cl, te):
headers = []
if cl is not None:
headers.append(("Content-Length", str(cl)))
if te:
headers.append(("Transfer-Encoding", "chunked"))
return headers
def resp(status_code=200, cl=None, te=False):
return Response(status_code=statu... | _alive(
Request(method="GET", target="/", headers=[], http_version="1.0")
)
assert _keep_alive(Response(status_code=200, headers=[]))
assert not _keep_alive(Response(status_code=200, headers=[("Connection", "close")]))
assert not _keep_alive(
Response(status_code=200, headers=[("Connect... | 119 | 120 | 400 | 8 | 111 | Kludex/h11 | h11/tests/test_connection.py | Python | test__body_framing | test__body_framing | 40 | 77 | 40 | 40 | 661d8b0a8219e09ffdf94c00938dab8a92e67d58 | bigcode/the-stack | train |
3315c39cd0087561252c548d | train | function | def test_sendfile():
class SendfilePlaceholder:
def __len__(self):
return 10
placeholder = SendfilePlaceholder()
def setup(header, http_version):
c = Connection(SERVER)
receive_and_get(
c, "GET / HTTP/{}\r\nHost: a\r\n\r\n".format(http_version).encode("ascii... | def test_sendfile():
| class SendfilePlaceholder:
def __len__(self):
return 10
placeholder = SendfilePlaceholder()
def setup(header, http_version):
c = Connection(SERVER)
receive_and_get(
c, "GET / HTTP/{}\r\nHost: a\r\n\r\n".format(http_version).encode("ascii")
)
... | (),
]
assert c.states == {CLIENT: CLOSED, SERVER: SEND_RESPONSE}
c.send(Response(status_code=200, headers=[]))
c.send(EndOfMessage())
assert c.states == {CLIENT: CLOSED, SERVER: MUST_CLOSE}
c.send(ConnectionClosed())
assert c.states == {CLIENT: CLOSED, SERVER: CLOSED}
def test_sendfile():
| 78 | 78 | 261 | 5 | 73 | Kludex/h11 | h11/tests/test_connection.py | Python | test_sendfile | test_sendfile | 843 | 874 | 843 | 843 | 8873386f5453267da0fec6660f438467522c2bf2 | bigcode/the-stack | train |
c46e83e2dc5b0241a39da436 | train | function | def test_HEAD_framing_headers():
def setup(method, http_version):
c = Connection(SERVER)
c.receive_data(
method + b" / HTTP/" + http_version + b"\r\n" + b"Host: example.com\r\n\r\n"
)
assert type(c.next_event()) is Request
assert type(c.next_event()) is EndOfMessa... | def test_HEAD_framing_headers():
| def setup(method, http_version):
c = Connection(SERVER)
c.receive_data(
method + b" / HTTP/" + http_version + b"\r\n" + b"Host: example.com\r\n\r\n"
)
assert type(c.next_event()) is Request
assert type(c.next_event()) is EndOfMessage
return c
for meth... | = Connection(CLIENT)
# Early detection should occur before even receiving a `\r\n`
c.receive_data(data)
with pytest.raises(RemoteProtocolError):
c.next_event()
# This used to give different headers for HEAD and GET.
# The correct way to handle HEAD is to put whatever headers we *would* have
# put... | 102 | 102 | 340 | 8 | 94 | Kludex/h11 | h11/tests/test_connection.py | Python | test_HEAD_framing_headers | test_HEAD_framing_headers | 1,023 | 1,062 | 1,023 | 1,023 | 5df12c9bc875388c71894340df5c628d0474e7f3 | bigcode/the-stack | train |
dce46a371a11142e0017a950 | train | function | def test_chunk_boundaries():
conn = Connection(our_role=SERVER)
request = (
b"POST / HTTP/1.1\r\n"
b"Host: example.com\r\n"
b"Transfer-Encoding: chunked\r\n"
b"\r\n"
)
conn.receive_data(request)
assert conn.next_event() == Request(
method="POST",
targ... | def test_chunk_boundaries():
| conn = Connection(our_role=SERVER)
request = (
b"POST / HTTP/1.1\r\n"
b"Host: example.com\r\n"
b"Transfer-Encoding: chunked\r\n"
b"\r\n"
)
conn.receive_data(request)
assert conn.next_event() == Request(
method="POST",
target="/",
headers=[("Ho... | 200, headers=[("Transfer-Encoding", "chunked")])
)
p.send(SERVER, Data(data=b"54321", chunk_start=True, chunk_end=True))
p.send(SERVER, Data(data=b"12345", chunk_start=True, chunk_end=True))
p.send(SERVER, EndOfMessage())
for conn in p.conns:
assert conn.states == {CLIENT: DONE, SERVER: DON... | 95 | 95 | 317 | 6 | 89 | Kludex/h11 | h11/tests/test_connection.py | Python | test_chunk_boundaries | test_chunk_boundaries | 178 | 214 | 178 | 178 | ddda14e0b5cce06cc0210cac88845c6bb514edd4 | bigcode/the-stack | train |
1b4d9940d1fe3da2699cd31d | train | function | def test_empty_request():
c = Connection(SERVER)
c.receive_data(b"\r\n")
with pytest.raises(RemoteProtocolError):
c.next_event()
| def test_empty_request():
| c = Connection(SERVER)
c.receive_data(b"\r\n")
with pytest.raises(RemoteProtocolError):
c.next_event()
| # Should be able to send this spontaneously as a server without seeing
# anything from client
p = ConnectionPair()
p.send(SERVER, Response(status_code=408, headers=[(b"connection", b"close")]))
# This used to raise IndexError
def test_empty_request():
| 64 | 64 | 35 | 5 | 58 | Kludex/h11 | h11/tests/test_connection.py | Python | test_empty_request | test_empty_request | 971 | 975 | 971 | 971 | 9fe7019f770c0bd0505c6821fc255c80454bf451 | bigcode/the-stack | train |
8da2c1e622630ec2c0655401 | train | function | def test_connection_drop():
c = Connection(SERVER)
c.receive_data(b"GET /")
assert c.next_event() is NEED_DATA
c.receive_data(b"")
with pytest.raises(RemoteProtocolError):
c.next_event()
| def test_connection_drop():
| c = Connection(SERVER)
c.receive_data(b"GET /")
assert c.next_event() is NEED_DATA
c.receive_data(b"")
with pytest.raises(RemoteProtocolError):
c.next_event()
| .our_state is ERROR
assert c.their_state is not ERROR
def test_idle_receive_nothing():
# At one point this incorrectly raised an error
for role in [CLIENT, SERVER]:
c = Connection(role)
assert c.next_event() is NEED_DATA
def test_connection_drop():
| 64 | 64 | 52 | 5 | 58 | Kludex/h11 | h11/tests/test_connection.py | Python | test_connection_drop | test_connection_drop | 954 | 960 | 954 | 954 | 72b0dafef1cc07920e1010223d4b42bbf2e90ae6 | bigcode/the-stack | train |
2f4cf1dbafd28ea878aa0f4d | train | function | def test_408_request_timeout():
# Should be able to send this spontaneously as a server without seeing
# anything from client
p = ConnectionPair()
p.send(SERVER, Response(status_code=408, headers=[(b"connection", b"close")]))
| def test_408_request_timeout():
# Should be able to send this spontaneously as a server without seeing
# anything from client
| p = ConnectionPair()
p.send(SERVER, Response(status_code=408, headers=[(b"connection", b"close")]))
| (b"GET /")
assert c.next_event() is NEED_DATA
c.receive_data(b"")
with pytest.raises(RemoteProtocolError):
c.next_event()
def test_408_request_timeout():
# Should be able to send this spontaneously as a server without seeing
# anything from client
| 64 | 64 | 58 | 28 | 36 | Kludex/h11 | h11/tests/test_connection.py | Python | test_408_request_timeout | test_408_request_timeout | 963 | 967 | 963 | 965 | e86f27f7199471f10726bf28de656b7472229957 | bigcode/the-stack | train |
c806ac5da78aed197690222f | train | function | def test_max_incomplete_event_size_countermeasure():
# Infinitely long headers are definitely not okay
c = Connection(SERVER)
c.receive_data(b"GET / HTTP/1.0\r\nEndless: ")
assert c.next_event() is NEED_DATA
with pytest.raises(RemoteProtocolError):
while True:
c.receive_data(b"a"... | def test_max_incomplete_event_size_countermeasure():
# Infinitely long headers are definitely not okay
| c = Connection(SERVER)
c.receive_data(b"GET / HTTP/1.0\r\nEndless: ")
assert c.next_event() is NEED_DATA
with pytest.raises(RemoteProtocolError):
while True:
c.receive_data(b"a" * 1024)
c.next_event()
# Checking that the same header is accepted / rejected depending o... | 100 Continue
p = setup()
p.send(SERVER, InformationalResponse(status_code=100, headers=[]))
for conn in p.conns:
assert not conn.client_is_waiting_for_100_continue
assert not conn.they_are_waiting_for_100_continue
# Disabled by a real response
p = setup()
p.send(
SERVER... | 222 | 222 | 741 | 21 | 200 | Kludex/h11 | h11/tests/test_connection.py | Python | test_max_incomplete_event_size_countermeasure | test_max_incomplete_event_size_countermeasure | 388 | 461 | 388 | 389 | 117b218ec38c4be57feeb1fce694fd8994efa3ec | bigcode/the-stack | train |
4489b64fa508781eaecff00e | train | class | class ExperimentBase(object):
"""
An experiment template in order to structure the training code and take
care of saving, loading, logging, visualization stuffs. It's intended to
be flexible and simple.
So it only handles output directory (create directory for the output,
create a checkpoint di... | class ExperimentBase(object):
| """
An experiment template in order to structure the training code and take
care of saving, loading, logging, visualization stuffs. It's intended to
be flexible and simple.
So it only handles output directory (create directory for the output,
create a checkpoint directory, dump the config in us... | # Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | 209 | 256 | 1,883 | 5 | 204 | JiehangXie/PaddleSpeech | paddlespeech/t2s/training/experiment.py | Python | ExperimentBase | ExperimentBase | 29 | 308 | 29 | 29 | 1a0dd2f956568f20f3696d764bcce1f565cdb5d7 | bigcode/the-stack | train |
4f6aec898f7d656e211ca5e0 | train | class | class FeatureExtractor2D(FeatureExtractor):
def __init__(self, stride, mean, std, resize_to, crop_to, **kwargs):
super(FeatureExtractor2D, self).__init__(stride, mean, std, resize_to, crop_to, **kwargs)
self.sample_func = sample_frames_metafunc(stride)
self.preprocess_func = preprocess_fram... | class FeatureExtractor2D(FeatureExtractor):
| def __init__(self, stride, mean, std, resize_to, crop_to, **kwargs):
super(FeatureExtractor2D, self).__init__(stride, mean, std, resize_to, crop_to, **kwargs)
self.sample_func = sample_frames_metafunc(stride)
self.preprocess_func = preprocess_frame_metafunc(mean, std, resize_to, crop_to)
| X[i: i + self.batch_size]
feats_batch = self.model(X_batch)
feats_batch = feats_batch.data.cpu().numpy()
feats = feats_batch if feats is None else np.concatenate([ feats, feats_batch ], axis=0)
return feats
class FeatureExtractor2D(FeatureExtractor):
| 64 | 64 | 92 | 9 | 54 | Lechatelia/video_feature_extractor | feature_extractor.py | Python | FeatureExtractor2D | FeatureExtractor2D | 59 | 64 | 59 | 59 | 8c490a581127c516c540164d87c438e5853313df | bigcode/the-stack | train |
8f23075afb9a41566d932a31 | train | class | class FeatureExtractor3D(FeatureExtractor):
def __init__(self, stride, mean, std, resize_to, crop_to, **kwargs):
super(FeatureExtractor3D, self).__init__(stride, mean, std, resize_to, crop_to, **kwargs)
self.sample_func = sample_clips_metafunc(stride)
self.preprocess_func = preprocess_clip_... | class FeatureExtractor3D(FeatureExtractor):
| def __init__(self, stride, mean, std, resize_to, crop_to, **kwargs):
super(FeatureExtractor3D, self).__init__(stride, mean, std, resize_to, crop_to, **kwargs)
self.sample_func = sample_clips_metafunc(stride)
self.preprocess_func = preprocess_clip_metafunc(mean, std, resize_to, crop_to)
| D, self).__init__(stride, mean, std, resize_to, crop_to, **kwargs)
self.sample_func = sample_frames_metafunc(stride)
self.preprocess_func = preprocess_frame_metafunc(mean, std, resize_to, crop_to)
class FeatureExtractor3D(FeatureExtractor):
| 64 | 64 | 93 | 9 | 55 | Lechatelia/video_feature_extractor | feature_extractor.py | Python | FeatureExtractor3D | FeatureExtractor3D | 67 | 72 | 67 | 67 | f5a5683fce43ebd2d1e090c5c09bd353ccbf2017 | bigcode/the-stack | train |
4c51597715d61cfd0deff80b | train | class | class FeatureExtractor(ABC):
def __init__(self, stride, mean, std, resize_to, crop_to, *, model, batch_size):
self.model = model
self.batch_size = batch_size
@property
def sample_func(self):
if not hasattr(self, '_sample_func'):
raise NotImplementedError("You should defi... | class FeatureExtractor(ABC):
| def __init__(self, stride, mean, std, resize_to, crop_to, *, model, batch_size):
self.model = model
self.batch_size = batch_size
@property
def sample_func(self):
if not hasattr(self, '_sample_func'):
raise NotImplementedError("You should define 'sample_func'")
re... | from abc import ABC
import numpy as np
import torch
from commons import preprocess_clip_metafunc, preprocess_frame_metafunc, sample_clips_metafunc, sample_frames_metafunc
class FeatureExtractor(ABC):
| 47 | 121 | 406 | 6 | 40 | Lechatelia/video_feature_extractor | feature_extractor.py | Python | FeatureExtractor | FeatureExtractor | 9 | 56 | 9 | 9 | 3e3790b06d0c3ddc1a32696780d73f931840ef0c | bigcode/the-stack | train |
101305d16ae28b13b939b9ed | train | class | class MyHTMLParser(HTMLParser):
def __init(self, url, name):
self.url = url
self.name = name
def handle_starttag(self, tag, attrs):
print('<%s>' % tag)
def handle_endtag(self, tag):
print('</%s>' % tag)
def handle_startendtag(self, tag, attrs):
print('<%s/>' % t... | class MyHTMLParser(HTMLParser):
| def __init(self, url, name):
self.url = url
self.name = name
def handle_starttag(self, tag, attrs):
print('<%s>' % tag)
def handle_endtag(self, tag):
print('</%s>' % tag)
def handle_startendtag(self, tag, attrs):
print('<%s/>' % tag)
def handle_data(self, d... | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
from html.parser import HTMLParser
from html.entities import name2codepoint
class MyHTMLParser(HTMLParser):
| 39 | 64 | 157 | 8 | 30 | cgyqu/python_learning | HtmlParse.py | Python | MyHTMLParser | MyHTMLParser | 7 | 30 | 7 | 7 | 8621f903553d1ae954ed78899924bfda53c35a82 | bigcode/the-stack | train |
4eed222f845dbf95749035d6 | train | function | def _create_keyvault(cmd,
cli_ctx,
resource_group_name,
vault_name,
location=None,
sku=None,
enabled_for_deployment=True,
enabled_for_disk_encryption=None,
... | def _create_keyvault(cmd,
cli_ctx,
resource_group_name,
vault_name,
location=None,
sku=None,
enabled_for_deployment=True,
enabled_for_disk_encryption=None,
... | from azure.cli.core._profile import Profile
from azure.graphrbac.models import GraphErrorException
profile = Profile(cli_ctx=cli_ctx)
cred, _, tenant_id = profile.get_login_credentials(
resource=cli_ctx.cloud.endpoints.active_directory_graph_resource_id)
graph_client = GraphRbacManagementCli... | .text)['error']['details'][0]['message'] # pylint: disable=no-member
except: # pylint: disable=bare-except
pass
raise CLIError('{}'.format(message))
pem_output_folder = None
if certificate_output_folder is not None:
os.makedirs(certificate_output_folder, exis... | 256 | 256 | 893 | 61 | 195 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _create_keyvault | _create_keyvault | 1,624 | 1,719 | 1,624 | 1,634 | 5045c5bdaf9918626d179a48df2c6dc9235fdaf8 | bigcode/the-stack | train |
3ea319a4ba5d9e59d56829d4 | train | function | def _get_object_id_by_spn(graph_client, spn):
accounts = list(graph_client.service_principals.list(
filter="servicePrincipalNames/any(c:c eq '{}')".format(spn)))
if not accounts:
logger.warning("Unable to find user with spn '%s'", spn)
return None
if len(accounts) > 1:
logger... | def _get_object_id_by_spn(graph_client, spn):
| accounts = list(graph_client.service_principals.list(
filter="servicePrincipalNames/any(c:c eq '{}')".format(spn)))
if not accounts:
logger.warning("Unable to find user with spn '%s'", spn)
return None
if len(accounts) > 1:
logger.warning("Multiple service principals found wi... | current_user = graph_client.signed_in_user.get()
if current_user and current_user.object_id: # pylint:disable=no-member
return current_user.object_id # pylint:disable=no-member
except CloudError:
pass
def _get_object_id_by_spn(graph_client, spn):
| 64 | 64 | 121 | 14 | 49 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _get_object_id_by_spn | _get_object_id_by_spn | 1,732 | 1,742 | 1,732 | 1,732 | 9425bf280ac7f0d13ac55fa6bcdeb67c2b570747 | bigcode/the-stack | train |
9c4f6256f9d1edabad984c09 | train | function | def update_cluster_durability(cmd, client, resource_group_name, cluster_name, node_type, durability_level):
cli_ctx = cmd.cli_ctx
# get cluster node type durability
cluster = client.get(resource_group_name, cluster_name)
node_type_refs = [n for n in cluster.node_types if n.name.lower() == node_type.low... | def update_cluster_durability(cmd, client, resource_group_name, cluster_name, node_type, durability_level):
| cli_ctx = cmd.cli_ctx
# get cluster node type durability
cluster = client.get(resource_group_name, cluster_name)
node_type_refs = [n for n in cluster.node_types if n.name.lower() == node_type.lower()]
if not node_type_refs:
raise CLIError("Failed to find the node type in the cluster.")
... | ability_level,
reliability_required_instance_count))
# update vmss
vmss_poll = compute_client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name, vmss.name, vmss)
LongRunningOperation(cli_ctx)(vmss_poll)
# update cluster
node_type.vm_instance_count = vmss.sk... | 140 | 140 | 468 | 23 | 117 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | update_cluster_durability | update_cluster_durability | 515 | 557 | 515 | 515 | 046de84ed92b9460c15525988d891f23378c9420 | bigcode/the-stack | train |
1ea79848a7ef7be057b2b87a | train | function | def set_cluster_setting(cmd,
client,
resource_group_name,
cluster_name,
section=None,
parameter=None,
value=None,
settings_section_description=None):
... | def set_cluster_setting(cmd,
client,
resource_group_name,
cluster_name,
section=None,
parameter=None,
value=None,
settings_section_description=None):
| cli_ctx = cmd.cli_ctx
def _set(setting_dict, section, parameter, value):
if section not in setting_dict:
setting_dict[section] = {}
setting_dict[section][parameter] = value
return setting_dict
if settings_section_description and (section or parameter or value):
r... | (
'When \'--upgrade-mode\' set to \'manual\', --version must be given')
patch_request.cluster_code_version = version
patch_request.upgrade_mode = upgrade_mode
update_cluster_poll = client.begin_update(resource_group_name, cluster_name, patch_request)
return LongRunningOperation(cli_... | 105 | 105 | 352 | 36 | 69 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | set_cluster_setting | set_cluster_setting | 584 | 620 | 584 | 591 | 897be2b1f61bbb3326a4b34486a56847f8e56a12 | bigcode/the-stack | train |
25990d9951da6c7d7ae2dc61 | train | function | def _create_certificate(cmd,
cli_ctx,
resource_group_name,
certificate_file=None,
certificate_password=None,
vault_name=None,
vault_resource_group_name=None,
... | def _create_certificate(cmd,
cli_ctx,
resource_group_name,
certificate_file=None,
certificate_password=None,
vault_name=None,
vault_resource_group_name=None,
... | _verify_cert_function_parameter(certificate_file, certificate_password,
vault_name, vault_resource_group_name,
certificate_output_folder,
certificate_subject_name,
secret_i... | certificate_password:
raise CLIError(
'\'--certificate-password\' is ingored if \'--secret-identifier\' is present')
if certificate_output_folder:
raise CLIError(
'\'--certificate-output-folder\' is ingored if \'--secret-identifier\' i... | 223 | 223 | 746 | 54 | 169 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _create_certificate | _create_certificate | 1,062 | 1,145 | 1,062 | 1,071 | ed1cddca0268aa690da2e66fa59580fb0fd20dbe | bigcode/the-stack | train |
c13a6c1c850abf1e25a365e4 | train | function | def _get_keyVault_not_arm_client(cli_ctx):
from azure.cli.command_modules.keyvault._client_factory import keyvault_data_plane_factory
return keyvault_data_plane_factory(cli_ctx)
| def _get_keyVault_not_arm_client(cli_ctx):
| from azure.cli.command_modules.keyvault._client_factory import keyvault_data_plane_factory
return keyvault_data_plane_factory(cli_ctx)
| _output_folder, certificate_name + '.pfx')
_download_secret(cli_ctx, vault_base_url, certificate_name,
pem_output_folder, pfx_output_folder)
return client.get_certificate(vault_base_url, certificate_name, ''), pem_output_folder
def _get_keyVault_not_arm_client(cli_ctx):
| 64 | 64 | 39 | 11 | 52 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _get_keyVault_not_arm_client | _get_keyVault_not_arm_client | 1,619 | 1,621 | 1,619 | 1,619 | 712d2cd036b1c934c66dcf2392ae501cdcf3e033 | bigcode/the-stack | train |
5dc272788f9ea940e0f24f1b | train | function | def add_app_cert(cmd,
client,
resource_group_name,
cluster_name,
certificate_file=None,
certificate_password=None,
vault_name=None,
vault_resource_group_name=None,
certificate_output_f... | def add_app_cert(cmd,
client,
resource_group_name,
cluster_name,
certificate_file=None,
certificate_password=None,
vault_name=None,
vault_resource_group_name=None,
certificate_output_f... | cli_ctx = cmd.cli_ctx
result = _create_certificate(cmd,
cli_ctx,
resource_group_name,
certificate_file,
certificate_password,
vault_name,
... | _list)
return output_list
def add_app_cert(cmd,
client,
resource_group_name,
cluster_name,
certificate_file=None,
certificate_password=None,
vault_name=None,
vault_resource_group_name=None,
... | 64 | 64 | 150 | 57 | 6 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | add_app_cert | add_app_cert | 279 | 303 | 279 | 289 | 404e8fbb898541fee385d042e839c47b13e8972a | bigcode/the-stack | train |
f47f4064ec025a645416c4eb | train | function | def _safe_get_vault(cli_ctx, resource_group_name, vault_name):
key_vault_client = keyvault_client_factory(cli_ctx).vaults
try:
vault = key_vault_client.get(resource_group_name, vault_name)
return vault
except ResourceNotFoundError:
return None
except CloudError as ex:
if ... | def _safe_get_vault(cli_ctx, resource_group_name, vault_name):
| key_vault_client = keyvault_client_factory(cli_ctx).vaults
try:
vault = key_vault_client.get(resource_group_name, vault_name)
return vault
except ResourceNotFoundError:
return None
except CloudError as ex:
if ex.error.error == 'ResourceNotFound':
return None
... |
vault_resource_group_name = vault.id.split('/')[4]
v = client.get(vault_resource_group_name, vault.name)
vault_uri = v.properties.vault_uri
return vault_uri, vault_resource_group_name
def _safe_get_vault(cli_ctx, resource_group_name, vault_name):
| 64 | 64 | 90 | 16 | 47 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _safe_get_vault | _safe_get_vault | 1,362 | 1,372 | 1,362 | 1,362 | 6fd7030fb1234b2e95309ba2796f0294256a3ba7 | bigcode/the-stack | train |
98fbfdb971d46e81c3f6a690 | train | function | def add_client_cert(cmd,
client,
resource_group_name,
cluster_name,
is_admin=False,
thumbprint=None,
certificate_common_name=None,
certificate_issuer_thumbprint=None,
... | def add_client_cert(cmd,
client,
resource_group_name,
cluster_name,
is_admin=False,
thumbprint=None,
certificate_common_name=None,
certificate_issuer_thumbprint=None,
... | cli_ctx = cmd.cli_ctx
if thumbprint:
if certificate_common_name or certificate_issuer_thumbprint or admin_client_thumbprints or readonly_client_thumbprints or client_certificate_common_names:
raise CLIError(
"--thumbprint can only specified alone or with --is-admin")
if c... | (top_error.code, top_error.message))
if top_error.details:
for error in top_error.details:
_build_detailed_error(error, output_list)
return output_list
def add_app_cert(cmd,
client,
resource_group_name,
cluster_name,
cer... | 251 | 251 | 837 | 63 | 188 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | add_client_cert | add_client_cert | 306 | 383 | 306 | 316 | c47466eb4fb11f14fa8378db74fb8528e4222a86 | bigcode/the-stack | train |
3922ac7016b0a86ea5e26f54 | train | function | def _get_cluster_id_in_sf_extension(fabric_ext):
cluster_endpoint = fabric_ext.settings["clusterEndpoint"]
endpoint_list = cluster_endpoint.split('/')
cluster_id = endpoint_list[len(endpoint_list) - 1]
return cluster_id
| def _get_cluster_id_in_sf_extension(fabric_ext):
| cluster_endpoint = fabric_ext.settings["clusterEndpoint"]
endpoint_list = cluster_endpoint.split('/')
cluster_id = endpoint_list[len(endpoint_list) - 1]
return cluster_id
| _type in (SERVICE_FABRIC_WINDOWS_NODE_EXT_NAME, SERVICE_FABRIC_LINUX_NODE_EXT_NAME):
fabric_ext = ext
break
if fabric_ext is None or fabric_ext == []:
return None
return fabric_ext
def _get_cluster_id_in_sf_extension(fabric_ext):
| 64 | 64 | 50 | 12 | 51 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _get_cluster_id_in_sf_extension | _get_cluster_id_in_sf_extension | 1,198 | 1,202 | 1,198 | 1,198 | 98d26799cd0faf3a04a009bd01d05ef4297b15f1 | bigcode/the-stack | train |
94a52d965c10e7145d1bc00a | train | function | def _dict_to_fabric_settings(setting_dict):
settings = []
if setting_dict and any(setting_dict):
for k, v in setting_dict.items():
parameters = []
setting_des = SettingsSectionDescription(name=k, parameters=parameters)
for kk, vv in v.items():
setting_... | def _dict_to_fabric_settings(setting_dict):
| settings = []
if setting_dict and any(setting_dict):
for k, v in setting_dict.items():
parameters = []
setting_des = SettingsSectionDescription(name=k, parameters=parameters)
for kk, vv in v.items():
setting_des.parameters.append(
S... | _name not in d:
d[section_name] = {}
if s1.parameters:
for s2 in s1.parameters:
parameter_name = s2.name
d[section_name][parameter_name] = s2.value
return d
def _dict_to_fabric_settings(setting_dict):
| 64 | 64 | 99 | 10 | 53 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _dict_to_fabric_settings | _dict_to_fabric_settings | 1,274 | 1,285 | 1,274 | 1,274 | 4cd841a2f7bda3311419575ad7a228b3fde1b550 | bigcode/the-stack | train |
44a51085d2f41415d00a3ccd | train | function | def _build_detailed_error(top_error, output_list):
if output_list:
output_list.append(' Inner Error - Code: "{}" Message: "{}"'.format(top_error.code, top_error.message))
else:
output_list.append('Error - Code: "{}" Message: "{}"'.format(top_error.code, top_error.message))
if top_error.deta... | def _build_detailed_error(top_error, output_list):
| if output_list:
output_list.append(' Inner Error - Code: "{}" Message: "{}"'.format(top_error.code, top_error.message))
else:
output_list.append('Error - Code: "{}" Message: "{}"'.format(top_error.code, top_error.message))
if top_error.details:
for error in top_error.details:
... | .get(resource_group_name, cluster_name)
output_dict['certificate'] = {'certificate_file': output_file,
'vault_id': vault_id,
'certificate_identifier': certificate_uri,
'thumbprint': cert_thumbprint}
return out... | 64 | 64 | 101 | 12 | 51 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _build_detailed_error | _build_detailed_error | 266 | 276 | 266 | 266 | 5d7326b45a68589a0f8b71510d0b05a2cf114fbc | bigcode/the-stack | train |
9651ec7134a63048c55439a3 | train | function | def _get_sf_vm_extension(vmss):
fabric_ext = None
for ext in vmss.virtual_machine_profile.extension_profile.extensions:
extension_type = None
if hasattr(ext, 'type1') and ext.type1 is not None:
extension_type = ext.type1.lower()
elif hasattr(ext, 'type_properties_type') and e... | def _get_sf_vm_extension(vmss):
| fabric_ext = None
for ext in vmss.virtual_machine_profile.extension_profile.extensions:
extension_type = None
if hasattr(ext, 'type1') and ext.type1 is not None:
extension_type = ext.type1.lower()
elif hasattr(ext, 'type_properties_type') and ext.type_properties_type is not N... | [0].vault_certificates.append(
VaultCertificate(secret_url, 'my'))
poller = compute_client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name, vmss.name, vmss)
return LongRunningOperation(cli_ctx)(poller)
def _get_sf_vm_extension(vmss):
| 64 | 64 | 150 | 9 | 55 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _get_sf_vm_extension | _get_sf_vm_extension | 1,180 | 1,195 | 1,180 | 1,180 | e16a033b028eb1a036281a4072f7c3709cf28da5 | bigcode/the-stack | train |
d14a516035bb1ab153f27891 | train | function | def remove_cluster_node(cmd, client, resource_group_name, cluster_name, node_type, number_of_nodes_to_remove):
cli_ctx = cmd.cli_ctx
number_of_nodes_to_remove = int(number_of_nodes_to_remove)
if number_of_nodes_to_remove <= 0:
raise CLIError("--number-of-nodes-to-remove must be greater than 0")
... | def remove_cluster_node(cmd, client, resource_group_name, cluster_name, node_type, number_of_nodes_to_remove):
| cli_ctx = cmd.cli_ctx
number_of_nodes_to_remove = int(number_of_nodes_to_remove)
if number_of_nodes_to_remove <= 0:
raise CLIError("--number-of-nodes-to-remove must be greater than 0")
compute_client = compute_client_factory(cli_ctx)
cluster = client.get(resource_group_name, cluster_name)
... | (
resource_group_name, vmss.name, vmss)
LongRunningOperation(cli_ctx)(vmss_poll)
# update cluster
node_type.vm_instance_count = vmss.sku.capacity
patch_request = ClusterUpdateParameters(node_types=cluster.node_types)
update_cluster_poll = client.begin_update(resource_group_name, cluster_na... | 110 | 110 | 369 | 24 | 86 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | remove_cluster_node | remove_cluster_node | 482 | 512 | 482 | 482 | ac39a4159518db709d02d1e231abb9373cfe9ff8 | bigcode/the-stack | train |
b1ce22622ec65695afc62f36 | train | function | def _get_thumbprint_from_secret_identifier(cli_ctx, vault, secret_identifier):
secret_uri = urlparse(secret_identifier)
path = secret_uri.path
segment = path.split('/')
secret_name = segment[2]
secret_version = segment[3]
vault_uri_group = _get_vault_uri_and_resource_group_name(cli_ctx, vault)
... | def _get_thumbprint_from_secret_identifier(cli_ctx, vault, secret_identifier):
| secret_uri = urlparse(secret_identifier)
path = secret_uri.path
segment = path.split('/')
secret_name = segment[2]
secret_version = segment[3]
vault_uri_group = _get_vault_uri_and_resource_group_name(cli_ctx, vault)
vault_uri = vault_uri_group[0]
client_not_arm = _get_keyVault_not_arm_cl... | asn1_to_iso8601(asn1_date):
import dateutil.parser
if isinstance(asn1_date, bytes):
asn1_date = asn1_date.decode('utf-8')
return dateutil.parser.parse(asn1_date)
def _get_thumbprint_from_secret_identifier(cli_ctx, vault, secret_identifier):
| 70 | 70 | 236 | 16 | 54 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _get_thumbprint_from_secret_identifier | _get_thumbprint_from_secret_identifier | 1,382 | 1,408 | 1,382 | 1,382 | 4a2dc48e766b760574c104ea9794ef9d9d376833 | bigcode/the-stack | train |
cbcff645b73db594c15e29b8 | train | function | def _verify_cert_function_parameter(certificate_file=None,
certificate_password=None,
vault_name=None, # pylint: disable=unused-argument
vault_resource_group_name=None, # pylint: disable=unused-argument
... | def _verify_cert_function_parameter(certificate_file=None,
certificate_password=None,
vault_name=None, # pylint: disable=unused-argument
vault_resource_group_name=None, # pylint: disable=unused-argument
... | if certificate_file:
if certificate_subject_name:
raise CLIError(
'\'--certificate-subject-name\' is ingored if \'--certificate-file\' is present')
if certificate_output_folder:
raise CLIError(
'\'--certificate-output-folder\' is ingored if \'-... | ss
raise CLIError("Failed to find vmss in resource group {} for cluster id {} and node type {}".format(resource_group_name, cluster_id, node_type_name))
def _verify_cert_function_parameter(certificate_file=None,
certificate_password=None,
vault... | 101 | 101 | 339 | 65 | 36 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _verify_cert_function_parameter | _verify_cert_function_parameter | 1,022 | 1,059 | 1,022 | 1,028 | 05a95f59e86376ff6c054fbfa58b078b17f97a3f | bigcode/the-stack | train |
7cc3ce6c381bdf0e4cc6599c | train | function | def _get_certificate_name(certificate_subject_name, resource_group_name):
if certificate_subject_name is None:
certificate_name = resource_group_name
else:
certificate_name = certificate_subject_name
name = ""
for n in certificate_name:
if n.isalpha() or n == '-' or n.isdigit():... | def _get_certificate_name(certificate_subject_name, resource_group_name):
| if certificate_subject_name is None:
certificate_name = resource_group_name
else:
certificate_name = certificate_subject_name
name = ""
for n in certificate_name:
if n.isalpha() or n == '-' or n.isdigit():
name += n
certificate_name = name
if certificate_sub... | _name, deployment_name,
deployment)
return LongRunningOperation(cmd.cli_ctx)(deploy_poll)
def _get_vault_name(resource_group_name, vault_name):
if not vault_name:
return resource_group_name
return vault_name
def _get_certificate_name(certificate_subject_name, resource... | 64 | 64 | 125 | 14 | 49 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _get_certificate_name | _get_certificate_name | 1,322 | 1,339 | 1,322 | 1,322 | faf897d73cc61b179935fc63a2ed92f1bcd45990 | bigcode/the-stack | train |
c6e39d260e6ba952b2e34f52 | train | function | def _asn1_to_iso8601(asn1_date):
import dateutil.parser
if isinstance(asn1_date, bytes):
asn1_date = asn1_date.decode('utf-8')
return dateutil.parser.parse(asn1_date)
| def _asn1_to_iso8601(asn1_date):
| import dateutil.parser
if isinstance(asn1_date, bytes):
asn1_date = asn1_date.decode('utf-8')
return dateutil.parser.parse(asn1_date)
| _vault_client.get(resource_group_name, vault_name)
return vault
except ResourceNotFoundError:
return None
except CloudError as ex:
if ex.error.error == 'ResourceNotFound':
return None
raise
def _asn1_to_iso8601(asn1_date):
| 64 | 64 | 56 | 13 | 50 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _asn1_to_iso8601 | _asn1_to_iso8601 | 1,375 | 1,379 | 1,375 | 1,375 | 296bd0a5d6973272cfbdb1194c5d7816c98dcf9b | bigcode/the-stack | train |
d831bca6e594a9baa523e90c | train | function | def _add_cert_to_vmss(cli_ctx, vmss, resource_group_name, vault_id, secret_url):
compute_client = compute_client_factory(cli_ctx)
secrets = [
s for s in vmss.virtual_machine_profile.os_profile.secrets if s.source_vault.id == vault_id]
if secrets is None or secrets == []:
if vmss.virtual_mach... | def _add_cert_to_vmss(cli_ctx, vmss, resource_group_name, vault_id, secret_url):
| compute_client = compute_client_factory(cli_ctx)
secrets = [
s for s in vmss.virtual_machine_profile.os_profile.secrets if s.source_vault.id == vault_id]
if secrets is None or secrets == []:
if vmss.virtual_machine_profile.os_profile.secrets is None:
vmss.virtual_machine_profile.... | _file = result[1]
vault_id = vault.id
secret_url = kv_result.sid
import base64
certificate_thumbprint = b64_to_hex(
base64.b64encode(kv_result.x509_thumbprint))
return vault_id, secret_url, certificate_thumbprint, output_file
# pylint: disable=incon... | 98 | 98 | 328 | 23 | 74 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _add_cert_to_vmss | _add_cert_to_vmss | 1,149 | 1,177 | 1,149 | 1,149 | 73a93ca592cd09b46b6b67f15890eb1053d9a3d2 | bigcode/the-stack | train |
00fe6469dae7ebac0d750b72 | train | function | def _create_vmss(cmd, resource_group_name, cluster_name, cluster, node_type_name, durability_level, vm_password, vm_user_name, vm_sku, vm_tier, capacity):
cli_ctx = cmd.cli_ctx
subnet_name = "subnet_{}".format(1)
network_client = network_client_factory(cli_ctx)
location = _get_resource_group_by_name(cli... | def _create_vmss(cmd, resource_group_name, cluster_name, cluster, node_type_name, durability_level, vm_password, vm_user_name, vm_sku, vm_tier, capacity):
| cli_ctx = cmd.cli_ctx
subnet_name = "subnet_{}".format(1)
network_client = network_client_factory(cli_ctx)
location = _get_resource_group_by_name(cli_ctx, resource_group_name).location
virtual_network = list(
network_client.virtual_networks.list(resource_group_name))[0]
subnets = list(ne... | durability_level, vm_password, vm_user_name, vm_sku, vm_tier, capacity)
return client.get(resource_group_name, cluster_name)
def _add_node_type_to_sfrp(cmd, client, resource_group_name, cluster_name, cluster, node_type_name, capacity, durability_level):
cluster.node_types.append(NodeTypeDescription(name=nod... | 256 | 256 | 2,747 | 40 | 216 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _create_vmss | _create_vmss | 739 | 1,006 | 739 | 739 | 46c66873dd5101de2cd687609a982f821120f943 | bigcode/the-stack | train |
07684cf7aacfca33e078c7d6 | train | function | def _get_default_policy(cli_ctx, subject):
if subject.lower().startswith('cn') is not True:
subject = "CN={0}".format(subject)
return _default_certificate_profile(cli_ctx, subject)
| def _get_default_policy(cli_ctx, subject):
| if subject.lower().startswith('cn') is not True:
subject = "CN={0}".format(subject)
return _default_certificate_profile(cli_ctx, subject)
| with open(pfx_path, 'wb') as f:
f.write(decoded)
except Exception as ex: # pylint: disable=broad-except
if os.path.isfile(pfx_path):
os.remove(pfx_path)
raise ex
def _get_default_policy(cli_ctx, subject):
| 64 | 64 | 45 | 10 | 53 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _get_default_policy | _get_default_policy | 1,532 | 1,535 | 1,532 | 1,532 | 96359e54391af633955c11f9596c4db7310bd60d | bigcode/the-stack | train |
05557e91764e667fecfa6985 | train | function | def _get_vault_uri_and_resource_group_name(cli_ctx, vault):
client = keyvault_client_factory(cli_ctx).vaults
vault_resource_group_name = vault.id.split('/')[4]
v = client.get(vault_resource_group_name, vault.name)
vault_uri = v.properties.vault_uri
return vault_uri, vault_resource_group_name
| def _get_vault_uri_and_resource_group_name(cli_ctx, vault):
| client = keyvault_client_factory(cli_ctx).vaults
vault_resource_group_name = vault.id.split('/')[4]
v = client.get(vault_resource_group_name, vault.name)
vault_uri = v.properties.vault_uri
return vault_uri, vault_resource_group_name
| .name.lower() == vault_name.lower()]
if vault:
return vault[0]
raise CLIError("Unable to find vault with name '{}'. Please make sure the secret identifier '{}' is correct.".format(vault_name, secret_identifier))
def _get_vault_uri_and_resource_group_name(cli_ctx, vault):
| 64 | 64 | 75 | 15 | 49 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _get_vault_uri_and_resource_group_name | _get_vault_uri_and_resource_group_name | 1,354 | 1,359 | 1,354 | 1,354 | fe1f0386a3394054c6d4ab4281428719601b7479 | bigcode/the-stack | train |
b081510bce58f91f9dd848ab | train | function | def _create_self_signed_key_vault_certificate(cli_ctx, vault_base_url, certificate_name, certificate_policy, certificate_output_folder=None, disabled=False, tags=None, validity=None):
CertificateAttributes = get_sdk(cli_ctx, ResourceType.DATA_KEYVAULT, 'models.certificate_attributes#CertificateAttributes')
cert... | def _create_self_signed_key_vault_certificate(cli_ctx, vault_base_url, certificate_name, certificate_policy, certificate_output_folder=None, disabled=False, tags=None, validity=None):
| CertificateAttributes = get_sdk(cli_ctx, ResourceType.DATA_KEYVAULT, 'models.certificate_attributes#CertificateAttributes')
cert_attrs = CertificateAttributes(enabled=not disabled)
logger.info("Starting long-running operation 'keyvault certificate create'")
if validity is not None:
certificate_p... | Type.key_encipherment,
KeyUsageType.key_agreement,
KeyUsageType.key_cert_sign],
... | 131 | 131 | 437 | 36 | 94 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _create_self_signed_key_vault_certificate | _create_self_signed_key_vault_certificate | 1,573 | 1,616 | 1,573 | 1,573 | 4c8daeb494fd884a92a2a709428294df2e194670 | bigcode/the-stack | train |
319c5ccaadf085f8b31b3ff5 | train | function | def add_cluster_node_type(cmd,
client,
resource_group_name,
cluster_name,
node_type,
capacity,
vm_user_name,
vm_password,
... | def add_cluster_node_type(cmd,
client,
resource_group_name,
cluster_name,
node_type,
capacity,
vm_user_name,
vm_password,
... | if durability_level.lower() == 'gold':
if vm_sku.lower() != 'standard_d15_v2' and vm_sku.lower() != 'standard_g5':
raise CLIError(
'Only Standard_D15_v2 and Standard_G5 supports Gold durability, please specify --vm-sku to right value')
cluster = client.get(resource_group_name... | patch_request)
return LongRunningOperation(cli_ctx)(update_cluster_poll)
def add_cluster_node_type(cmd,
client,
resource_group_name,
cluster_name,
node_type,
capacity,
... | 78 | 78 | 260 | 63 | 15 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | add_cluster_node_type | add_cluster_node_type | 697 | 719 | 697 | 707 | 21b1e69bfb9f80840d8ce28098ce63f7ccc70c6d | bigcode/the-stack | train |
a2abd5f7d26f068db1b194d4 | train | function | def _get_cluster_vmss_by_node_type(compute_client, resource_group_name, cluster_id, node_type_name):
vmsses = list(compute_client.virtual_machine_scale_sets.list(resource_group_name))
for vmss in vmsses:
fabric_ext = _get_sf_vm_extension(vmss)
if fabric_ext is not None:
curr_cluste... | def _get_cluster_vmss_by_node_type(compute_client, resource_group_name, cluster_id, node_type_name):
| vmsses = list(compute_client.virtual_machine_scale_sets.list(resource_group_name))
for vmss in vmsses:
fabric_ext = _get_sf_vm_extension(vmss)
if fabric_ext is not None:
curr_cluster_id = _get_cluster_id_in_sf_extension(fabric_ext)
if curr_cluster_id.lower() == cluster_i... | provision=False,
upgrade_policy=UpgradePolicy(mode=UpgradeMode.automatic),
virtual_machine_profile=virtual_machine_sca... | 64 | 64 | 153 | 24 | 40 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _get_cluster_vmss_by_node_type | _get_cluster_vmss_by_node_type | 1,009 | 1,019 | 1,009 | 1,010 | bd9c6036c358b386f5e49ad37c76fc02b2e9f23b | bigcode/the-stack | train |
5d34bf06e8169e6a6e133643 | train | function | def new_cluster(cmd,
client,
resource_group_name,
location=None,
certificate_subject_name=None,
parameter_file=None,
template_file=None,
cluster_name=None,
vault_resource_group_name=None,
... | def new_cluster(cmd,
client,
resource_group_name,
location=None,
certificate_subject_name=None,
parameter_file=None,
template_file=None,
cluster_name=None,
vault_resource_group_name=None,
... | cli_ctx = cmd.cli_ctx
if certificate_subject_name is None and certificate_file is None and secret_identifier is None:
raise CLIError(
'\'--certificate-subject-name\', \'--certificate-file\', \'--secret-identifier\', one of them must be specified')
if certificate_output_folder and certifi... | isk",
'WindowsServer1803withContainers': "Datacenter-Core-1803-with-Containers-smalldisk",
'WindowsServer1809withContainers': "Datacenter-Core-1809-with-Containers-smalldisk",
'WindowsServer2019Datacenter': "2019-Datacenter",
'WindowsServer2019DatacenterwithContainers': "2019-Dat... | 256 | 256 | 1,261 | 98 | 157 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | new_cluster | new_cluster | 119 | 263 | 119 | 137 | 9910cac597ee70047aeaacb8d6d041f86b0a7a89 | bigcode/the-stack | train |
a65d1776c277713f52110d4d | train | function | def import_certificate(cli_ctx, vault_base_url, certificate_name, certificate_data,
disabled=False, password=None, certificate_policy=None, tags=None):
CertificateAttributes = get_sdk(cli_ctx, ResourceType.DATA_KEYVAULT, 'models.certificate_attributes#CertificateAttributes')
CertificatePo... | def import_certificate(cli_ctx, vault_base_url, certificate_name, certificate_data,
disabled=False, password=None, certificate_policy=None, tags=None):
| CertificateAttributes = get_sdk(cli_ctx, ResourceType.DATA_KEYVAULT, 'models.certificate_attributes#CertificateAttributes')
CertificatePolicy = get_sdk(cli_ctx, ResourceType.DATA_KEYVAULT, 'models.certificate_policy#CertificatePolicy')
SecretProperties = get_sdk(cli_ctx, ResourceType.DATA_KEYVAULT, 'models.... | secret_version)
cert_bytes = secret.value
x509 = None
import base64
decoded = base64.b64decode(cert_bytes)
try:
x509 = crypto.load_pkcs12(decoded).get_certificate()
except (ValueError, crypto.Error):
pass
if not x509:
x509 = crypto.load_certificate(crypto.FILETYPE_P... | 196 | 196 | 655 | 30 | 165 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | import_certificate | import_certificate | 1,417 | 1,491 | 1,417 | 1,418 | 80e0efa21b41c95fd5b7ff8f84343999f4803dcb | bigcode/the-stack | train |
ee5ff3db8caa7fae89c0102a | train | function | def _modify_template(linux):
_, template_file = _get_template_file_and_parameters_file(linux)
template = get_file_json(template_file)
return template
| def _modify_template(linux):
| _, template_file = _get_template_file_and_parameters_file(linux)
template = get_file_json(template_file)
return template
| \',\'certificateUrlValue\',' +
'if the secondary certificate parameters are specified in the parameters file, the parameters names should be specified with' + '\'secSourceVaultValue\',\'secCertificateThumbprint\',\'secCertificateUrlValue\'')
return parameters, output_file
def _modify_temp... | 64 | 64 | 35 | 7 | 56 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _modify_template | _modify_template | 1,887 | 1,890 | 1,887 | 1,887 | 7365e271108ce0700aa68f74a0566135e7604295 | bigcode/the-stack | train |
ce7ebe03e8f37f8c45b58a37 | train | function | def _get_certificate(client, vault_base_url, certificate_name):
""" Download a certificate from a KeyVault. """
cert = client.get_certificate(vault_base_url, certificate_name, '')
return cert
| def _get_certificate(client, vault_base_url, certificate_name):
| """ Download a certificate from a KeyVault. """
cert = client.get_certificate(vault_base_url, certificate_name, '')
return cert
| .load_certificate(crypto.FILETYPE_PEM, cert_bytes)
if not x509:
raise Exception('invalid certificate')
thumbprint = x509.digest("sha1").decode("utf-8").replace(':', '')
return thumbprint
def _get_certificate(client, vault_base_url, certificate_name):
| 64 | 64 | 43 | 13 | 50 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _get_certificate | _get_certificate | 1,411 | 1,414 | 1,411 | 1,411 | 60d7fbca55ab268b6eef53058ff3367ed5a78e49 | bigcode/the-stack | train |
305e08f3e0f1f576dca24f0e | train | function | def _default_certificate_profile(cli_ctx, subject):
CertificateAttributes = get_sdk(cli_ctx, ResourceType.DATA_KEYVAULT, 'models.certificate_attributes#CertificateAttributes')
CertificatePolicy = get_sdk(cli_ctx, ResourceType.DATA_KEYVAULT, 'models.certificate_policy#CertificatePolicy')
ActionType = get_sdk... | def _default_certificate_profile(cli_ctx, subject):
| CertificateAttributes = get_sdk(cli_ctx, ResourceType.DATA_KEYVAULT, 'models.certificate_attributes#CertificateAttributes')
CertificatePolicy = get_sdk(cli_ctx, ResourceType.DATA_KEYVAULT, 'models.certificate_policy#CertificatePolicy')
ActionType = get_sdk(cli_ctx, ResourceType.DATA_KEYVAULT, 'models.key_va... | fx_path:
try:
import base64
decoded = base64.b64decode(secret_value)
p12 = crypto.load_pkcs12(decoded)
with open(pfx_path, 'wb') as f:
f.write(decoded)
except Exception as ex: # pylint: disable=broad-except
if os.path.isfile(pf... | 142 | 142 | 476 | 10 | 132 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _default_certificate_profile | _default_certificate_profile | 1,538 | 1,570 | 1,538 | 1,538 | 81e8f4ad28551bc8b804dc369626cafa1e156cb9 | bigcode/the-stack | train |
8993834a2c90474286c9c71e | train | function | def _get_template_file_and_parameters_file(linux=None):
script_dir = os.path.dirname(os.path.realpath(__file__))
template_parameter_folder = ""
if linux:
template_parameter_folder = os.path.join('template', 'linux')
else:
template_parameter_folder = os.path.join('template', 'windows')
... | def _get_template_file_and_parameters_file(linux=None):
| script_dir = os.path.dirname(os.path.realpath(__file__))
template_parameter_folder = ""
if linux:
template_parameter_folder = os.path.join('template', 'linux')
else:
template_parameter_folder = os.path.join('template', 'windows')
parameter_file = os.path.join(
script_dir, tem... | if spn:
return _get_object_id_by_spn(graph_client, spn)
if upn:
return _get_object_id_by_upn(graph_client, upn)
return _get_object_id_from_subscription(graph_client, subscription)
def _get_template_file_and_parameters_file(linux=None):
| 64 | 64 | 115 | 12 | 52 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _get_template_file_and_parameters_file | _get_template_file_and_parameters_file | 1,779 | 1,790 | 1,779 | 1,779 | 3c67b29a91dc6423d1bd531b8eb399860a814650 | bigcode/the-stack | train |
f02419c9738a2de3cddca141 | train | function | def _get_vault_name(resource_group_name, vault_name):
if not vault_name:
return resource_group_name
return vault_name
| def _get_vault_name(resource_group_name, vault_name):
| if not vault_name:
return resource_group_name
return vault_name
| .validate, resource_group_name, deployment_name, deployment)
deploy_poll = sdk_no_wait(no_wait, client.deployments.begin_create_or_update, resource_group_name, deployment_name,
deployment)
return LongRunningOperation(cmd.cli_ctx)(deploy_poll)
def _get_vault_name(resource_group_nam... | 64 | 64 | 30 | 13 | 51 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _get_vault_name | _get_vault_name | 1,316 | 1,319 | 1,316 | 1,316 | 6692015643e525d37f7ea53e0ed33e7089dff1ba | bigcode/the-stack | train |
bc8fe1523bcd11fa8402ecd9 | train | function | def remove_cluster_setting(cmd,
client,
resource_group_name,
cluster_name,
section=None,
parameter=None,
settings_section_description=None):
cli_ctx = cmd... | def remove_cluster_setting(cmd,
client,
resource_group_name,
cluster_name,
section=None,
parameter=None,
settings_section_description=None):
| cli_ctx = cmd.cli_ctx
def _remove(setting_dict, section, parameter):
if section not in setting_dict:
raise CLIError(
"Can't find the section {} in the settings".format(section))
if parameter not in setting_dict[section]:
raise CLIError(
"C... | (setting_dict, section, parameter, value)
settings = _dict_to_fabric_settings(setting_dict)
patch_request = ClusterUpdateParameters(fabric_settings=settings)
update_cluster_poll = client.begin_update(resource_group_name, cluster_name, patch_request)
return LongRunningOperation(cli_ctx)(update_cluster_po... | 95 | 95 | 318 | 32 | 63 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | remove_cluster_setting | remove_cluster_setting | 623 | 659 | 623 | 629 | e641d374da4ed928a21a45522ba2fa711289469a | bigcode/the-stack | train |
836fd6ad9157c61a4709c6f2 | train | function | def _get_current_user_object_id(graph_client):
try:
current_user = graph_client.signed_in_user.get()
if current_user and current_user.object_id: # pylint:disable=no-member
return current_user.object_id # pylint:disable=no-member
except CloudError:
pass
| def _get_current_user_object_id(graph_client):
| try:
current_user = graph_client.signed_in_user.get()
if current_user and current_user.object_id: # pylint:disable=no-member
return current_user.object_id # pylint:disable=no-member
except CloudError:
pass
| kv_poll = keyvault_client.vaults.begin_create_or_update(resource_group_name=resource_group_name,
vault_name=vault_name,
parameters=parameters)
return LongRunningOperation(cli_ctx)(kv_poll)
# p... | 64 | 64 | 63 | 10 | 53 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _get_current_user_object_id | _get_current_user_object_id | 1,723 | 1,729 | 1,723 | 1,723 | 71f597bd4c41ce76b4aea4335526a3a9fb3804ea | bigcode/the-stack | train |
4fe55dad2c387ff2e9c9fc08 | train | function | def add_cluster_node(cmd, client, resource_group_name, cluster_name, node_type, number_of_nodes_to_add):
cli_ctx = cmd.cli_ctx
number_of_nodes_to_add = int(number_of_nodes_to_add)
if number_of_nodes_to_add <= 0:
raise CLIError("--number-of-nodes-to-add must be greater than 0")
compute_client = c... | def add_cluster_node(cmd, client, resource_group_name, cluster_name, node_type, number_of_nodes_to_add):
| cli_ctx = cmd.cli_ctx
number_of_nodes_to_add = int(number_of_nodes_to_add)
if number_of_nodes_to_add <= 0:
raise CLIError("--number-of-nodes-to-add must be greater than 0")
compute_client = compute_client_factory(cli_ctx)
cluster = client.get(resource_group_name, cluster_name)
node_types... | client_certificate_common_names is invalid')
patch_request = ClusterUpdateParameters(client_certificate_thumbprints=cluster.client_certificate_thumbprints,
client_certificate_common_names=cluster.client_certificate_common_names)
update_cluster_poll = client.begin_upd... | 91 | 91 | 304 | 24 | 67 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | add_cluster_node | add_cluster_node | 454 | 479 | 454 | 454 | 7e0f46dedc7dce81624d283d43048270da9256b7 | bigcode/the-stack | train |
53678378984e273a1f62aa2b | train | function | def list_cluster(client, resource_group_name=None):
cluster_list = client.list_by_resource_group(resource_group_name=resource_group_name) \
if resource_group_name else client.list()
return cluster_list
| def list_cluster(client, resource_group_name=None):
| cluster_list = client.list_by_resource_group(resource_group_name=resource_group_name) \
if resource_group_name else client.list()
return cluster_list
| "Datacenter-Core-1809-with-Containers-smalldisk",
'WindowsServer2019Datacenter': "2019-Datacenter",
'WindowsServer2019DatacenterwithContainers': "2019-Datacenter-Core-with-Containers"}
def list_cluster(client, resource_group_name=None):
| 63 | 64 | 42 | 10 | 53 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | list_cluster | list_cluster | 112 | 115 | 112 | 112 | 84434f0dd9c82f15ff74edf3325f3ec1111ef0bf | bigcode/the-stack | train |
927b8db2d4c15fc91cb306f0 | train | function | def _get_vault_from_secret_identifier(cli_ctx, secret_identifier):
key_vault_client = keyvault_client_factory(cli_ctx).vaults
vault_name = urlparse(secret_identifier).hostname.split('.')[0]
vaults = key_vault_client.list()
if vaults is not None:
vault = [v for v in vaults if v.name.lower() == va... | def _get_vault_from_secret_identifier(cli_ctx, secret_identifier):
| key_vault_client = keyvault_client_factory(cli_ctx).vaults
vault_name = urlparse(secret_identifier).hostname.split('.')[0]
vaults = key_vault_client.list()
if vaults is not None:
vault = [v for v in vaults if v.name.lower() == vault_name.lower()]
if vault:
return vault[0]
... | :
import datetime
suffix = datetime.datetime.now().strftime("%Y%m%d%H%M")
certificate_name = "{}{}".format(certificate_name, suffix)
return certificate_name
# pylint: disable=inconsistent-return-statements
def _get_vault_from_secret_identifier(cli_ctx, secret_identifier):
| 64 | 64 | 123 | 14 | 49 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _get_vault_from_secret_identifier | _get_vault_from_secret_identifier | 1,343 | 1,351 | 1,343 | 1,343 | e4cd61b66cd6898399b143d1a7608ffcef275c79 | bigcode/the-stack | train |
307fc1add10e376e90afd875 | train | function | def _get_reliability_level(cluster_size):
size = int(cluster_size)
if 0 < size < 3:
return 'None'
if 3 <= size < 5:
return 'Bronze'
if 5 <= size < 7:
return 'Silver'
if 7 <= size < 9:
return 'Gold'
if size >= 9:
return 'Platinum'
| def _get_reliability_level(cluster_size):
| size = int(cluster_size)
if 0 < size < 3:
return 'None'
if 3 <= size < 5:
return 'Bronze'
if 5 <= size < 7:
return 'Silver'
if 7 <= size < 9:
return 'Gold'
if size >= 9:
return 'Platinum'
| ze':
return 3
if level == 'silver':
return 5
if level == 'gold':
return 7
if level == 'platinum':
return 9
# pylint: disable=inconsistent-return-statements
def _get_reliability_level(cluster_size):
| 64 | 64 | 91 | 10 | 53 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _get_reliability_level | _get_reliability_level | 1,246 | 1,257 | 1,246 | 1,246 | e94b997dc92a8b347f0b83ae9fe9ea2e613e8c45 | bigcode/the-stack | train |
db88c38875f1336da28650b5 | train | function | def _set_parameters_for_customize_template(cmd,
cli_ctx,
resource_group_name,
certificate_file,
certificate_password,
... | def _set_parameters_for_customize_template(cmd,
cli_ctx,
resource_group_name,
certificate_file,
certificate_password,
... | parameters = get_file_json(parameter_file)['parameters']
if parameters is None:
raise CLIError('Invalid parameters file')
if SOURCE_VAULT_VALUE in parameters and CERTIFICATE_THUMBPRINT in parameters and CERTIFICATE_URL_VALUE in parameters:
logger.info('Found primary certificate parameters in... | value']['value'] = vault_id
parameters['certificateUrlvalue']['value'] = certificate_id
parameters['reliabilityLevel']['value'] = reliability_level
parameters['nt0InstanceCount']['value'] = int(cluster_size)
parameters['durabilityLevel']['value'] = durability_level
parameters['vmSku']['value'] = vm_... | 177 | 177 | 593 | 54 | 122 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _set_parameters_for_customize_template | _set_parameters_for_customize_template | 1,827 | 1,884 | 1,827 | 1,837 | 4e021042088e2b848b10f413b28f70dd94fcf9a8 | bigcode/the-stack | train |
355c31b1f55baa0703d05677 | train | function | def _download_secret(cli_ctx, vault_base_url, secret_name, pem_path, pfx_path, secret_version=''):
client = _get_keyVault_not_arm_client(cli_ctx)
secret = client.get_secret(vault_base_url, secret_name, secret_version)
secret_value = secret.value
if pem_path:
try:
import base64
... | def _download_secret(cli_ctx, vault_base_url, secret_name, pem_path, pfx_path, secret_version=''):
| client = _get_keyVault_not_arm_client(cli_ctx)
secret = client.get_secret(vault_base_url, secret_name, secret_version)
secret_value = secret.value
if pem_path:
try:
import base64
decoded = base64.b64decode(secret_value)
p12 = crypto.load_pkcs12(decoded)
... | client_not_arm.import_certificate(cli_ctx=cli_ctx,
vault_base_url=vault_base_url,
certificate_name=certificate_name,
base64_encoded_certificate=certificate_data,
... | 99 | 99 | 330 | 25 | 73 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _download_secret | _download_secret | 1,494 | 1,529 | 1,494 | 1,494 | 4604d365b3acfc4e528fb368e818a3b6685bc7ed | bigcode/the-stack | train |
784ab17a9ad892ce0f9d386c | train | function | def _get_object_id_from_subscription(graph_client, subscription):
if subscription['user']:
if subscription['user']['type'] == 'user':
return _get_object_id_by_upn(graph_client, subscription['user']['name'])
if subscription['user']['type'] == 'servicePrincipal':
return _get_ob... | def _get_object_id_from_subscription(graph_client, subscription):
| if subscription['user']:
if subscription['user']['type'] == 'user':
return _get_object_id_by_upn(graph_client, subscription['user']['name'])
if subscription['user']['type'] == 'servicePrincipal':
return _get_object_id_by_spn(graph_client, subscription['user']['name'])
... |
if len(accounts) > 1:
logger.warning("Multiple users principals found with upn '%s'. "
"You can avoid this by specifying object id.", upn)
return None
return accounts[0].object_id
def _get_object_id_from_subscription(graph_client, subscription):
| 64 | 64 | 127 | 12 | 51 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _get_object_id_from_subscription | _get_object_id_from_subscription | 1,758 | 1,768 | 1,758 | 1,758 | d2b1df0c36530f37ff099ae254b0e6e6b86ab049 | bigcode/the-stack | train |
7681f9c7fd6a6cf229ef041e | train | function | def _get_target_instance(reliability_level):
level = reliability_level.lower()
if level == 'none':
return 1
if level == 'bronze':
return 3
if level == 'silver':
return 5
if level == 'gold':
return 7
if level == 'platinum':
return 9
| def _get_target_instance(reliability_level):
| level = reliability_level.lower()
if level == 'none':
return 1
if level == 'bronze':
return 3
if level == 'silver':
return 5
if level == 'gold':
return 7
if level == 'platinum':
return 9
| =_add_cert_to_vmss, args=[cli_ctx, vmss, resource_group_name, vault_id, secret_url])
t.start()
threads.append(t)
for t in threads:
t.join()
# pylint: disable=inconsistent-return-statements
def _get_target_instance(reliability_level):
| 64 | 64 | 79 | 10 | 53 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _get_target_instance | _get_target_instance | 1,231 | 1,242 | 1,231 | 1,231 | 3eb6c52e6210ec1063c2065976afe2c136633c87 | bigcode/the-stack | train |
ac92a3b20623abac40053af0 | train | function | def _set_parameters_for_default_template(cluster_location,
cluster_name,
admin_password,
certificate_thumbprint,
vault_id,
... | def _set_parameters_for_default_template(cluster_location,
cluster_name,
admin_password,
certificate_thumbprint,
vault_id,
... | parameter_file, _ = _get_template_file_and_parameters_file(linux)
parameters = get_file_json(parameter_file)['parameters']
if parameters is None:
raise CLIError('Invalid parameters file')
parameters['clusterLocation']['value'] = cluster_location
parameters['clusterName']['value'] = cluster_n... | template_file = os.path.join(
script_dir, template_parameter_folder, 'template.json')
return parameter_file, template_file
def _set_parameters_for_default_template(cluster_location,
cluster_name,
admin_password,
... | 87 | 87 | 292 | 59 | 27 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _set_parameters_for_default_template | _set_parameters_for_default_template | 1,793 | 1,824 | 1,793 | 1,805 | 935b27ab28f790e01be8f8573701d94b807190ee | bigcode/the-stack | train |
e5350e29b1baec3e11dc6ee8 | train | function | def _get_object_id(graph_client, subscription=None, spn=None, upn=None):
if spn:
return _get_object_id_by_spn(graph_client, spn)
if upn:
return _get_object_id_by_upn(graph_client, upn)
return _get_object_id_from_subscription(graph_client, subscription)
| def _get_object_id(graph_client, subscription=None, spn=None, upn=None):
| if spn:
return _get_object_id_by_spn(graph_client, spn)
if upn:
return _get_object_id_by_upn(graph_client, upn)
return _get_object_id_from_subscription(graph_client, subscription)
| Unknown user type '%s'",
subscription['user']['type'])
else:
logger.warning('Current credentials are not from a user or service principal. '
'Azure Key Vault does not work with certificate credentials.')
def _get_object_id(graph_client, subscription=None, spn=No... | 63 | 64 | 72 | 19 | 44 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _get_object_id | _get_object_id | 1,771 | 1,776 | 1,771 | 1,771 | 6eadf95833158a1c4dec888986b0811ed9915d97 | bigcode/the-stack | train |
8b5e0336f18f1bfadd195718 | train | function | def update_cluster_reliability_level(cmd,
client,
resource_group_name,
cluster_name, reliability_level,
auto_add_node=False):
cli_ctx = cmd.cli_ctx
reliability_leve... | def update_cluster_reliability_level(cmd,
client,
resource_group_name,
cluster_name, reliability_level,
auto_add_node=False):
| cli_ctx = cmd.cli_ctx
reliability_level = reliability_level.lower()
cluster = client.get(resource_group_name, cluster_name)
instance_now = _get_target_instance(cluster.reliability_level)
instance_target = _get_target_instance(reliability_level)
node_types = [n for n in cluster.node_types if n.is... | raise CLIError('settings_section_description is invalid')
else:
setting_dict = _remove(setting_dict, section, parameter)
settings = _dict_to_fabric_settings(setting_dict)
patch_request = ClusterUpdateParameters(fabric_settings=settings)
update_cluster_poll = client.begin_update(... | 111 | 111 | 371 | 30 | 81 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | update_cluster_reliability_level | update_cluster_reliability_level | 662 | 694 | 662 | 666 | a27535b8e9a7ec6a967c7af6b5c7124732a8d9a4 | bigcode/the-stack | train |
8214eafe2cf86bdd2c09dc2b | train | function | def _fabric_settings_to_dict(fabric_settings):
d = {}
if fabric_settings:
for s1 in fabric_settings:
section_name = s1.name
if section_name not in d:
d[section_name] = {}
if s1.parameters:
for s2 in s1.parameters:
pa... | def _fabric_settings_to_dict(fabric_settings):
| d = {}
if fabric_settings:
for s1 in fabric_settings:
section_name = s1.name
if section_name not in d:
d[section_name] = {}
if s1.parameters:
for s2 in s1.parameters:
parameter_name = s2.name
d[se... | size < 5:
return 'Bronze'
if 5 <= size < 7:
return 'Silver'
if 7 <= size < 9:
return 'Gold'
if size >= 9:
return 'Platinum'
def _fabric_settings_to_dict(fabric_settings):
| 64 | 64 | 92 | 10 | 54 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _fabric_settings_to_dict | _fabric_settings_to_dict | 1,260 | 1,271 | 1,260 | 1,260 | 1745db8ffd668b8ce18efe51358aa9c45bb89151 | bigcode/the-stack | train |
284592f489f4e3ffb3f8e618 | train | function | def _add_cert_to_all_vmss(cli_ctx, resource_group_name, cluster_id, vault_id, secret_url, is_cluster_cert=False, thumbprint=None):
threads = []
import threading
compute_client = compute_client_factory(cli_ctx)
vmsses = list(compute_client.virtual_machine_scale_sets.list(resource_group_name))
if vmss... | def _add_cert_to_all_vmss(cli_ctx, resource_group_name, cluster_id, vault_id, secret_url, is_cluster_cert=False, thumbprint=None):
| threads = []
import threading
compute_client = compute_client_factory(cli_ctx)
vmsses = list(compute_client.virtual_machine_scale_sets.list(resource_group_name))
if vmsses is not None:
for vmss in vmsses:
fabric_ext = _get_sf_vm_extension(vmss)
if fabric_ext is not No... | _ext):
cluster_endpoint = fabric_ext.settings["clusterEndpoint"]
endpoint_list = cluster_endpoint.split('/')
cluster_id = endpoint_list[len(endpoint_list) - 1]
return cluster_id
def _add_cert_to_all_vmss(cli_ctx, resource_group_name, cluster_id, vault_id, secret_url, is_cluster_cert=False, thumbprint=No... | 73 | 73 | 244 | 33 | 39 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _add_cert_to_all_vmss | _add_cert_to_all_vmss | 1,205 | 1,227 | 1,205 | 1,205 | d5872dfb65ba0cf7f445fad8a4b09f28e6a7fb22 | bigcode/the-stack | train |
28122023db29480201297baf | train | function | def _add_node_type_to_sfrp(cmd, client, resource_group_name, cluster_name, cluster, node_type_name, capacity, durability_level):
cluster.node_types.append(NodeTypeDescription(name=node_type_name,
client_connection_endpoint_port=DEFAULT_CLIENT_CONNECTION_ENDPOINT,
... | def _add_node_type_to_sfrp(cmd, client, resource_group_name, cluster_name, cluster, node_type_name, capacity, durability_level):
| cluster.node_types.append(NodeTypeDescription(name=node_type_name,
client_connection_endpoint_port=DEFAULT_CLIENT_CONNECTION_ENDPOINT,
http_gateway_endpoint_port=DEFAULT_HTTP_GATEWAY_ENDPOINT,
... | _type, durability_level, vm_password, vm_user_name, vm_sku, vm_tier, capacity)
return client.get(resource_group_name, cluster_name)
def _add_node_type_to_sfrp(cmd, client, resource_group_name, cluster_name, cluster, node_type_name, capacity, durability_level):
| 64 | 64 | 185 | 31 | 33 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _add_node_type_to_sfrp | _add_node_type_to_sfrp | 722 | 736 | 722 | 722 | 719b3765d6efa2c9ceebd943205ef76a00a287dd | bigcode/the-stack | train |
f4786c9056ac57d623814faf | train | function | def remove_client_cert(cmd,
client,
resource_group_name,
cluster_name,
thumbprints=None,
certificate_common_name=None,
certificate_issuer_thumbprint=None,
clie... | def remove_client_cert(cmd,
client,
resource_group_name,
cluster_name,
thumbprints=None,
certificate_common_name=None,
certificate_issuer_thumbprint=None,
clie... | cli_ctx = cmd.cli_ctx
if thumbprints:
if certificate_common_name or certificate_issuer_thumbprint or client_certificate_common_names:
raise CLIError("--thumbprint can only specified alone")
if certificate_common_name or certificate_issuer_thumbprint:
if certificate_issuer_thumbpr... | :
if 'certificateCommonName' in common_name and 'certificateIssuerThumbprint' in common_name and 'isAdmin' in common_name:
cluster.client_certificate_common_names = _add_common_name(
cluster, common_name['isAdmin'], common_name['certificateCommonName'], common_name['certi... | 185 | 185 | 619 | 44 | 141 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | remove_client_cert | remove_client_cert | 386 | 451 | 386 | 393 | b580b34c70a916a222c8046e123d7c934f7391d2 | bigcode/the-stack | train |
e43c66202640d8634a66b560 | train | function | def _get_object_id_by_upn(graph_client, upn):
accounts = list(graph_client.users.list(
filter="userPrincipalName eq '{}'".format(upn)))
if not accounts:
logger.warning("Unable to find user with upn '%s'", upn)
return None
if len(accounts) > 1:
logger.warning("Multiple users p... | def _get_object_id_by_upn(graph_client, upn):
| accounts = list(graph_client.users.list(
filter="userPrincipalName eq '{}'".format(upn)))
if not accounts:
logger.warning("Unable to find user with upn '%s'", upn)
return None
if len(accounts) > 1:
logger.warning("Multiple users principals found with upn '%s'. "
... | if len(accounts) > 1:
logger.warning("Multiple service principals found with spn '%s'. "
"You can avoid this by specifying object id.", spn)
return None
return accounts[0].object_id
def _get_object_id_by_upn(graph_client, upn):
| 64 | 64 | 113 | 14 | 49 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _get_object_id_by_upn | _get_object_id_by_upn | 1,745 | 1,755 | 1,745 | 1,745 | 5a58aa1181d74c5e3e20e547116abeff3ad436e2 | bigcode/the-stack | train |
68a26b9c8545a67730c7c773 | train | function | def update_cluster_upgrade_type(cmd,
client,
resource_group_name,
cluster_name,
upgrade_mode,
version=None):
if upgrade_mode.lower() != 'manual' and upgrade... | def update_cluster_upgrade_type(cmd,
client,
resource_group_name,
cluster_name,
upgrade_mode,
version=None):
| if upgrade_mode.lower() != 'manual' and upgrade_mode.lower() != 'automatic':
raise CLIError(
'--upgrade-mode can either be \'manual\' or \'automatic\'')
cli_ctx = cmd.cli_ctx
cluster = client.get(resource_group_name, cluster_name)
patch_request = ClusterUpdateParameters(node_types=c... | .begin_create_or_update(resource_group_name, vmss.name, vmss)
LongRunningOperation(cli_ctx)(vmss_poll)
return client.get(resource_group_name, cluster_name)
def update_cluster_upgrade_type(cmd,
client,
resource_group_name,
... | 64 | 64 | 190 | 27 | 37 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | update_cluster_upgrade_type | update_cluster_upgrade_type | 560 | 581 | 560 | 565 | 9caa766cef2e142e77dc229d862fd79a4b7999fb | bigcode/the-stack | train |
2a4ebf7f0ad3820b92b2c758 | train | function | def _deploy_arm_template_core(cmd,
resource_group_name,
template,
parameters,
deployment_name=None,
mode='incremental',
validate_only=False,... | def _deploy_arm_template_core(cmd,
resource_group_name,
template,
parameters,
deployment_name=None,
mode='incremental',
validate_only=False,... | DeploymentProperties = cmd.get_models('DeploymentProperties', resource_type=ResourceType.MGMT_RESOURCE_RESOURCES)
properties = DeploymentProperties(
template=template, template_link=None, parameters=parameters, mode=mode)
client = resource_client_factory(cmd.cli_ctx)
Deployment = cmd.get_models(... | .parameters.append(
SettingsParameterDescription(name=kk, value=vv))
if setting_des.parameters and any(setting_des.parameters):
settings.append(setting_des)
return settings
def _deploy_arm_template_core(cmd,
resource_group_name,
... | 76 | 76 | 256 | 40 | 35 | ZengTaoxu/azure-cli | src/azure-cli/azure/cli/command_modules/servicefabric/custom.py | Python | _deploy_arm_template_core | _deploy_arm_template_core | 1,288 | 1,313 | 1,288 | 1,295 | 40d8fcc9888f674a0bcf00e643d8853f5f033e3c | bigcode/the-stack | train |
c4cd370d38b6b59d3919b0d5 | train | function | def test_parse_edgelist_with_data_list(example_graph):
G = example_graph
H = nx.parse_edgelist(
["1 2 3", "2 3 27", "3 4 3.0"], nodetype=int, data=(("weight", float),)
)
assert_nodes_equal(G.nodes, H.nodes)
assert_edges_equal(G.edges(data=True), H.edges(data=True))
| def test_parse_edgelist_with_data_list(example_graph):
| G = example_graph
H = nx.parse_edgelist(
["1 2 3", "2 3 27", "3 4 3.0"], nodetype=int, data=(("weight", float),)
)
assert_nodes_equal(G.nodes, H.nodes)
assert_edges_equal(G.edges(data=True), H.edges(data=True))
| 3 {'weight': 27}", "3 4 {'weight': 3.0}"],
nodetype=int,
)
assert_nodes_equal(G.nodes, H.nodes)
assert_edges_equal(G.edges(data=True), H.edges(data=True))
def test_parse_edgelist_with_data_list(example_graph):
| 64 | 64 | 89 | 12 | 52 | cuihaoleo/networkx | networkx/readwrite/tests/test_edgelist.py | Python | test_parse_edgelist_with_data_list | test_parse_edgelist_with_data_list | 131 | 137 | 131 | 131 | 7266b3f9bbb9ae0d326dbc0addb7083db8316d3f | bigcode/the-stack | train |
19ad3980c60577c8c1f5e720 | train | function | def test_parse_edgelist():
# ignore lines with less than 2 nodes
lines = ["1;2", "2 3", "3 4"]
G = nx.parse_edgelist(lines, nodetype=int)
assert list(G.edges()) == [(2, 3), (3, 4)]
# unknown nodetype
with pytest.raises(TypeError, match="Failed to convert nodes"):
lines = ["1 2", "2 3", "... | def test_parse_edgelist():
# ignore lines with less than 2 nodes
| lines = ["1;2", "2 3", "3 4"]
G = nx.parse_edgelist(lines, nodetype=int)
assert list(G.edges()) == [(2, 3), (3, 4)]
# unknown nodetype
with pytest.raises(TypeError, match="Failed to convert nodes"):
lines = ["1 2", "2 3", "3 4"]
nx.parse_edgelist(lines, nodetype="nope")
# lines h... | (example_graph):
G = example_graph
H = nx.parse_edgelist(
["1 2 3", "2 3 27", "3 4 3.0"], nodetype=int, data=(("weight", float),)
)
assert_nodes_equal(G.nodes, H.nodes)
assert_edges_equal(G.edges(data=True), H.edges(data=True))
def test_parse_edgelist():
# ignore lines with less than 2 n... | 98 | 98 | 328 | 18 | 80 | cuihaoleo/networkx | networkx/readwrite/tests/test_edgelist.py | Python | test_parse_edgelist | test_parse_edgelist | 140 | 162 | 140 | 141 | 7638ae14f21731182310abbe908c6518361175f1 | bigcode/the-stack | train |
f7537bac5db2cd9513adf476 | train | function | @pytest.mark.parametrize(
("data", "extra_kwargs"),
(
(edges_no_data, {}),
(edges_with_values, {}),
(edges_with_weight, {}),
(edges_with_multiple_attrs, {}),
(edges_with_multiple_attrs_csv, {"delimiter": ","}),
),
)
def test_read_edgelist_no_data(data, extra_kwargs):
... | @pytest.mark.parametrize(
("data", "extra_kwargs"),
(
(edges_no_data, {}),
(edges_with_values, {}),
(edges_with_weight, {}),
(edges_with_multiple_attrs, {}),
(edges_with_multiple_attrs_csv, {"delimiter": ","}),
),
)
def test_read_edgelist_no_data(data, extra_kwargs):
| bytesIO = io.BytesIO(data.encode("utf-8"))
G = nx.read_edgelist(bytesIO, nodetype=int, data=False, **extra_kwargs)
assert_edges_equal(G.edges(), [(1, 2), (2, 3)])
| @pytest.mark.parametrize(
("data", "extra_kwargs"),
(
(edges_no_data, {}),
(edges_with_values, {}),
(edges_with_weight, {}),
(edges_with_multiple_attrs, {}),
(edges_with_multiple_attrs_csv, {"delimiter": ","}),
),
)
def test_read_edgelist_no_data(data, extra_kwargs):
| 72 | 64 | 127 | 72 | 0 | cuihaoleo/networkx | networkx/readwrite/tests/test_edgelist.py | Python | test_read_edgelist_no_data | test_read_edgelist_no_data | 71 | 84 | 71 | 81 | 3d9f87eab54dd92125a1c539672e063c6fa7f4e5 | bigcode/the-stack | train |
b51dd9f2749cc8f009dfd591 | train | function | def test_parse_edgelist_with_data_dict(example_graph):
G = example_graph
H = nx.parse_edgelist(
["1 2 {'weight': 3}", "2 3 {'weight': 27}", "3 4 {'weight': 3.0}"],
nodetype=int,
)
assert_nodes_equal(G.nodes, H.nodes)
assert_edges_equal(G.edges(data=True), H.edges(data=True))
| def test_parse_edgelist_with_data_dict(example_graph):
| G = example_graph
H = nx.parse_edgelist(
["1 2 {'weight': 3}", "2 3 {'weight': 27}", "3 4 {'weight': 3.0}"],
nodetype=int,
)
assert_nodes_equal(G.nodes, H.nodes)
assert_edges_equal(G.edges(data=True), H.edges(data=True))
| G = example_graph
H = nx.parse_edgelist(["1 2", "2 3", "3 4"], nodetype=int)
assert_nodes_equal(G.nodes, H.nodes)
assert_edges_equal(G.edges, H.edges)
def test_parse_edgelist_with_data_dict(example_graph):
| 64 | 64 | 92 | 12 | 52 | cuihaoleo/networkx | networkx/readwrite/tests/test_edgelist.py | Python | test_parse_edgelist_with_data_dict | test_parse_edgelist_with_data_dict | 121 | 128 | 121 | 121 | fb46efaa047482e8c97e1bd833acf65cf049af3b | bigcode/the-stack | train |
e99d02f39256a84325eb5ac1 | train | function | def test_read_weighted_edgelist():
bytesIO = io.BytesIO(edges_with_values.encode("utf-8"))
G = nx.read_weighted_edgelist(bytesIO, nodetype=int)
assert_edges_equal(G.edges(data=True), _expected_edges_weights)
| def test_read_weighted_edgelist():
| bytesIO = io.BytesIO(edges_with_values.encode("utf-8"))
G = nx.read_weighted_edgelist(bytesIO, nodetype=int)
assert_edges_equal(G.edges(data=True), _expected_edges_weights)
| bytesIO = io.BytesIO(data.encode("utf-8"))
G = nx.read_edgelist(bytesIO, nodetype=int, data=False, **extra_kwargs)
assert_edges_equal(G.edges(), [(1, 2), (2, 3)])
def test_read_weighted_edgelist():
| 63 | 64 | 56 | 9 | 54 | cuihaoleo/networkx | networkx/readwrite/tests/test_edgelist.py | Python | test_read_weighted_edgelist | test_read_weighted_edgelist | 87 | 90 | 87 | 87 | 636e72cb6e53270126cd02feccd934ee98d548b1 | bigcode/the-stack | train |
cf50063cd6a05d33960993fd | train | function | @pytest.fixture
def example_graph():
G = nx.Graph()
G.add_weighted_edges_from([(1, 2, 3.0), (2, 3, 27.0), (3, 4, 3.0)])
return G
| @pytest.fixture
def example_graph():
| G = nx.Graph()
G.add_weighted_edges_from([(1, 2, 3.0), (2, 3, 27.0), (3, 4, 3.0)])
return G
| _read_edgelist_with_data(data, extra_kwargs, expected):
bytesIO = io.BytesIO(data.encode("utf-8"))
G = nx.read_edgelist(bytesIO, nodetype=int, **extra_kwargs)
assert_edges_equal(G.edges(data=True), expected)
@pytest.fixture
def example_graph():
| 64 | 64 | 57 | 7 | 57 | cuihaoleo/networkx | networkx/readwrite/tests/test_edgelist.py | Python | example_graph | example_graph | 107 | 111 | 107 | 108 | 5e8b2c4fb75833676bc455827c48f919eeab7adb | bigcode/the-stack | train |
4f5f272a50633dd2218b7936 | train | function | @pytest.mark.parametrize(
("data", "extra_kwargs", "expected"),
(
(edges_with_weight, {}, _expected_edges_weights),
(edges_with_multiple_attrs, {}, _expected_edges_multiattr),
(edges_with_multiple_attrs_csv, {"delimiter": ","}, _expected_edges_multiattr),
),
)
def test_read_edgelist_... | @pytest.mark.parametrize(
("data", "extra_kwargs", "expected"),
(
(edges_with_weight, {}, _expected_edges_weights),
(edges_with_multiple_attrs, {}, _expected_edges_multiattr),
(edges_with_multiple_attrs_csv, {"delimiter": ","}, _expected_edges_multiattr),
),
)
def test_read_edgelist_... | bytesIO = io.BytesIO(data.encode("utf-8"))
G = nx.read_edgelist(bytesIO, nodetype=int, **extra_kwargs)
assert_edges_equal(G.edges(data=True), expected)
| @pytest.mark.parametrize(
("data", "extra_kwargs", "expected"),
(
(edges_with_weight, {}, _expected_edges_weights),
(edges_with_multiple_attrs, {}, _expected_edges_multiattr),
(edges_with_multiple_attrs_csv, {"delimiter": ","}, _expected_edges_multiattr),
),
)
def test_read_edgelist_... | 80 | 64 | 124 | 80 | 0 | cuihaoleo/networkx | networkx/readwrite/tests/test_edgelist.py | Python | test_read_edgelist_with_data | test_read_edgelist_with_data | 93 | 104 | 93 | 101 | 4e54dee70002f3245fd91bde4c161937a917ba79 | bigcode/the-stack | train |
b961bf3461c918bf6682bfb4 | train | class | class TestEdgelist:
@classmethod
def setup_class(cls):
cls.G = nx.Graph(name="test")
e = [("a", "b"), ("b", "c"), ("c", "d"), ("d", "e"), ("e", "f"), ("a", "f")]
cls.G.add_edges_from(e)
cls.G.add_node("g")
cls.DG = nx.DiGraph(cls.G)
cls.XG = nx.MultiGraph()
... | class TestEdgelist:
@classmethod
| def setup_class(cls):
cls.G = nx.Graph(name="test")
e = [("a", "b"), ("b", "c"), ("c", "d"), ("d", "e"), ("e", "f"), ("a", "f")]
cls.G.add_edges_from(e)
cls.G.add_node("g")
cls.DG = nx.DiGraph(cls.G)
cls.XG = nx.MultiGraph()
cls.XG.add_weighted_edges_from([(1,... | match="Failed to convert nodes"):
lines = ["1 2", "2 3", "3 4"]
nx.parse_edgelist(lines, nodetype="nope")
# lines have invalid edge format
with pytest.raises(TypeError, match="Failed to convert edge data"):
lines = ["1 2 3", "2 3", "3 4"]
nx.parse_edgelist(lines, nodetype=int)
... | 256 | 256 | 1,543 | 10 | 246 | cuihaoleo/networkx | networkx/readwrite/tests/test_edgelist.py | Python | TestEdgelist | TestEdgelist | 165 | 307 | 165 | 166 | 2fcc1156fd14c9eeb50fad532ac16d4d53b9f145 | bigcode/the-stack | train |
8c319324f08f5322e937aa11 | train | function | def test_parse_edgelist_no_data(example_graph):
G = example_graph
H = nx.parse_edgelist(["1 2", "2 3", "3 4"], nodetype=int)
assert_nodes_equal(G.nodes, H.nodes)
assert_edges_equal(G.edges, H.edges)
| def test_parse_edgelist_no_data(example_graph):
| G = example_graph
H = nx.parse_edgelist(["1 2", "2 3", "3 4"], nodetype=int)
assert_nodes_equal(G.nodes, H.nodes)
assert_edges_equal(G.edges, H.edges)
| example_graph():
G = nx.Graph()
G.add_weighted_edges_from([(1, 2, 3.0), (2, 3, 27.0), (3, 4, 3.0)])
return G
def test_parse_edgelist_no_data(example_graph):
| 64 | 64 | 64 | 11 | 52 | cuihaoleo/networkx | networkx/readwrite/tests/test_edgelist.py | Python | test_parse_edgelist_no_data | test_parse_edgelist_no_data | 114 | 118 | 114 | 114 | 9c3c4915b3ef9bb5393b3eaf7ae5d54215471731 | bigcode/the-stack | train |
bcc0cbdf85c947e0a3608934 | train | class | class DummyAPI(object):
def __init__(self, existing, expected):
self.existing = existing
self.expected = expected
def get_rule_lists(self):
return {'data': self.existing['rule_lists']}
def update_rule_lists(self, list_id, expected):
assert self.expected['rule_lists'][list_i... | class DummyAPI(object):
| def __init__(self, existing, expected):
self.existing = existing
self.expected = expected
def get_rule_lists(self):
return {'data': self.existing['rule_lists']}
def update_rule_lists(self, list_id, expected):
assert self.expected['rule_lists'][list_id] == expected
def ... | import sigsci_site_manager.merge as merge
class DummyAPI(object):
| 15 | 64 | 97 | 5 | 9 | foospidy/sigsci_site_manager | tests/test_merge.py | Python | DummyAPI | DummyAPI | 4 | 16 | 4 | 4 | 40ecfb11dfc33556e957b024162bc1aacfd01df3 | bigcode/the-stack | train |
0e9f9af444b27a135d41996d | train | function | def test_find_match():
one = {'key1': 1, 'key2': 2}
two = {'key1': 1, 'key2': 5}
three = {'key1': 2, 'key2': 3}
haystack = [one, two, three]
needle = {'key1': 2, 'key2': 4, 'key3': 3}
assert merge._find_match(needle, haystack, ['key1']) == three
assert merge._find_match(needle, haystack, ['... | def test_find_match():
| one = {'key1': 1, 'key2': 2}
two = {'key1': 1, 'key2': 5}
three = {'key1': 2, 'key2': 3}
haystack = [one, two, three]
needle = {'key1': 2, 'key2': 4, 'key3': 3}
assert merge._find_match(needle, haystack, ['key1']) == three
assert merge._find_match(needle, haystack, ['key2']) is None
ass... | }
}
api = DummyAPI(existing, expected)
test_data = [{
'name': 'existing list',
'type': 'string',
'description': 'existing list',
'entries': ['foobar']
}]
merge.merge_rule_lists(api, test_data)
def test_find_match():
| 64 | 64 | 148 | 5 | 59 | foospidy/sigsci_site_manager | tests/test_merge.py | Python | test_find_match | test_find_match | 204 | 213 | 204 | 204 | d48969b36768575ff797cf8ead7f04187f82bdf9 | bigcode/the-stack | train |
132aa54a56ef078114ed8b6e | train | function | def test_merge_rule_lists_add_new_different_type():
existing = {
'rule_lists': [{
'id': '1',
'name': 'existing list',
'type': 'ip',
'description': 'existing list',
'entries': ['1.1.1.1']
}]
}
expected = {
'rule_lists': {
... | def test_merge_rule_lists_add_new_different_type():
| existing = {
'rule_lists': [{
'id': '1',
'name': 'existing list',
'type': 'ip',
'description': 'existing list',
'entries': ['1.1.1.1']
}]
}
expected = {
'rule_lists': {
'1': {
'id': '1',
... | , expected)
test_data = [{
'name': 'existing list',
'type': 'ip',
'description': 'existing list',
'entries': ['2.2.2.2']
}]
merge.merge_rule_lists(api, test_data)
def test_merge_rule_lists_add_new_different_type():
| 67 | 67 | 226 | 11 | 56 | foospidy/sigsci_site_manager | tests/test_merge.py | Python | test_merge_rule_lists_add_new_different_type | test_merge_rule_lists_add_new_different_type | 119 | 154 | 119 | 119 | ffc8e3b9928fae6911ea7ee6458cdee72bfed287 | bigcode/the-stack | train |
a0c251c9106831260d7af999 | train | function | def test_merge_rule_lists_no_change():
existing = {
'rule_lists': [{
'id': '1',
'name': 'existing list',
'type': 'ip',
'description': 'existing list',
'entries': ['1.1.1.1']
}]
}
expected = {
'rule_lists': {
'1':... | def test_merge_rule_lists_no_change():
| existing = {
'rule_lists': [{
'id': '1',
'name': 'existing list',
'type': 'ip',
'description': 'existing list',
'entries': ['1.1.1.1']
}]
}
expected = {
'rule_lists': {
'1': {
'name': 'existing li... | self.existing['rule_lists']}
def update_rule_lists(self, list_id, expected):
assert self.expected['rule_lists'][list_id] == expected
def add_rule_lists(self, expected):
assert self.expected['rule_lists']['new'] == expected
def test_merge_rule_lists_no_change():
| 64 | 64 | 184 | 8 | 55 | foospidy/sigsci_site_manager | tests/test_merge.py | Python | test_merge_rule_lists_no_change | test_merge_rule_lists_no_change | 19 | 47 | 19 | 19 | c066b502fd096171e37063edc8159883d2e67c23 | bigcode/the-stack | train |
2181f94b1a2b3cd205440d10 | train | function | def test_merge_rule_lists_add_new_different_type_no_change():
existing = {
'rule_lists': [
{
'id': '1',
'name': 'existing list',
'type': 'ip',
'description': 'existing list',
'entries': ['1.1.1.1']
},
... | def test_merge_rule_lists_add_new_different_type_no_change():
| existing = {
'rule_lists': [
{
'id': '1',
'name': 'existing list',
'type': 'ip',
'description': 'existing list',
'entries': ['1.1.1.1']
},
{
'id': '2',
'name': ... | 'entries': ['foobar']
}
}
}
api = DummyAPI(existing, expected)
test_data = [{
'name': 'existing list',
'type': 'string',
'description': 'existing list',
'entries': ['foobar']
}]
merge.merge_rule_lists(api, test_data)
def test_merge... | 82 | 82 | 274 | 13 | 69 | foospidy/sigsci_site_manager | tests/test_merge.py | Python | test_merge_rule_lists_add_new_different_type_no_change | test_merge_rule_lists_add_new_different_type_no_change | 157 | 201 | 157 | 157 | 025a676612cb033c633d583bee03fa63be025de1 | bigcode/the-stack | train |
70f71e319094e93bcc25a2fb | train | function | def test_merge_rule_lists_add_new():
existing = {
'rule_lists': [{
'id': '1',
'name': 'existing list',
'type': 'ip',
'description': 'existing list',
'entries': ['1.1.1.1']
}]
}
expected = {
'rule_lists': {
'1': {... | def test_merge_rule_lists_add_new():
| existing = {
'rule_lists': [{
'id': '1',
'name': 'existing list',
'type': 'ip',
'description': 'existing list',
'entries': ['1.1.1.1']
}]
}
expected = {
'rule_lists': {
'1': {
'id': '1',
... | api = DummyAPI(existing, expected)
test_data = [{
'name': 'existing list',
'type': 'ip',
'description': 'existing list',
'entries': ['1.1.1.1']
}]
merge.merge_rule_lists(api, test_data)
def test_merge_rule_lists_add_new():
| 70 | 70 | 234 | 8 | 62 | foospidy/sigsci_site_manager | tests/test_merge.py | Python | test_merge_rule_lists_add_new | test_merge_rule_lists_add_new | 50 | 85 | 50 | 50 | bf31d5d861f06520156418df70dcfa87aeacda31 | bigcode/the-stack | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.