repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
partition
stringclasses
1 value
postlund/pyatv
pyatv/mrp/srp.py
Credentials.parse
def parse(cls, detail_string): """Parse a string represention of Credentials.""" split = detail_string.split(':') if len(split) != 4: raise Exception('invalid credentials') # TODO: other exception ltpk = binascii.unhexlify(split[0]) ltsk = binascii.unhexlify(split[1...
python
def parse(cls, detail_string): """Parse a string represention of Credentials.""" split = detail_string.split(':') if len(split) != 4: raise Exception('invalid credentials') # TODO: other exception ltpk = binascii.unhexlify(split[0]) ltsk = binascii.unhexlify(split[1...
[ "def", "parse", "(", "cls", ",", "detail_string", ")", ":", "split", "=", "detail_string", ".", "split", "(", "':'", ")", "if", "len", "(", "split", ")", "!=", "4", ":", "raise", "Exception", "(", "'invalid credentials'", ")", "# TODO: other exception", "l...
Parse a string represention of Credentials.
[ "Parse", "a", "string", "represention", "of", "Credentials", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/srp.py#L32-L42
train
postlund/pyatv
pyatv/mrp/srp.py
SRPAuthHandler.initialize
def initialize(self): """Initialize operation by generating new keys.""" self._signing_key = SigningKey(os.urandom(32)) self._auth_private = self._signing_key.to_seed() self._auth_public = self._signing_key.get_verifying_key().to_bytes() self._verify_private = curve25519.Private(...
python
def initialize(self): """Initialize operation by generating new keys.""" self._signing_key = SigningKey(os.urandom(32)) self._auth_private = self._signing_key.to_seed() self._auth_public = self._signing_key.get_verifying_key().to_bytes() self._verify_private = curve25519.Private(...
[ "def", "initialize", "(", "self", ")", ":", "self", ".", "_signing_key", "=", "SigningKey", "(", "os", ".", "urandom", "(", "32", ")", ")", "self", ".", "_auth_private", "=", "self", ".", "_signing_key", ".", "to_seed", "(", ")", "self", ".", "_auth_pu...
Initialize operation by generating new keys.
[ "Initialize", "operation", "by", "generating", "new", "keys", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/srp.py#L85-L92
train
postlund/pyatv
pyatv/mrp/srp.py
SRPAuthHandler.verify1
def verify1(self, credentials, session_pub_key, encrypted): """First verification step.""" # No additional hashing used self._shared = self._verify_private.get_shared_key( curve25519.Public(session_pub_key), hashfunc=lambda x: x) session_key = hkdf_expand('Pair-Verify-Encryp...
python
def verify1(self, credentials, session_pub_key, encrypted): """First verification step.""" # No additional hashing used self._shared = self._verify_private.get_shared_key( curve25519.Public(session_pub_key), hashfunc=lambda x: x) session_key = hkdf_expand('Pair-Verify-Encryp...
[ "def", "verify1", "(", "self", ",", "credentials", ",", "session_pub_key", ",", "encrypted", ")", ":", "# No additional hashing used", "self", ".", "_shared", "=", "self", ".", "_verify_private", ".", "get_shared_key", "(", "curve25519", ".", "Public", "(", "ses...
First verification step.
[ "First", "verification", "step", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/srp.py#L94-L127
train
postlund/pyatv
pyatv/mrp/srp.py
SRPAuthHandler.verify2
def verify2(self): """Last verification step. The derived keys (output, input) are returned here. """ output_key = hkdf_expand('MediaRemote-Salt', 'MediaRemote-Write-Encryption-Key', self._shared) input_key = hkd...
python
def verify2(self): """Last verification step. The derived keys (output, input) are returned here. """ output_key = hkdf_expand('MediaRemote-Salt', 'MediaRemote-Write-Encryption-Key', self._shared) input_key = hkd...
[ "def", "verify2", "(", "self", ")", ":", "output_key", "=", "hkdf_expand", "(", "'MediaRemote-Salt'", ",", "'MediaRemote-Write-Encryption-Key'", ",", "self", ".", "_shared", ")", "input_key", "=", "hkdf_expand", "(", "'MediaRemote-Salt'", ",", "'MediaRemote-Read-Encry...
Last verification step. The derived keys (output, input) are returned here.
[ "Last", "verification", "step", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/srp.py#L129-L143
train
postlund/pyatv
pyatv/mrp/srp.py
SRPAuthHandler.step1
def step1(self, pin): """First pairing step.""" context = SRPContext( 'Pair-Setup', str(pin), prime=constants.PRIME_3072, generator=constants.PRIME_3072_GEN, hash_func=hashlib.sha512) self._session = SRPClientSession( context, binascii....
python
def step1(self, pin): """First pairing step.""" context = SRPContext( 'Pair-Setup', str(pin), prime=constants.PRIME_3072, generator=constants.PRIME_3072_GEN, hash_func=hashlib.sha512) self._session = SRPClientSession( context, binascii....
[ "def", "step1", "(", "self", ",", "pin", ")", ":", "context", "=", "SRPContext", "(", "'Pair-Setup'", ",", "str", "(", "pin", ")", ",", "prime", "=", "constants", ".", "PRIME_3072", ",", "generator", "=", "constants", ".", "PRIME_3072_GEN", ",", "hash_fu...
First pairing step.
[ "First", "pairing", "step", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/srp.py#L145-L153
train
postlund/pyatv
pyatv/mrp/srp.py
SRPAuthHandler.step2
def step2(self, atv_pub_key, atv_salt): """Second pairing step.""" pk_str = binascii.hexlify(atv_pub_key).decode() salt = binascii.hexlify(atv_salt).decode() self._client_session_key, _, _ = self._session.process(pk_str, salt) if not self._session.verify_proof(self._session.key_...
python
def step2(self, atv_pub_key, atv_salt): """Second pairing step.""" pk_str = binascii.hexlify(atv_pub_key).decode() salt = binascii.hexlify(atv_salt).decode() self._client_session_key, _, _ = self._session.process(pk_str, salt) if not self._session.verify_proof(self._session.key_...
[ "def", "step2", "(", "self", ",", "atv_pub_key", ",", "atv_salt", ")", ":", "pk_str", "=", "binascii", ".", "hexlify", "(", "atv_pub_key", ")", ".", "decode", "(", ")", "salt", "=", "binascii", ".", "hexlify", "(", "atv_salt", ")", ".", "decode", "(", ...
Second pairing step.
[ "Second", "pairing", "step", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/srp.py#L155-L167
train
postlund/pyatv
pyatv/mrp/srp.py
SRPAuthHandler.step3
def step3(self): """Third pairing step.""" ios_device_x = hkdf_expand( 'Pair-Setup-Controller-Sign-Salt', 'Pair-Setup-Controller-Sign-Info', binascii.unhexlify(self._client_session_key)) self._session_key = hkdf_expand( 'Pair-Setup-Encrypt-Salt', ...
python
def step3(self): """Third pairing step.""" ios_device_x = hkdf_expand( 'Pair-Setup-Controller-Sign-Salt', 'Pair-Setup-Controller-Sign-Info', binascii.unhexlify(self._client_session_key)) self._session_key = hkdf_expand( 'Pair-Setup-Encrypt-Salt', ...
[ "def", "step3", "(", "self", ")", ":", "ios_device_x", "=", "hkdf_expand", "(", "'Pair-Setup-Controller-Sign-Salt'", ",", "'Pair-Setup-Controller-Sign-Info'", ",", "binascii", ".", "unhexlify", "(", "self", ".", "_client_session_key", ")", ")", "self", ".", "_sessio...
Third pairing step.
[ "Third", "pairing", "step", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/srp.py#L169-L191
train
postlund/pyatv
pyatv/mrp/srp.py
SRPAuthHandler.step4
def step4(self, encrypted_data): """Last pairing step.""" chacha = chacha20.Chacha20Cipher(self._session_key, self._session_key) decrypted_tlv_bytes = chacha.decrypt( encrypted_data, nounce='PS-Msg06'.encode()) if not decrypted_tlv_bytes: raise Exception('data dec...
python
def step4(self, encrypted_data): """Last pairing step.""" chacha = chacha20.Chacha20Cipher(self._session_key, self._session_key) decrypted_tlv_bytes = chacha.decrypt( encrypted_data, nounce='PS-Msg06'.encode()) if not decrypted_tlv_bytes: raise Exception('data dec...
[ "def", "step4", "(", "self", ",", "encrypted_data", ")", ":", "chacha", "=", "chacha20", ".", "Chacha20Cipher", "(", "self", ".", "_session_key", ",", "self", ".", "_session_key", ")", "decrypted_tlv_bytes", "=", "chacha", ".", "decrypt", "(", "encrypted_data"...
Last pairing step.
[ "Last", "pairing", "step", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/srp.py#L193-L215
train
postlund/pyatv
pyatv/airplay/srp.py
hash_sha512
def hash_sha512(*indata): """Create SHA512 hash for input arguments.""" hasher = hashlib.sha512() for data in indata: if isinstance(data, str): hasher.update(data.encode('utf-8')) elif isinstance(data, bytes): hasher.update(data) else: raise Except...
python
def hash_sha512(*indata): """Create SHA512 hash for input arguments.""" hasher = hashlib.sha512() for data in indata: if isinstance(data, str): hasher.update(data.encode('utf-8')) elif isinstance(data, bytes): hasher.update(data) else: raise Except...
[ "def", "hash_sha512", "(", "*", "indata", ")", ":", "hasher", "=", "hashlib", ".", "sha512", "(", ")", "for", "data", "in", "indata", ":", "if", "isinstance", "(", "data", ",", "str", ")", ":", "hasher", ".", "update", "(", "data", ".", "encode", "...
Create SHA512 hash for input arguments.
[ "Create", "SHA512", "hash", "for", "input", "arguments", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/airplay/srp.py#L20-L30
train
postlund/pyatv
pyatv/airplay/srp.py
aes_encrypt
def aes_encrypt(mode, aes_key, aes_iv, *data): """Encrypt data with AES in specified mode.""" encryptor = Cipher( algorithms.AES(aes_key), mode(aes_iv), backend=default_backend()).encryptor() result = None for value in data: result = encryptor.update(value) encryptor...
python
def aes_encrypt(mode, aes_key, aes_iv, *data): """Encrypt data with AES in specified mode.""" encryptor = Cipher( algorithms.AES(aes_key), mode(aes_iv), backend=default_backend()).encryptor() result = None for value in data: result = encryptor.update(value) encryptor...
[ "def", "aes_encrypt", "(", "mode", ",", "aes_key", ",", "aes_iv", ",", "*", "data", ")", ":", "encryptor", "=", "Cipher", "(", "algorithms", ".", "AES", "(", "aes_key", ")", ",", "mode", "(", "aes_iv", ")", ",", "backend", "=", "default_backend", "(", ...
Encrypt data with AES in specified mode.
[ "Encrypt", "data", "with", "AES", "in", "specified", "mode", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/airplay/srp.py#L33-L45
train
postlund/pyatv
pyatv/airplay/srp.py
new_credentials
def new_credentials(): """Generate a new identifier and seed for authentication. Use the returned values in the following way: * The identifier shall be passed as username to SRPAuthHandler.step1 * Seed shall be passed to SRPAuthHandler constructor """ identifier = binascii.b2a_hex(os.urandom(8...
python
def new_credentials(): """Generate a new identifier and seed for authentication. Use the returned values in the following way: * The identifier shall be passed as username to SRPAuthHandler.step1 * Seed shall be passed to SRPAuthHandler constructor """ identifier = binascii.b2a_hex(os.urandom(8...
[ "def", "new_credentials", "(", ")", ":", "identifier", "=", "binascii", ".", "b2a_hex", "(", "os", ".", "urandom", "(", "8", ")", ")", ".", "decode", "(", ")", ".", "upper", "(", ")", "seed", "=", "binascii", ".", "b2a_hex", "(", "os", ".", "urando...
Generate a new identifier and seed for authentication. Use the returned values in the following way: * The identifier shall be passed as username to SRPAuthHandler.step1 * Seed shall be passed to SRPAuthHandler constructor
[ "Generate", "a", "new", "identifier", "and", "seed", "for", "authentication", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/airplay/srp.py#L48-L57
train
postlund/pyatv
pyatv/airplay/srp.py
SRPAuthHandler.initialize
def initialize(self, seed=None): """Initialize handler operation. This method will generate new encryption keys and must be called prior to doing authentication or verification. """ self.seed = seed or os.urandom(32) # Generate new seed if not provided signing_key = Sig...
python
def initialize(self, seed=None): """Initialize handler operation. This method will generate new encryption keys and must be called prior to doing authentication or verification. """ self.seed = seed or os.urandom(32) # Generate new seed if not provided signing_key = Sig...
[ "def", "initialize", "(", "self", ",", "seed", "=", "None", ")", ":", "self", ".", "seed", "=", "seed", "or", "os", ".", "urandom", "(", "32", ")", "# Generate new seed if not provided", "signing_key", "=", "SigningKey", "(", "self", ".", "seed", ")", "v...
Initialize handler operation. This method will generate new encryption keys and must be called prior to doing authentication or verification.
[ "Initialize", "handler", "operation", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/airplay/srp.py#L86-L100
train
postlund/pyatv
pyatv/airplay/srp.py
SRPAuthHandler.verify1
def verify1(self): """First device verification step.""" self._check_initialized() self._verify_private = curve25519.Private(secret=self.seed) self._verify_public = self._verify_private.get_public() log_binary(_LOGGER, 'Verification keys', Pr...
python
def verify1(self): """First device verification step.""" self._check_initialized() self._verify_private = curve25519.Private(secret=self.seed) self._verify_public = self._verify_private.get_public() log_binary(_LOGGER, 'Verification keys', Pr...
[ "def", "verify1", "(", "self", ")", ":", "self", ".", "_check_initialized", "(", ")", "self", ".", "_verify_private", "=", "curve25519", ".", "Private", "(", "secret", "=", "self", ".", "seed", ")", "self", ".", "_verify_public", "=", "self", ".", "_veri...
First device verification step.
[ "First", "device", "verification", "step", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/airplay/srp.py#L102-L112
train
postlund/pyatv
pyatv/airplay/srp.py
SRPAuthHandler.verify2
def verify2(self, atv_public_key, data): """Last device verification step.""" self._check_initialized() log_binary(_LOGGER, 'Verify', PublicSecret=atv_public_key, Data=data) # Generate a shared secret key public = curve25519.Public(atv_public_key) shared = self._verify_p...
python
def verify2(self, atv_public_key, data): """Last device verification step.""" self._check_initialized() log_binary(_LOGGER, 'Verify', PublicSecret=atv_public_key, Data=data) # Generate a shared secret key public = curve25519.Public(atv_public_key) shared = self._verify_p...
[ "def", "verify2", "(", "self", ",", "atv_public_key", ",", "data", ")", ":", "self", ".", "_check_initialized", "(", ")", "log_binary", "(", "_LOGGER", ",", "'Verify'", ",", "PublicSecret", "=", "atv_public_key", ",", "Data", "=", "data", ")", "# Generate a ...
Last device verification step.
[ "Last", "device", "verification", "step", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/airplay/srp.py#L114-L137
train
postlund/pyatv
pyatv/airplay/srp.py
SRPAuthHandler.step1
def step1(self, username, password): """First authentication step.""" self._check_initialized() context = AtvSRPContext( str(username), str(password), prime=constants.PRIME_2048, generator=constants.PRIME_2048_GEN) self.session = SRPClientSession( ...
python
def step1(self, username, password): """First authentication step.""" self._check_initialized() context = AtvSRPContext( str(username), str(password), prime=constants.PRIME_2048, generator=constants.PRIME_2048_GEN) self.session = SRPClientSession( ...
[ "def", "step1", "(", "self", ",", "username", ",", "password", ")", ":", "self", ".", "_check_initialized", "(", ")", "context", "=", "AtvSRPContext", "(", "str", "(", "username", ")", ",", "str", "(", "password", ")", ",", "prime", "=", "constants", "...
First authentication step.
[ "First", "authentication", "step", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/airplay/srp.py#L139-L147
train
postlund/pyatv
pyatv/airplay/srp.py
SRPAuthHandler.step2
def step2(self, pub_key, salt): """Second authentication step.""" self._check_initialized() pk_str = binascii.hexlify(pub_key).decode() salt = binascii.hexlify(salt).decode() self.client_session_key, _, _ = self.session.process(pk_str, salt) _LOGGER.debug('Client session ...
python
def step2(self, pub_key, salt): """Second authentication step.""" self._check_initialized() pk_str = binascii.hexlify(pub_key).decode() salt = binascii.hexlify(salt).decode() self.client_session_key, _, _ = self.session.process(pk_str, salt) _LOGGER.debug('Client session ...
[ "def", "step2", "(", "self", ",", "pub_key", ",", "salt", ")", ":", "self", ".", "_check_initialized", "(", ")", "pk_str", "=", "binascii", ".", "hexlify", "(", "pub_key", ")", ".", "decode", "(", ")", "salt", "=", "binascii", ".", "hexlify", "(", "s...
Second authentication step.
[ "Second", "authentication", "step", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/airplay/srp.py#L149-L165
train
postlund/pyatv
pyatv/airplay/srp.py
SRPAuthHandler.step3
def step3(self): """Last authentication step.""" self._check_initialized() # TODO: verify: self.client_session_key same as self.session.key_b64()? session_key = binascii.unhexlify(self.client_session_key) aes_key = hash_sha512('Pair-Setup-AES-Key', session_key)[0:16] tmp...
python
def step3(self): """Last authentication step.""" self._check_initialized() # TODO: verify: self.client_session_key same as self.session.key_b64()? session_key = binascii.unhexlify(self.client_session_key) aes_key = hash_sha512('Pair-Setup-AES-Key', session_key)[0:16] tmp...
[ "def", "step3", "(", "self", ")", ":", "self", ".", "_check_initialized", "(", ")", "# TODO: verify: self.client_session_key same as self.session.key_b64()?", "session_key", "=", "binascii", ".", "unhexlify", "(", "self", ".", "client_session_key", ")", "aes_key", "=", ...
Last authentication step.
[ "Last", "authentication", "step", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/airplay/srp.py#L167-L182
train
postlund/pyatv
pyatv/airplay/auth.py
DeviceAuthenticator.start_authentication
async def start_authentication(self): """Start the authentication process. This method will show the expected PIN on screen. """ _, code = await self.http.post_data( 'pair-pin-start', headers=_AIRPLAY_HEADERS) if code != 200: raise DeviceAuthenticationErr...
python
async def start_authentication(self): """Start the authentication process. This method will show the expected PIN on screen. """ _, code = await self.http.post_data( 'pair-pin-start', headers=_AIRPLAY_HEADERS) if code != 200: raise DeviceAuthenticationErr...
[ "async", "def", "start_authentication", "(", "self", ")", ":", "_", ",", "code", "=", "await", "self", ".", "http", ".", "post_data", "(", "'pair-pin-start'", ",", "headers", "=", "_AIRPLAY_HEADERS", ")", "if", "code", "!=", "200", ":", "raise", "DeviceAut...
Start the authentication process. This method will show the expected PIN on screen.
[ "Start", "the", "authentication", "process", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/airplay/auth.py#L26-L34
train
postlund/pyatv
pyatv/airplay/auth.py
DeviceAuthenticator.finish_authentication
async def finish_authentication(self, username, password): """Finish authentication process. A username (generated by new_credentials) and the PIN code shown on screen must be provided. """ # Step 1 self.srp.step1(username, password) data = await self._send_plist...
python
async def finish_authentication(self, username, password): """Finish authentication process. A username (generated by new_credentials) and the PIN code shown on screen must be provided. """ # Step 1 self.srp.step1(username, password) data = await self._send_plist...
[ "async", "def", "finish_authentication", "(", "self", ",", "username", ",", "password", ")", ":", "# Step 1", "self", ".", "srp", ".", "step1", "(", "username", ",", "password", ")", "data", "=", "await", "self", ".", "_send_plist", "(", "'step1'", ",", ...
Finish authentication process. A username (generated by new_credentials) and the PIN code shown on screen must be provided.
[ "Finish", "authentication", "process", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/airplay/auth.py#L36-L58
train
postlund/pyatv
pyatv/airplay/auth.py
AuthenticationVerifier.verify_authed
async def verify_authed(self): """Verify if device is allowed to use AirPlau.""" resp = await self._send(self.srp.verify1(), 'verify1') atv_public_secret = resp[0:32] data = resp[32:] # TODO: what is this? await self._send( self.srp.verify2(atv_public_secret, data),...
python
async def verify_authed(self): """Verify if device is allowed to use AirPlau.""" resp = await self._send(self.srp.verify1(), 'verify1') atv_public_secret = resp[0:32] data = resp[32:] # TODO: what is this? await self._send( self.srp.verify2(atv_public_secret, data),...
[ "async", "def", "verify_authed", "(", "self", ")", ":", "resp", "=", "await", "self", ".", "_send", "(", "self", ".", "srp", ".", "verify1", "(", ")", ",", "'verify1'", ")", "atv_public_secret", "=", "resp", "[", "0", ":", "32", "]", "data", "=", "...
Verify if device is allowed to use AirPlau.
[ "Verify", "if", "device", "is", "allowed", "to", "use", "AirPlau", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/airplay/auth.py#L86-L94
train
postlund/pyatv
pyatv/airplay/api.py
AirPlayAPI.generate_credentials
async def generate_credentials(self): """Create new credentials for authentication. Credentials that have been authenticated shall be saved and loaded with load_credentials before playing anything. If credentials are lost, authentication must be performed again. """ iden...
python
async def generate_credentials(self): """Create new credentials for authentication. Credentials that have been authenticated shall be saved and loaded with load_credentials before playing anything. If credentials are lost, authentication must be performed again. """ iden...
[ "async", "def", "generate_credentials", "(", "self", ")", ":", "identifier", ",", "seed", "=", "new_credentials", "(", ")", "return", "'{0}:{1}'", ".", "format", "(", "identifier", ",", "seed", ".", "decode", "(", ")", ".", "upper", "(", ")", ")" ]
Create new credentials for authentication. Credentials that have been authenticated shall be saved and loaded with load_credentials before playing anything. If credentials are lost, authentication must be performed again.
[ "Create", "new", "credentials", "for", "authentication", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/airplay/api.py#L25-L33
train
postlund/pyatv
pyatv/airplay/api.py
AirPlayAPI.load_credentials
async def load_credentials(self, credentials): """Load existing credentials.""" split = credentials.split(':') self.identifier = split[0] self.srp.initialize(binascii.unhexlify(split[1])) _LOGGER.debug('Loaded AirPlay credentials: %s', credentials)
python
async def load_credentials(self, credentials): """Load existing credentials.""" split = credentials.split(':') self.identifier = split[0] self.srp.initialize(binascii.unhexlify(split[1])) _LOGGER.debug('Loaded AirPlay credentials: %s', credentials)
[ "async", "def", "load_credentials", "(", "self", ",", "credentials", ")", ":", "split", "=", "credentials", ".", "split", "(", "':'", ")", "self", ".", "identifier", "=", "split", "[", "0", "]", "self", ".", "srp", ".", "initialize", "(", "binascii", "...
Load existing credentials.
[ "Load", "existing", "credentials", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/airplay/api.py#L35-L40
train
postlund/pyatv
pyatv/mrp/connection.py
MrpConnection.enable_encryption
def enable_encryption(self, output_key, input_key): """Enable encryption with the specified keys.""" self._chacha = chacha20.Chacha20Cipher(output_key, input_key)
python
def enable_encryption(self, output_key, input_key): """Enable encryption with the specified keys.""" self._chacha = chacha20.Chacha20Cipher(output_key, input_key)
[ "def", "enable_encryption", "(", "self", ",", "output_key", ",", "input_key", ")", ":", "self", ".", "_chacha", "=", "chacha20", ".", "Chacha20Cipher", "(", "output_key", ",", "input_key", ")" ]
Enable encryption with the specified keys.
[ "Enable", "encryption", "with", "the", "specified", "keys", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/connection.py#L37-L39
train
postlund/pyatv
pyatv/mrp/connection.py
MrpConnection.connect
def connect(self): """Connect to device.""" return self.loop.create_connection(lambda: self, self.host, self.port)
python
def connect(self): """Connect to device.""" return self.loop.create_connection(lambda: self, self.host, self.port)
[ "def", "connect", "(", "self", ")", ":", "return", "self", ".", "loop", ".", "create_connection", "(", "lambda", ":", "self", ",", "self", ".", "host", ",", "self", ".", "port", ")" ]
Connect to device.
[ "Connect", "to", "device", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/connection.py#L46-L48
train
postlund/pyatv
pyatv/mrp/connection.py
MrpConnection.close
def close(self): """Close connection to device.""" if self._transport: self._transport.close() self._transport = None self._chacha = None
python
def close(self): """Close connection to device.""" if self._transport: self._transport.close() self._transport = None self._chacha = None
[ "def", "close", "(", "self", ")", ":", "if", "self", ".", "_transport", ":", "self", ".", "_transport", ".", "close", "(", ")", "self", ".", "_transport", "=", "None", "self", ".", "_chacha", "=", "None" ]
Close connection to device.
[ "Close", "connection", "to", "device", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/connection.py#L50-L55
train
postlund/pyatv
pyatv/mrp/connection.py
MrpConnection.send
def send(self, message): """Send message to device.""" serialized = message.SerializeToString() log_binary(_LOGGER, '>> Send', Data=serialized) if self._chacha: serialized = self._chacha.encrypt(serialized) log_binary(_LOGGER, '>> Send', Encrypted=serialized) ...
python
def send(self, message): """Send message to device.""" serialized = message.SerializeToString() log_binary(_LOGGER, '>> Send', Data=serialized) if self._chacha: serialized = self._chacha.encrypt(serialized) log_binary(_LOGGER, '>> Send', Encrypted=serialized) ...
[ "def", "send", "(", "self", ",", "message", ")", ":", "serialized", "=", "message", ".", "SerializeToString", "(", ")", "log_binary", "(", "_LOGGER", ",", "'>> Send'", ",", "Data", "=", "serialized", ")", "if", "self", ".", "_chacha", ":", "serialized", ...
Send message to device.
[ "Send", "message", "to", "device", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/connection.py#L57-L68
train
postlund/pyatv
pyatv/net.py
HttpSession.get_data
async def get_data(self, path, headers=None, timeout=None): """Perform a GET request.""" url = self.base_url + path _LOGGER.debug('GET URL: %s', url) resp = None try: resp = await self._session.get( url, headers=headers, timeout=DEFAULT...
python
async def get_data(self, path, headers=None, timeout=None): """Perform a GET request.""" url = self.base_url + path _LOGGER.debug('GET URL: %s', url) resp = None try: resp = await self._session.get( url, headers=headers, timeout=DEFAULT...
[ "async", "def", "get_data", "(", "self", ",", "path", ",", "headers", "=", "None", ",", "timeout", "=", "None", ")", ":", "url", "=", "self", ".", "base_url", "+", "path", "_LOGGER", ".", "debug", "(", "'GET URL: %s'", ",", "url", ")", "resp", "=", ...
Perform a GET request.
[ "Perform", "a", "GET", "request", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/net.py#L20-L40
train
postlund/pyatv
pyatv/net.py
HttpSession.post_data
async def post_data(self, path, data=None, headers=None, timeout=None): """Perform a POST request.""" url = self.base_url + path _LOGGER.debug('POST URL: %s', url) self._log_data(data, False) resp = None try: resp = await self._session.post( u...
python
async def post_data(self, path, data=None, headers=None, timeout=None): """Perform a POST request.""" url = self.base_url + path _LOGGER.debug('POST URL: %s', url) self._log_data(data, False) resp = None try: resp = await self._session.post( u...
[ "async", "def", "post_data", "(", "self", ",", "path", ",", "data", "=", "None", ",", "headers", "=", "None", ",", "timeout", "=", "None", ")", ":", "url", "=", "self", ".", "base_url", "+", "path", "_LOGGER", ".", "debug", "(", "'POST URL: %s'", ","...
Perform a POST request.
[ "Perform", "a", "POST", "request", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/net.py#L42-L65
train
postlund/pyatv
pyatv/dmap/tags.py
read_uint
def read_uint(data, start, length): """Extract a uint from a position in a sequence.""" return int.from_bytes(data[start:start+length], byteorder='big')
python
def read_uint(data, start, length): """Extract a uint from a position in a sequence.""" return int.from_bytes(data[start:start+length], byteorder='big')
[ "def", "read_uint", "(", "data", ",", "start", ",", "length", ")", ":", "return", "int", ".", "from_bytes", "(", "data", "[", "start", ":", "start", "+", "length", "]", ",", "byteorder", "=", "'big'", ")" ]
Extract a uint from a position in a sequence.
[ "Extract", "a", "uint", "from", "a", "position", "in", "a", "sequence", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/dmap/tags.py#L11-L13
train
postlund/pyatv
pyatv/dmap/tags.py
read_bplist
def read_bplist(data, start, length): """Extract a binary plist from a position in a sequence.""" # TODO: pylint doesn't find FMT_BINARY, why? # pylint: disable=no-member return plistlib.loads(data[start:start+length], fmt=plistlib.FMT_BINARY)
python
def read_bplist(data, start, length): """Extract a binary plist from a position in a sequence.""" # TODO: pylint doesn't find FMT_BINARY, why? # pylint: disable=no-member return plistlib.loads(data[start:start+length], fmt=plistlib.FMT_BINARY)
[ "def", "read_bplist", "(", "data", ",", "start", ",", "length", ")", ":", "# TODO: pylint doesn't find FMT_BINARY, why?", "# pylint: disable=no-member", "return", "plistlib", ".", "loads", "(", "data", "[", "start", ":", "start", "+", "length", "]", ",", "fmt", ...
Extract a binary plist from a position in a sequence.
[ "Extract", "a", "binary", "plist", "from", "a", "position", "in", "a", "sequence", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/dmap/tags.py#L21-L26
train
postlund/pyatv
pyatv/dmap/tags.py
raw_tag
def raw_tag(name, value): """Create a DMAP tag with raw data.""" return name.encode('utf-8') + \ len(value).to_bytes(4, byteorder='big') + \ value
python
def raw_tag(name, value): """Create a DMAP tag with raw data.""" return name.encode('utf-8') + \ len(value).to_bytes(4, byteorder='big') + \ value
[ "def", "raw_tag", "(", "name", ",", "value", ")", ":", "return", "name", ".", "encode", "(", "'utf-8'", ")", "+", "len", "(", "value", ")", ".", "to_bytes", "(", "4", ",", "byteorder", "=", "'big'", ")", "+", "value" ]
Create a DMAP tag with raw data.
[ "Create", "a", "DMAP", "tag", "with", "raw", "data", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/dmap/tags.py#L69-L73
train
postlund/pyatv
pyatv/dmap/tags.py
string_tag
def string_tag(name, value): """Create a DMAP tag with string data.""" return name.encode('utf-8') + \ len(value).to_bytes(4, byteorder='big') + \ value.encode('utf-8')
python
def string_tag(name, value): """Create a DMAP tag with string data.""" return name.encode('utf-8') + \ len(value).to_bytes(4, byteorder='big') + \ value.encode('utf-8')
[ "def", "string_tag", "(", "name", ",", "value", ")", ":", "return", "name", ".", "encode", "(", "'utf-8'", ")", "+", "len", "(", "value", ")", ".", "to_bytes", "(", "4", ",", "byteorder", "=", "'big'", ")", "+", "value", ".", "encode", "(", "'utf-8...
Create a DMAP tag with string data.
[ "Create", "a", "DMAP", "tag", "with", "string", "data", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/dmap/tags.py#L76-L80
train
postlund/pyatv
pyatv/mrp/messages.py
create
def create(message_type, priority=0): """Create a ProtocolMessage.""" message = protobuf.ProtocolMessage() message.type = message_type message.priority = priority return message
python
def create(message_type, priority=0): """Create a ProtocolMessage.""" message = protobuf.ProtocolMessage() message.type = message_type message.priority = priority return message
[ "def", "create", "(", "message_type", ",", "priority", "=", "0", ")", ":", "message", "=", "protobuf", ".", "ProtocolMessage", "(", ")", "message", ".", "type", "=", "message_type", "message", ".", "priority", "=", "priority", "return", "message" ]
Create a ProtocolMessage.
[ "Create", "a", "ProtocolMessage", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/messages.py#L9-L14
train
postlund/pyatv
pyatv/mrp/messages.py
device_information
def device_information(name, identifier): """Create a new DEVICE_INFO_MESSAGE.""" # pylint: disable=no-member message = create(protobuf.DEVICE_INFO_MESSAGE) info = message.inner() info.uniqueIdentifier = identifier info.name = name info.localizedModelName = 'iPhone' info.systemBuildVersi...
python
def device_information(name, identifier): """Create a new DEVICE_INFO_MESSAGE.""" # pylint: disable=no-member message = create(protobuf.DEVICE_INFO_MESSAGE) info = message.inner() info.uniqueIdentifier = identifier info.name = name info.localizedModelName = 'iPhone' info.systemBuildVersi...
[ "def", "device_information", "(", "name", ",", "identifier", ")", ":", "# pylint: disable=no-member", "message", "=", "create", "(", "protobuf", ".", "DEVICE_INFO_MESSAGE", ")", "info", "=", "message", ".", "inner", "(", ")", "info", ".", "uniqueIdentifier", "="...
Create a new DEVICE_INFO_MESSAGE.
[ "Create", "a", "new", "DEVICE_INFO_MESSAGE", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/messages.py#L18-L32
train
postlund/pyatv
pyatv/mrp/messages.py
set_connection_state
def set_connection_state(): """Create a new SET_CONNECTION_STATE.""" message = create(protobuf.ProtocolMessage.SET_CONNECTION_STATE_MESSAGE) message.inner().state = protobuf.SetConnectionStateMessage.Connected return message
python
def set_connection_state(): """Create a new SET_CONNECTION_STATE.""" message = create(protobuf.ProtocolMessage.SET_CONNECTION_STATE_MESSAGE) message.inner().state = protobuf.SetConnectionStateMessage.Connected return message
[ "def", "set_connection_state", "(", ")", ":", "message", "=", "create", "(", "protobuf", ".", "ProtocolMessage", ".", "SET_CONNECTION_STATE_MESSAGE", ")", "message", ".", "inner", "(", ")", ".", "state", "=", "protobuf", ".", "SetConnectionStateMessage", ".", "C...
Create a new SET_CONNECTION_STATE.
[ "Create", "a", "new", "SET_CONNECTION_STATE", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/messages.py#L40-L44
train
postlund/pyatv
pyatv/mrp/messages.py
crypto_pairing
def crypto_pairing(pairing_data): """Create a new CRYPTO_PAIRING_MESSAGE.""" message = create(protobuf.CRYPTO_PAIRING_MESSAGE) crypto = message.inner() crypto.status = 0 crypto.pairingData = tlv8.write_tlv(pairing_data) return message
python
def crypto_pairing(pairing_data): """Create a new CRYPTO_PAIRING_MESSAGE.""" message = create(protobuf.CRYPTO_PAIRING_MESSAGE) crypto = message.inner() crypto.status = 0 crypto.pairingData = tlv8.write_tlv(pairing_data) return message
[ "def", "crypto_pairing", "(", "pairing_data", ")", ":", "message", "=", "create", "(", "protobuf", ".", "CRYPTO_PAIRING_MESSAGE", ")", "crypto", "=", "message", ".", "inner", "(", ")", "crypto", ".", "status", "=", "0", "crypto", ".", "pairingData", "=", "...
Create a new CRYPTO_PAIRING_MESSAGE.
[ "Create", "a", "new", "CRYPTO_PAIRING_MESSAGE", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/messages.py#L47-L53
train
postlund/pyatv
pyatv/mrp/messages.py
client_updates_config
def client_updates_config(artwork=True, now_playing=True, volume=True, keyboard=True): """Create a new CLIENT_UPDATES_CONFIG_MESSAGE.""" message = create(protobuf.CLIENT_UPDATES_CONFIG_MESSAGE) config = message.inner() config.artworkUpdates = artwork config.nowPlayingUpdate...
python
def client_updates_config(artwork=True, now_playing=True, volume=True, keyboard=True): """Create a new CLIENT_UPDATES_CONFIG_MESSAGE.""" message = create(protobuf.CLIENT_UPDATES_CONFIG_MESSAGE) config = message.inner() config.artworkUpdates = artwork config.nowPlayingUpdate...
[ "def", "client_updates_config", "(", "artwork", "=", "True", ",", "now_playing", "=", "True", ",", "volume", "=", "True", ",", "keyboard", "=", "True", ")", ":", "message", "=", "create", "(", "protobuf", ".", "CLIENT_UPDATES_CONFIG_MESSAGE", ")", "config", ...
Create a new CLIENT_UPDATES_CONFIG_MESSAGE.
[ "Create", "a", "new", "CLIENT_UPDATES_CONFIG_MESSAGE", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/messages.py#L56-L65
train
postlund/pyatv
pyatv/mrp/messages.py
register_hid_device
def register_hid_device(screen_width, screen_height, absolute=False, integrated_display=False): """Create a new REGISTER_HID_DEVICE_MESSAGE.""" message = create(protobuf.REGISTER_HID_DEVICE_MESSAGE) descriptor = message.inner().deviceDescriptor descriptor.absolute = 1 if absolute...
python
def register_hid_device(screen_width, screen_height, absolute=False, integrated_display=False): """Create a new REGISTER_HID_DEVICE_MESSAGE.""" message = create(protobuf.REGISTER_HID_DEVICE_MESSAGE) descriptor = message.inner().deviceDescriptor descriptor.absolute = 1 if absolute...
[ "def", "register_hid_device", "(", "screen_width", ",", "screen_height", ",", "absolute", "=", "False", ",", "integrated_display", "=", "False", ")", ":", "message", "=", "create", "(", "protobuf", ".", "REGISTER_HID_DEVICE_MESSAGE", ")", "descriptor", "=", "messa...
Create a new REGISTER_HID_DEVICE_MESSAGE.
[ "Create", "a", "new", "REGISTER_HID_DEVICE_MESSAGE", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/messages.py#L73-L82
train
postlund/pyatv
pyatv/mrp/messages.py
send_packed_virtual_touch_event
def send_packed_virtual_touch_event(xpos, ypos, phase, device_id, finger): """Create a new WAKE_DEVICE_MESSAGE.""" message = create(protobuf.SEND_PACKED_VIRTUAL_TOUCH_EVENT_MESSAGE) event = message.inner() # The packed version of VirtualTouchEvent contains X, Y, phase, deviceID # and finger stored ...
python
def send_packed_virtual_touch_event(xpos, ypos, phase, device_id, finger): """Create a new WAKE_DEVICE_MESSAGE.""" message = create(protobuf.SEND_PACKED_VIRTUAL_TOUCH_EVENT_MESSAGE) event = message.inner() # The packed version of VirtualTouchEvent contains X, Y, phase, deviceID # and finger stored ...
[ "def", "send_packed_virtual_touch_event", "(", "xpos", ",", "ypos", ",", "phase", ",", "device_id", ",", "finger", ")", ":", "message", "=", "create", "(", "protobuf", ".", "SEND_PACKED_VIRTUAL_TOUCH_EVENT_MESSAGE", ")", "event", "=", "message", ".", "inner", "(...
Create a new WAKE_DEVICE_MESSAGE.
[ "Create", "a", "new", "WAKE_DEVICE_MESSAGE", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/messages.py#L85-L99
train
postlund/pyatv
pyatv/mrp/messages.py
send_hid_event
def send_hid_event(use_page, usage, down): """Create a new SEND_HID_EVENT_MESSAGE.""" message = create(protobuf.SEND_HID_EVENT_MESSAGE) event = message.inner() # TODO: This should be generated somehow. I guess it's mach AbsoluteTime # which is tricky to generate. The device does not seem to care mu...
python
def send_hid_event(use_page, usage, down): """Create a new SEND_HID_EVENT_MESSAGE.""" message = create(protobuf.SEND_HID_EVENT_MESSAGE) event = message.inner() # TODO: This should be generated somehow. I guess it's mach AbsoluteTime # which is tricky to generate. The device does not seem to care mu...
[ "def", "send_hid_event", "(", "use_page", ",", "usage", ",", "down", ")", ":", "message", "=", "create", "(", "protobuf", ".", "SEND_HID_EVENT_MESSAGE", ")", "event", "=", "message", ".", "inner", "(", ")", "# TODO: This should be generated somehow. I guess it's mac...
Create a new SEND_HID_EVENT_MESSAGE.
[ "Create", "a", "new", "SEND_HID_EVENT_MESSAGE", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/messages.py#L102-L124
train
postlund/pyatv
pyatv/mrp/messages.py
command
def command(cmd): """Playback command request.""" message = create(protobuf.SEND_COMMAND_MESSAGE) send_command = message.inner() send_command.command = cmd return message
python
def command(cmd): """Playback command request.""" message = create(protobuf.SEND_COMMAND_MESSAGE) send_command = message.inner() send_command.command = cmd return message
[ "def", "command", "(", "cmd", ")", ":", "message", "=", "create", "(", "protobuf", ".", "SEND_COMMAND_MESSAGE", ")", "send_command", "=", "message", ".", "inner", "(", ")", "send_command", ".", "command", "=", "cmd", "return", "message" ]
Playback command request.
[ "Playback", "command", "request", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/messages.py#L127-L132
train
postlund/pyatv
pyatv/mrp/messages.py
repeat
def repeat(mode): """Change repeat mode of current player.""" message = command(protobuf.CommandInfo_pb2.ChangeShuffleMode) send_command = message.inner() send_command.options.externalPlayerCommand = True send_command.options.repeatMode = mode return message
python
def repeat(mode): """Change repeat mode of current player.""" message = command(protobuf.CommandInfo_pb2.ChangeShuffleMode) send_command = message.inner() send_command.options.externalPlayerCommand = True send_command.options.repeatMode = mode return message
[ "def", "repeat", "(", "mode", ")", ":", "message", "=", "command", "(", "protobuf", ".", "CommandInfo_pb2", ".", "ChangeShuffleMode", ")", "send_command", "=", "message", ".", "inner", "(", ")", "send_command", ".", "options", ".", "externalPlayerCommand", "="...
Change repeat mode of current player.
[ "Change", "repeat", "mode", "of", "current", "player", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/messages.py#L135-L141
train
postlund/pyatv
pyatv/mrp/messages.py
shuffle
def shuffle(enable): """Change shuffle mode of current player.""" message = command(protobuf.CommandInfo_pb2.ChangeShuffleMode) send_command = message.inner() send_command.options.shuffleMode = 3 if enable else 1 return message
python
def shuffle(enable): """Change shuffle mode of current player.""" message = command(protobuf.CommandInfo_pb2.ChangeShuffleMode) send_command = message.inner() send_command.options.shuffleMode = 3 if enable else 1 return message
[ "def", "shuffle", "(", "enable", ")", ":", "message", "=", "command", "(", "protobuf", ".", "CommandInfo_pb2", ".", "ChangeShuffleMode", ")", "send_command", "=", "message", ".", "inner", "(", ")", "send_command", ".", "options", ".", "shuffleMode", "=", "3"...
Change shuffle mode of current player.
[ "Change", "shuffle", "mode", "of", "current", "player", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/messages.py#L144-L149
train
postlund/pyatv
pyatv/mrp/messages.py
seek_to_position
def seek_to_position(position): """Seek to an absolute position in stream.""" message = command(protobuf.CommandInfo_pb2.SeekToPlaybackPosition) send_command = message.inner() send_command.options.playbackPosition = position return message
python
def seek_to_position(position): """Seek to an absolute position in stream.""" message = command(protobuf.CommandInfo_pb2.SeekToPlaybackPosition) send_command = message.inner() send_command.options.playbackPosition = position return message
[ "def", "seek_to_position", "(", "position", ")", ":", "message", "=", "command", "(", "protobuf", ".", "CommandInfo_pb2", ".", "SeekToPlaybackPosition", ")", "send_command", "=", "message", ".", "inner", "(", ")", "send_command", ".", "options", ".", "playbackPo...
Seek to an absolute position in stream.
[ "Seek", "to", "an", "absolute", "position", "in", "stream", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/messages.py#L152-L157
train
postlund/pyatv
examples/pairing.py
pair_with_device
async def pair_with_device(loop): """Make it possible to pair with device.""" my_zeroconf = Zeroconf() details = conf.AppleTV('127.0.0.1', 'Apple TV') details.add_service(conf.DmapService('login_id')) atv = pyatv.connect_to_apple_tv(details, loop) atv.pairing.pin(PIN_CODE) await atv.pairing...
python
async def pair_with_device(loop): """Make it possible to pair with device.""" my_zeroconf = Zeroconf() details = conf.AppleTV('127.0.0.1', 'Apple TV') details.add_service(conf.DmapService('login_id')) atv = pyatv.connect_to_apple_tv(details, loop) atv.pairing.pin(PIN_CODE) await atv.pairing...
[ "async", "def", "pair_with_device", "(", "loop", ")", ":", "my_zeroconf", "=", "Zeroconf", "(", ")", "details", "=", "conf", ".", "AppleTV", "(", "'127.0.0.1'", ",", "'Apple TV'", ")", "details", ".", "add_service", "(", "conf", ".", "DmapService", "(", "'...
Make it possible to pair with device.
[ "Make", "it", "possible", "to", "pair", "with", "device", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/examples/pairing.py#L17-L40
train
postlund/pyatv
pyatv/mrp/variant.py
read_variant
def read_variant(variant): """Read and parse a binary protobuf variant value.""" result = 0 cnt = 0 for data in variant: result |= (data & 0x7f) << (7 * cnt) cnt += 1 if not data & 0x80: return result, variant[cnt:] raise Exception('invalid variant')
python
def read_variant(variant): """Read and parse a binary protobuf variant value.""" result = 0 cnt = 0 for data in variant: result |= (data & 0x7f) << (7 * cnt) cnt += 1 if not data & 0x80: return result, variant[cnt:] raise Exception('invalid variant')
[ "def", "read_variant", "(", "variant", ")", ":", "result", "=", "0", "cnt", "=", "0", "for", "data", "in", "variant", ":", "result", "|=", "(", "data", "&", "0x7f", ")", "<<", "(", "7", "*", "cnt", ")", "cnt", "+=", "1", "if", "not", "data", "&...
Read and parse a binary protobuf variant value.
[ "Read", "and", "parse", "a", "binary", "protobuf", "variant", "value", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/variant.py#L4-L13
train
postlund/pyatv
examples/manual_connect.py
print_what_is_playing
async def print_what_is_playing(loop): """Connect to device and print what is playing.""" details = conf.AppleTV(ADDRESS, NAME) details.add_service(conf.DmapService(HSGID)) print('Connecting to {}'.format(details.address)) atv = pyatv.connect_to_apple_tv(details, loop) try: print((awai...
python
async def print_what_is_playing(loop): """Connect to device and print what is playing.""" details = conf.AppleTV(ADDRESS, NAME) details.add_service(conf.DmapService(HSGID)) print('Connecting to {}'.format(details.address)) atv = pyatv.connect_to_apple_tv(details, loop) try: print((awai...
[ "async", "def", "print_what_is_playing", "(", "loop", ")", ":", "details", "=", "conf", ".", "AppleTV", "(", "ADDRESS", ",", "NAME", ")", "details", ".", "add_service", "(", "conf", ".", "DmapService", "(", "HSGID", ")", ")", "print", "(", "'Connecting to ...
Connect to device and print what is playing.
[ "Connect", "to", "device", "and", "print", "what", "is", "playing", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/examples/manual_connect.py#L16-L28
train
postlund/pyatv
pyatv/mrp/protocol.py
MrpProtocol.add_listener
def add_listener(self, listener, message_type, data=None, one_shot=False): """Add a listener that will receice incoming messages.""" lst = self._one_shots if one_shot else self._listeners if message_type not in lst: lst[message_type] = [] lst[message_type].append(Listener(l...
python
def add_listener(self, listener, message_type, data=None, one_shot=False): """Add a listener that will receice incoming messages.""" lst = self._one_shots if one_shot else self._listeners if message_type not in lst: lst[message_type] = [] lst[message_type].append(Listener(l...
[ "def", "add_listener", "(", "self", ",", "listener", ",", "message_type", ",", "data", "=", "None", ",", "one_shot", "=", "False", ")", ":", "lst", "=", "self", ".", "_one_shots", "if", "one_shot", "else", "self", ".", "_listeners", "if", "message_type", ...
Add a listener that will receice incoming messages.
[ "Add", "a", "listener", "that", "will", "receice", "incoming", "messages", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/protocol.py#L43-L50
train
postlund/pyatv
pyatv/mrp/protocol.py
MrpProtocol.start
async def start(self): """Connect to device and listen to incoming messages.""" if self.connection.connected: return await self.connection.connect() # In case credentials have been given externally (i.e. not by pairing # with a device), then use that client id ...
python
async def start(self): """Connect to device and listen to incoming messages.""" if self.connection.connected: return await self.connection.connect() # In case credentials have been given externally (i.e. not by pairing # with a device), then use that client id ...
[ "async", "def", "start", "(", "self", ")", ":", "if", "self", ".", "connection", ".", "connected", ":", "return", "await", "self", ".", "connection", ".", "connect", "(", ")", "# In case credentials have been given externally (i.e. not by pairing", "# with a device), ...
Connect to device and listen to incoming messages.
[ "Connect", "to", "device", "and", "listen", "to", "incoming", "messages", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/protocol.py#L53-L99
train
postlund/pyatv
pyatv/mrp/protocol.py
MrpProtocol.stop
def stop(self): """Disconnect from device.""" if self._outstanding: _LOGGER.warning('There were %d outstanding requests', len(self._outstanding)) self._initial_message_sent = False self._outstanding = {} self._one_shots = {} self.c...
python
def stop(self): """Disconnect from device.""" if self._outstanding: _LOGGER.warning('There were %d outstanding requests', len(self._outstanding)) self._initial_message_sent = False self._outstanding = {} self._one_shots = {} self.c...
[ "def", "stop", "(", "self", ")", ":", "if", "self", ".", "_outstanding", ":", "_LOGGER", ".", "warning", "(", "'There were %d outstanding requests'", ",", "len", "(", "self", ".", "_outstanding", ")", ")", "self", ".", "_initial_message_sent", "=", "False", ...
Disconnect from device.
[ "Disconnect", "from", "device", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/protocol.py#L101-L110
train
postlund/pyatv
pyatv/mrp/protocol.py
MrpProtocol.send_and_receive
async def send_and_receive(self, message, generate_identifier=True, timeout=5): """Send a message and wait for a response.""" await self._connect_and_encrypt() # Some messages will respond with the same identifier as used in the # corresponding request. Ot...
python
async def send_and_receive(self, message, generate_identifier=True, timeout=5): """Send a message and wait for a response.""" await self._connect_and_encrypt() # Some messages will respond with the same identifier as used in the # corresponding request. Ot...
[ "async", "def", "send_and_receive", "(", "self", ",", "message", ",", "generate_identifier", "=", "True", ",", "timeout", "=", "5", ")", ":", "await", "self", ".", "_connect_and_encrypt", "(", ")", "# Some messages will respond with the same identifier as used in the", ...
Send a message and wait for a response.
[ "Send", "a", "message", "and", "wait", "for", "a", "response", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/protocol.py#L134-L153
train
postlund/pyatv
pyatv/dmap/__init__.py
BaseDmapAppleTV.playstatus
async def playstatus(self, use_revision=False, timeout=None): """Request raw data about what is currently playing. If use_revision=True, this command will "block" until playstatus changes on the device. Must be logged in. """ cmd_url = _PSU_CMD.format( self....
python
async def playstatus(self, use_revision=False, timeout=None): """Request raw data about what is currently playing. If use_revision=True, this command will "block" until playstatus changes on the device. Must be logged in. """ cmd_url = _PSU_CMD.format( self....
[ "async", "def", "playstatus", "(", "self", ",", "use_revision", "=", "False", ",", "timeout", "=", "None", ")", ":", "cmd_url", "=", "_PSU_CMD", ".", "format", "(", "self", ".", "playstatus_revision", "if", "use_revision", "else", "0", ")", "resp", "=", ...
Request raw data about what is currently playing. If use_revision=True, this command will "block" until playstatus changes on the device. Must be logged in.
[ "Request", "raw", "data", "about", "what", "is", "currently", "playing", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/dmap/__init__.py#L31-L43
train
postlund/pyatv
pyatv/dmap/__init__.py
BaseDmapAppleTV.ctrl_int_cmd
def ctrl_int_cmd(self, cmd): """Perform a "ctrl-int" command.""" cmd_url = 'ctrl-int/1/{}?[AUTH]&prompt-id=0'.format(cmd) return self.daap.post(cmd_url)
python
def ctrl_int_cmd(self, cmd): """Perform a "ctrl-int" command.""" cmd_url = 'ctrl-int/1/{}?[AUTH]&prompt-id=0'.format(cmd) return self.daap.post(cmd_url)
[ "def", "ctrl_int_cmd", "(", "self", ",", "cmd", ")", ":", "cmd_url", "=", "'ctrl-int/1/{}?[AUTH]&prompt-id=0'", ".", "format", "(", "cmd", ")", "return", "self", ".", "daap", ".", "post", "(", "cmd_url", ")" ]
Perform a "ctrl-int" command.
[ "Perform", "a", "ctrl", "-", "int", "command", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/dmap/__init__.py#L65-L68
train
postlund/pyatv
pyatv/dmap/__init__.py
BaseDmapAppleTV.controlprompt_cmd
def controlprompt_cmd(self, cmd): """Perform a "controlpromptentry" command.""" data = tags.string_tag('cmbe', cmd) + tags.uint8_tag('cmcc', 0) return self.daap.post(_CTRL_PROMPT_CMD, data=data)
python
def controlprompt_cmd(self, cmd): """Perform a "controlpromptentry" command.""" data = tags.string_tag('cmbe', cmd) + tags.uint8_tag('cmcc', 0) return self.daap.post(_CTRL_PROMPT_CMD, data=data)
[ "def", "controlprompt_cmd", "(", "self", ",", "cmd", ")", ":", "data", "=", "tags", ".", "string_tag", "(", "'cmbe'", ",", "cmd", ")", "+", "tags", ".", "uint8_tag", "(", "'cmcc'", ",", "0", ")", "return", "self", ".", "daap", ".", "post", "(", "_C...
Perform a "controlpromptentry" command.
[ "Perform", "a", "controlpromptentry", "command", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/dmap/__init__.py#L70-L73
train
postlund/pyatv
pyatv/dmap/__init__.py
DmapRemoteControl.up
async def up(self): """Press key up.""" await self._send_commands( self._move('Down', 0, 20, 275), self._move('Move', 1, 20, 270), self._move('Move', 2, 20, 265), self._move('Move', 3, 20, 260), self._move('Move', 4, 20, 255), self....
python
async def up(self): """Press key up.""" await self._send_commands( self._move('Down', 0, 20, 275), self._move('Move', 1, 20, 270), self._move('Move', 2, 20, 265), self._move('Move', 3, 20, 260), self._move('Move', 4, 20, 255), self....
[ "async", "def", "up", "(", "self", ")", ":", "await", "self", ".", "_send_commands", "(", "self", ".", "_move", "(", "'Down'", ",", "0", ",", "20", ",", "275", ")", ",", "self", ".", "_move", "(", "'Move'", ",", "1", ",", "20", ",", "270", ")",...
Press key up.
[ "Press", "key", "up", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/dmap/__init__.py#L94-L103
train
postlund/pyatv
pyatv/dmap/__init__.py
DmapRemoteControl.down
async def down(self): """Press key down.""" await self._send_commands( self._move('Down', 0, 20, 250), self._move('Move', 1, 20, 255), self._move('Move', 2, 20, 260), self._move('Move', 3, 20, 265), self._move('Move', 4, 20, 270), s...
python
async def down(self): """Press key down.""" await self._send_commands( self._move('Down', 0, 20, 250), self._move('Move', 1, 20, 255), self._move('Move', 2, 20, 260), self._move('Move', 3, 20, 265), self._move('Move', 4, 20, 270), s...
[ "async", "def", "down", "(", "self", ")", ":", "await", "self", ".", "_send_commands", "(", "self", ".", "_move", "(", "'Down'", ",", "0", ",", "20", ",", "250", ")", ",", "self", ".", "_move", "(", "'Move'", ",", "1", ",", "20", ",", "255", ")...
Press key down.
[ "Press", "key", "down", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/dmap/__init__.py#L105-L114
train
postlund/pyatv
pyatv/dmap/__init__.py
DmapRemoteControl.left
async def left(self): """Press key left.""" await self._send_commands( self._move('Down', 0, 75, 100), self._move('Move', 1, 70, 100), self._move('Move', 3, 65, 100), self._move('Move', 4, 60, 100), self._move('Move', 5, 55, 100), s...
python
async def left(self): """Press key left.""" await self._send_commands( self._move('Down', 0, 75, 100), self._move('Move', 1, 70, 100), self._move('Move', 3, 65, 100), self._move('Move', 4, 60, 100), self._move('Move', 5, 55, 100), s...
[ "async", "def", "left", "(", "self", ")", ":", "await", "self", ".", "_send_commands", "(", "self", ".", "_move", "(", "'Down'", ",", "0", ",", "75", ",", "100", ")", ",", "self", ".", "_move", "(", "'Move'", ",", "1", ",", "70", ",", "100", ")...
Press key left.
[ "Press", "key", "left", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/dmap/__init__.py#L116-L125
train
postlund/pyatv
pyatv/dmap/__init__.py
DmapRemoteControl.right
async def right(self): """Press key right.""" await self._send_commands( self._move('Down', 0, 50, 100), self._move('Move', 1, 55, 100), self._move('Move', 3, 60, 100), self._move('Move', 4, 65, 100), self._move('Move', 5, 70, 100), ...
python
async def right(self): """Press key right.""" await self._send_commands( self._move('Down', 0, 50, 100), self._move('Move', 1, 55, 100), self._move('Move', 3, 60, 100), self._move('Move', 4, 65, 100), self._move('Move', 5, 70, 100), ...
[ "async", "def", "right", "(", "self", ")", ":", "await", "self", ".", "_send_commands", "(", "self", ".", "_move", "(", "'Down'", ",", "0", ",", "50", ",", "100", ")", ",", "self", ".", "_move", "(", "'Move'", ",", "1", ",", "55", ",", "100", "...
Press key right.
[ "Press", "key", "right", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/dmap/__init__.py#L127-L136
train
postlund/pyatv
pyatv/dmap/__init__.py
DmapRemoteControl.set_position
def set_position(self, pos): """Seek in the current playing media.""" time_in_ms = int(pos)*1000 return self.apple_tv.set_property('dacp.playingtime', time_in_ms)
python
def set_position(self, pos): """Seek in the current playing media.""" time_in_ms = int(pos)*1000 return self.apple_tv.set_property('dacp.playingtime', time_in_ms)
[ "def", "set_position", "(", "self", ",", "pos", ")", ":", "time_in_ms", "=", "int", "(", "pos", ")", "*", "1000", "return", "self", ".", "apple_tv", ".", "set_property", "(", "'dacp.playingtime'", ",", "time_in_ms", ")" ]
Seek in the current playing media.
[ "Seek", "in", "the", "current", "playing", "media", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/dmap/__init__.py#L185-L188
train
postlund/pyatv
examples/device_auth.py
authenticate_with_device
async def authenticate_with_device(atv): """Perform device authentication and print credentials.""" credentials = await atv.airplay.generate_credentials() await atv.airplay.load_credentials(credentials) try: await atv.airplay.start_authentication() pin = input('PIN Code: ') awai...
python
async def authenticate_with_device(atv): """Perform device authentication and print credentials.""" credentials = await atv.airplay.generate_credentials() await atv.airplay.load_credentials(credentials) try: await atv.airplay.start_authentication() pin = input('PIN Code: ') awai...
[ "async", "def", "authenticate_with_device", "(", "atv", ")", ":", "credentials", "=", "await", "atv", ".", "airplay", ".", "generate_credentials", "(", ")", "await", "atv", ".", "airplay", ".", "load_credentials", "(", "credentials", ")", "try", ":", "await", ...
Perform device authentication and print credentials.
[ "Perform", "device", "authentication", "and", "print", "credentials", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/examples/device_auth.py#L7-L19
train
postlund/pyatv
pyatv/mrp/chacha20.py
Chacha20Cipher.encrypt
def encrypt(self, data, nounce=None): """Encrypt data with counter or specified nounce.""" if nounce is None: nounce = self._out_counter.to_bytes(length=8, byteorder='little') self._out_counter += 1 return self._enc_out.seal(b'\x00\x00\x00\x00' + nounce, data, bytes())
python
def encrypt(self, data, nounce=None): """Encrypt data with counter or specified nounce.""" if nounce is None: nounce = self._out_counter.to_bytes(length=8, byteorder='little') self._out_counter += 1 return self._enc_out.seal(b'\x00\x00\x00\x00' + nounce, data, bytes())
[ "def", "encrypt", "(", "self", ",", "data", ",", "nounce", "=", "None", ")", ":", "if", "nounce", "is", "None", ":", "nounce", "=", "self", ".", "_out_counter", ".", "to_bytes", "(", "length", "=", "8", ",", "byteorder", "=", "'little'", ")", "self",...
Encrypt data with counter or specified nounce.
[ "Encrypt", "data", "with", "counter", "or", "specified", "nounce", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/chacha20.py#L15-L21
train
postlund/pyatv
pyatv/mrp/chacha20.py
Chacha20Cipher.decrypt
def decrypt(self, data, nounce=None): """Decrypt data with counter or specified nounce.""" if nounce is None: nounce = self._in_counter.to_bytes(length=8, byteorder='little') self._in_counter += 1 decrypted = self._enc_in.open( b'\x00\x00\x00\x00' + nounce, d...
python
def decrypt(self, data, nounce=None): """Decrypt data with counter or specified nounce.""" if nounce is None: nounce = self._in_counter.to_bytes(length=8, byteorder='little') self._in_counter += 1 decrypted = self._enc_in.open( b'\x00\x00\x00\x00' + nounce, d...
[ "def", "decrypt", "(", "self", ",", "data", ",", "nounce", "=", "None", ")", ":", "if", "nounce", "is", "None", ":", "nounce", "=", "self", ".", "_in_counter", ".", "to_bytes", "(", "length", "=", "8", ",", "byteorder", "=", "'little'", ")", "self", ...
Decrypt data with counter or specified nounce.
[ "Decrypt", "data", "with", "counter", "or", "specified", "nounce", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/chacha20.py#L23-L35
train
postlund/pyatv
pyatv/helpers.py
auto_connect
def auto_connect(handler, timeout=5, not_found=None, event_loop=None): """Short method for connecting to a device. This is a convenience method that create an event loop, auto discovers devices, picks the first device found, connects to it and passes it to a user provided handler. An optional error han...
python
def auto_connect(handler, timeout=5, not_found=None, event_loop=None): """Short method for connecting to a device. This is a convenience method that create an event loop, auto discovers devices, picks the first device found, connects to it and passes it to a user provided handler. An optional error han...
[ "def", "auto_connect", "(", "handler", ",", "timeout", "=", "5", ",", "not_found", "=", "None", ",", "event_loop", "=", "None", ")", ":", "# A coroutine is used so we can connect to the device while being inside", "# the event loop", "async", "def", "_handle", "(", "l...
Short method for connecting to a device. This is a convenience method that create an event loop, auto discovers devices, picks the first device found, connects to it and passes it to a user provided handler. An optional error handler can be provided that is called when no device was found. Very inflexi...
[ "Short", "method", "for", "connecting", "to", "a", "device", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/helpers.py#L7-L37
train
postlund/pyatv
pyatv/dmap/daap.py
DaapRequester.login
async def login(self): """Login to Apple TV using specified login id.""" # Do not use session.get_data(...) in login as that would end up in # an infinte loop. def _login_request(): return self.http.get_data( self._mkurl('login?[AUTH]&hasFP=1', ...
python
async def login(self): """Login to Apple TV using specified login id.""" # Do not use session.get_data(...) in login as that would end up in # an infinte loop. def _login_request(): return self.http.get_data( self._mkurl('login?[AUTH]&hasFP=1', ...
[ "async", "def", "login", "(", "self", ")", ":", "# Do not use session.get_data(...) in login as that would end up in", "# an infinte loop.", "def", "_login_request", "(", ")", ":", "return", "self", ".", "http", ".", "get_data", "(", "self", ".", "_mkurl", "(", "'lo...
Login to Apple TV using specified login id.
[ "Login", "to", "Apple", "TV", "using", "specified", "login", "id", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/dmap/daap.py#L41-L55
train
postlund/pyatv
pyatv/dmap/daap.py
DaapRequester.get
async def get(self, cmd, daap_data=True, timeout=None, **args): """Perform a DAAP GET command.""" def _get_request(): return self.http.get_data( self._mkurl(cmd, *args), headers=_DMAP_HEADERS, timeout=timeout) await self._assure_logged...
python
async def get(self, cmd, daap_data=True, timeout=None, **args): """Perform a DAAP GET command.""" def _get_request(): return self.http.get_data( self._mkurl(cmd, *args), headers=_DMAP_HEADERS, timeout=timeout) await self._assure_logged...
[ "async", "def", "get", "(", "self", ",", "cmd", ",", "daap_data", "=", "True", ",", "timeout", "=", "None", ",", "*", "*", "args", ")", ":", "def", "_get_request", "(", ")", ":", "return", "self", ".", "http", ".", "get_data", "(", "self", ".", "...
Perform a DAAP GET command.
[ "Perform", "a", "DAAP", "GET", "command", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/dmap/daap.py#L57-L66
train
postlund/pyatv
pyatv/dmap/daap.py
DaapRequester.get_url
def get_url(self, cmd, **args): """Expand the request URL for a request.""" return self.http.base_url + self._mkurl(cmd, *args)
python
def get_url(self, cmd, **args): """Expand the request URL for a request.""" return self.http.base_url + self._mkurl(cmd, *args)
[ "def", "get_url", "(", "self", ",", "cmd", ",", "*", "*", "args", ")", ":", "return", "self", ".", "http", ".", "base_url", "+", "self", ".", "_mkurl", "(", "cmd", ",", "*", "args", ")" ]
Expand the request URL for a request.
[ "Expand", "the", "request", "URL", "for", "a", "request", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/dmap/daap.py#L68-L70
train
postlund/pyatv
pyatv/dmap/daap.py
DaapRequester.post
async def post(self, cmd, data=None, timeout=None, **args): """Perform DAAP POST command with optional data.""" def _post_request(): headers = copy(_DMAP_HEADERS) headers['Content-Type'] = 'application/x-www-form-urlencoded' return self.http.post_data( ...
python
async def post(self, cmd, data=None, timeout=None, **args): """Perform DAAP POST command with optional data.""" def _post_request(): headers = copy(_DMAP_HEADERS) headers['Content-Type'] = 'application/x-www-form-urlencoded' return self.http.post_data( ...
[ "async", "def", "post", "(", "self", ",", "cmd", ",", "data", "=", "None", ",", "timeout", "=", "None", ",", "*", "*", "args", ")", ":", "def", "_post_request", "(", ")", ":", "headers", "=", "copy", "(", "_DMAP_HEADERS", ")", "headers", "[", "'Con...
Perform DAAP POST command with optional data.
[ "Perform", "DAAP", "POST", "command", "with", "optional", "data", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/dmap/daap.py#L72-L84
train
postlund/pyatv
pyatv/mrp/__init__.py
MrpRemoteControl.set_repeat
def set_repeat(self, repeat_mode): """Change repeat mode.""" # TODO: extract to convert module if int(repeat_mode) == const.REPEAT_STATE_OFF: state = 1 elif int(repeat_mode) == const.REPEAT_STATE_ALL: state = 2 elif int(repeat_mode) == const.REPEAT_STATE_T...
python
def set_repeat(self, repeat_mode): """Change repeat mode.""" # TODO: extract to convert module if int(repeat_mode) == const.REPEAT_STATE_OFF: state = 1 elif int(repeat_mode) == const.REPEAT_STATE_ALL: state = 2 elif int(repeat_mode) == const.REPEAT_STATE_T...
[ "def", "set_repeat", "(", "self", ",", "repeat_mode", ")", ":", "# TODO: extract to convert module", "if", "int", "(", "repeat_mode", ")", "==", "const", ".", "REPEAT_STATE_OFF", ":", "state", "=", "1", "elif", "int", "(", "repeat_mode", ")", "==", "const", ...
Change repeat mode.
[ "Change", "repeat", "mode", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/__init__.py#L116-L128
train
postlund/pyatv
pyatv/mrp/__init__.py
MrpPlaying.genre
def genre(self): """Genre of the currently playing song.""" if self._metadata: from pyatv.mrp.protobuf import ContentItem_pb2 transaction = ContentItem_pb2.ContentItem() transaction.ParseFromString(self._metadata)
python
def genre(self): """Genre of the currently playing song.""" if self._metadata: from pyatv.mrp.protobuf import ContentItem_pb2 transaction = ContentItem_pb2.ContentItem() transaction.ParseFromString(self._metadata)
[ "def", "genre", "(", "self", ")", ":", "if", "self", ".", "_metadata", ":", "from", "pyatv", ".", "mrp", ".", "protobuf", "import", "ContentItem_pb2", "transaction", "=", "ContentItem_pb2", ".", "ContentItem", "(", ")", "transaction", ".", "ParseFromString", ...
Genre of the currently playing song.
[ "Genre", "of", "the", "currently", "playing", "song", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/__init__.py#L172-L177
train
postlund/pyatv
pyatv/mrp/__init__.py
MrpPlaying.total_time
def total_time(self): """Total play time in seconds.""" now_playing = self._setstate.nowPlayingInfo if now_playing.HasField('duration'): return int(now_playing.duration) return None
python
def total_time(self): """Total play time in seconds.""" now_playing = self._setstate.nowPlayingInfo if now_playing.HasField('duration'): return int(now_playing.duration) return None
[ "def", "total_time", "(", "self", ")", ":", "now_playing", "=", "self", ".", "_setstate", ".", "nowPlayingInfo", "if", "now_playing", ".", "HasField", "(", "'duration'", ")", ":", "return", "int", "(", "now_playing", ".", "duration", ")", "return", "None" ]
Total play time in seconds.
[ "Total", "play", "time", "in", "seconds", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/__init__.py#L181-L187
train
postlund/pyatv
pyatv/mrp/__init__.py
MrpPlaying.shuffle
def shuffle(self): """If shuffle is enabled or not.""" info = self._get_command_info(CommandInfo_pb2.ChangeShuffleMode) return None if info is None else info.shuffleMode
python
def shuffle(self): """If shuffle is enabled or not.""" info = self._get_command_info(CommandInfo_pb2.ChangeShuffleMode) return None if info is None else info.shuffleMode
[ "def", "shuffle", "(", "self", ")", ":", "info", "=", "self", ".", "_get_command_info", "(", "CommandInfo_pb2", ".", "ChangeShuffleMode", ")", "return", "None", "if", "info", "is", "None", "else", "info", ".", "shuffleMode" ]
If shuffle is enabled or not.
[ "If", "shuffle", "is", "enabled", "or", "not", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/__init__.py#L205-L208
train
postlund/pyatv
pyatv/mrp/__init__.py
MrpPlaying.repeat
def repeat(self): """Repeat mode.""" info = self._get_command_info(CommandInfo_pb2.ChangeRepeatMode) return None if info is None else info.repeatMode
python
def repeat(self): """Repeat mode.""" info = self._get_command_info(CommandInfo_pb2.ChangeRepeatMode) return None if info is None else info.repeatMode
[ "def", "repeat", "(", "self", ")", ":", "info", "=", "self", ".", "_get_command_info", "(", "CommandInfo_pb2", ".", "ChangeRepeatMode", ")", "return", "None", "if", "info", "is", "None", "else", "info", ".", "repeatMode" ]
Repeat mode.
[ "Repeat", "mode", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/__init__.py#L211-L214
train
postlund/pyatv
pyatv/mrp/__init__.py
MrpMetadata.playing
async def playing(self): """Return what is currently playing.""" # TODO: This is hack-ish if self._setstate is None: await self.protocol.start() # No SET_STATE_MESSAGE received yet, use default if self._setstate is None: return MrpPlaying(protobuf.SetStat...
python
async def playing(self): """Return what is currently playing.""" # TODO: This is hack-ish if self._setstate is None: await self.protocol.start() # No SET_STATE_MESSAGE received yet, use default if self._setstate is None: return MrpPlaying(protobuf.SetStat...
[ "async", "def", "playing", "(", "self", ")", ":", "# TODO: This is hack-ish", "if", "self", ".", "_setstate", "is", "None", ":", "await", "self", ".", "protocol", ".", "start", "(", ")", "# No SET_STATE_MESSAGE received yet, use default", "if", "self", ".", "_se...
Return what is currently playing.
[ "Return", "what", "is", "currently", "playing", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/__init__.py#L250-L260
train
postlund/pyatv
pyatv/mrp/__init__.py
MrpPairingHandler.stop
async def stop(self, **kwargs): """Stop pairing process.""" if not self._pin_code: raise Exception('no pin given') # TODO: new exception self.service.device_credentials = \ await self.pairing_procedure.finish_pairing(self._pin_code)
python
async def stop(self, **kwargs): """Stop pairing process.""" if not self._pin_code: raise Exception('no pin given') # TODO: new exception self.service.device_credentials = \ await self.pairing_procedure.finish_pairing(self._pin_code)
[ "async", "def", "stop", "(", "self", ",", "*", "*", "kwargs", ")", ":", "if", "not", "self", ".", "_pin_code", ":", "raise", "Exception", "(", "'no pin given'", ")", "# TODO: new exception", "self", ".", "service", ".", "device_credentials", "=", "await", ...
Stop pairing process.
[ "Stop", "pairing", "process", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/__init__.py#L324-L330
train
postlund/pyatv
pyatv/mrp/tlv8.py
read_tlv
def read_tlv(data): """Parse TLV8 bytes into a dict. If value is larger than 255 bytes, it is split up in multiple chunks. So the same tag might occurr several times. """ def _parse(data, pos, size, result=None): if result is None: result = {} if pos >= size: ...
python
def read_tlv(data): """Parse TLV8 bytes into a dict. If value is larger than 255 bytes, it is split up in multiple chunks. So the same tag might occurr several times. """ def _parse(data, pos, size, result=None): if result is None: result = {} if pos >= size: ...
[ "def", "read_tlv", "(", "data", ")", ":", "def", "_parse", "(", "data", ",", "pos", ",", "size", ",", "result", "=", "None", ")", ":", "if", "result", "is", "None", ":", "result", "=", "{", "}", "if", "pos", ">=", "size", ":", "return", "result",...
Parse TLV8 bytes into a dict. If value is larger than 255 bytes, it is split up in multiple chunks. So the same tag might occurr several times.
[ "Parse", "TLV8", "bytes", "into", "a", "dict", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/tlv8.py#L19-L41
train
postlund/pyatv
pyatv/mrp/tlv8.py
write_tlv
def write_tlv(data): """Convert a dict to TLV8 bytes.""" tlv = b'' for key, value in data.items(): tag = bytes([int(key)]) length = len(value) pos = 0 # A tag with length > 255 is added multiple times and concatenated into # one buffer when reading the TLV again. ...
python
def write_tlv(data): """Convert a dict to TLV8 bytes.""" tlv = b'' for key, value in data.items(): tag = bytes([int(key)]) length = len(value) pos = 0 # A tag with length > 255 is added multiple times and concatenated into # one buffer when reading the TLV again. ...
[ "def", "write_tlv", "(", "data", ")", ":", "tlv", "=", "b''", "for", "key", ",", "value", "in", "data", ".", "items", "(", ")", ":", "tag", "=", "bytes", "(", "[", "int", "(", "key", ")", "]", ")", "length", "=", "len", "(", "value", ")", "po...
Convert a dict to TLV8 bytes.
[ "Convert", "a", "dict", "to", "TLV8", "bytes", "." ]
655dfcda4e2f9d1c501540e18da4f480d8bf0e70
https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/tlv8.py#L44-L61
train
tommikaikkonen/prettyprinter
prettyprinter/prettyprinter.py
comment
def comment(value, comment_text): """Annotates a value or a Doc with a comment. When printed by prettyprinter, the comment will be rendered next to the value or Doc. """ if isinstance(value, Doc): return comment_doc(value, comment_text) return comment_value(value, comment_text)
python
def comment(value, comment_text): """Annotates a value or a Doc with a comment. When printed by prettyprinter, the comment will be rendered next to the value or Doc. """ if isinstance(value, Doc): return comment_doc(value, comment_text) return comment_value(value, comment_text)
[ "def", "comment", "(", "value", ",", "comment_text", ")", ":", "if", "isinstance", "(", "value", ",", "Doc", ")", ":", "return", "comment_doc", "(", "value", ",", "comment_text", ")", "return", "comment_value", "(", "value", ",", "comment_text", ")" ]
Annotates a value or a Doc with a comment. When printed by prettyprinter, the comment will be rendered next to the value or Doc.
[ "Annotates", "a", "value", "or", "a", "Doc", "with", "a", "comment", "." ]
6b405884b8085eaf867e81c02b7b662b463ac5a0
https://github.com/tommikaikkonen/prettyprinter/blob/6b405884b8085eaf867e81c02b7b662b463ac5a0/prettyprinter/prettyprinter.py#L156-L164
train
tommikaikkonen/prettyprinter
prettyprinter/prettyprinter.py
register_pretty
def register_pretty(type=None, predicate=None): """Returns a decorator that registers the decorated function as the pretty printer for instances of ``type``. :param type: the type to register the pretty printer for, or a ``str`` to indicate the module and name, e.g.: ``'collections.Counter...
python
def register_pretty(type=None, predicate=None): """Returns a decorator that registers the decorated function as the pretty printer for instances of ``type``. :param type: the type to register the pretty printer for, or a ``str`` to indicate the module and name, e.g.: ``'collections.Counter...
[ "def", "register_pretty", "(", "type", "=", "None", ",", "predicate", "=", "None", ")", ":", "if", "type", "is", "None", "and", "predicate", "is", "None", ":", "raise", "ValueError", "(", "\"You must provide either the 'type' or 'predicate' argument.\"", ")", "if"...
Returns a decorator that registers the decorated function as the pretty printer for instances of ``type``. :param type: the type to register the pretty printer for, or a ``str`` to indicate the module and name, e.g.: ``'collections.Counter'``. :param predicate: a predicate function that ta...
[ "Returns", "a", "decorator", "that", "registers", "the", "decorated", "function", "as", "the", "pretty", "printer", "for", "instances", "of", "type", "." ]
6b405884b8085eaf867e81c02b7b662b463ac5a0
https://github.com/tommikaikkonen/prettyprinter/blob/6b405884b8085eaf867e81c02b7b662b463ac5a0/prettyprinter/prettyprinter.py#L462-L544
train
tommikaikkonen/prettyprinter
prettyprinter/prettyprinter.py
commentdoc
def commentdoc(text): """Returns a Doc representing a comment `text`. `text` is treated as words, and any whitespace may be used to break the comment to multiple lines.""" if not text: raise ValueError( 'Expected non-empty comment str, got {}'.format(repr(text)) ) commen...
python
def commentdoc(text): """Returns a Doc representing a comment `text`. `text` is treated as words, and any whitespace may be used to break the comment to multiple lines.""" if not text: raise ValueError( 'Expected non-empty comment str, got {}'.format(repr(text)) ) commen...
[ "def", "commentdoc", "(", "text", ")", ":", "if", "not", "text", ":", "raise", "ValueError", "(", "'Expected non-empty comment str, got {}'", ".", "format", "(", "repr", "(", "text", ")", ")", ")", "commentlines", "=", "[", "]", "for", "line", "in", "text"...
Returns a Doc representing a comment `text`. `text` is treated as words, and any whitespace may be used to break the comment to multiple lines.
[ "Returns", "a", "Doc", "representing", "a", "comment", "text", ".", "text", "is", "treated", "as", "words", "and", "any", "whitespace", "may", "be", "used", "to", "break", "the", "comment", "to", "multiple", "lines", "." ]
6b405884b8085eaf867e81c02b7b662b463ac5a0
https://github.com/tommikaikkonen/prettyprinter/blob/6b405884b8085eaf867e81c02b7b662b463ac5a0/prettyprinter/prettyprinter.py#L599-L654
train
tommikaikkonen/prettyprinter
prettyprinter/prettyprinter.py
build_fncall
def build_fncall( ctx, fndoc, argdocs=(), kwargdocs=(), hug_sole_arg=False, trailing_comment=None, ): """Builds a doc that looks like a function call, from docs that represent the function, arguments and keyword arguments. If ``hug_sole_arg`` is True, and the represented fun...
python
def build_fncall( ctx, fndoc, argdocs=(), kwargdocs=(), hug_sole_arg=False, trailing_comment=None, ): """Builds a doc that looks like a function call, from docs that represent the function, arguments and keyword arguments. If ``hug_sole_arg`` is True, and the represented fun...
[ "def", "build_fncall", "(", "ctx", ",", "fndoc", ",", "argdocs", "=", "(", ")", ",", "kwargdocs", "=", "(", ")", ",", "hug_sole_arg", "=", "False", ",", "trailing_comment", "=", "None", ",", ")", ":", "if", "callable", "(", "fndoc", ")", ":", "fndoc"...
Builds a doc that looks like a function call, from docs that represent the function, arguments and keyword arguments. If ``hug_sole_arg`` is True, and the represented functional call is done with a single non-keyword argument, the function call parentheses will hug the sole argument doc without...
[ "Builds", "a", "doc", "that", "looks", "like", "a", "function", "call", "from", "docs", "that", "represent", "the", "function", "arguments", "and", "keyword", "arguments", "." ]
6b405884b8085eaf867e81c02b7b662b463ac5a0
https://github.com/tommikaikkonen/prettyprinter/blob/6b405884b8085eaf867e81c02b7b662b463ac5a0/prettyprinter/prettyprinter.py#L849-L1003
train
tommikaikkonen/prettyprinter
prettyprinter/prettyprinter.py
PrettyContext.assoc
def assoc(self, key, value): """ Return a modified PrettyContext with ``key`` set to ``value`` """ return self._replace(user_ctx={ **self.user_ctx, key: value, })
python
def assoc(self, key, value): """ Return a modified PrettyContext with ``key`` set to ``value`` """ return self._replace(user_ctx={ **self.user_ctx, key: value, })
[ "def", "assoc", "(", "self", ",", "key", ",", "value", ")", ":", "return", "self", ".", "_replace", "(", "user_ctx", "=", "{", "*", "*", "self", ".", "user_ctx", ",", "key", ":", "value", ",", "}", ")" ]
Return a modified PrettyContext with ``key`` set to ``value``
[ "Return", "a", "modified", "PrettyContext", "with", "key", "set", "to", "value" ]
6b405884b8085eaf867e81c02b7b662b463ac5a0
https://github.com/tommikaikkonen/prettyprinter/blob/6b405884b8085eaf867e81c02b7b662b463ac5a0/prettyprinter/prettyprinter.py#L297-L304
train
tommikaikkonen/prettyprinter
prettyprinter/doc.py
align
def align(doc): """Aligns each new line in ``doc`` with the first new line. """ validate_doc(doc) def evaluator(indent, column, page_width, ribbon_width): return Nest(column - indent, doc) return contextual(evaluator)
python
def align(doc): """Aligns each new line in ``doc`` with the first new line. """ validate_doc(doc) def evaluator(indent, column, page_width, ribbon_width): return Nest(column - indent, doc) return contextual(evaluator)
[ "def", "align", "(", "doc", ")", ":", "validate_doc", "(", "doc", ")", "def", "evaluator", "(", "indent", ",", "column", ",", "page_width", ",", "ribbon_width", ")", ":", "return", "Nest", "(", "column", "-", "indent", ",", "doc", ")", "return", "conte...
Aligns each new line in ``doc`` with the first new line.
[ "Aligns", "each", "new", "line", "in", "doc", "with", "the", "first", "new", "line", "." ]
6b405884b8085eaf867e81c02b7b662b463ac5a0
https://github.com/tommikaikkonen/prettyprinter/blob/6b405884b8085eaf867e81c02b7b662b463ac5a0/prettyprinter/doc.py#L57-L64
train
tommikaikkonen/prettyprinter
prettyprinter/layout.py
smart_fitting_predicate
def smart_fitting_predicate( page_width, ribbon_frac, min_nesting_level, max_width, triplestack ): """ Lookahead until the last doc at the current indentation level. Pretty, but not as fast. """ chars_left = max_width while chars_left >= 0: if not triplestack: ...
python
def smart_fitting_predicate( page_width, ribbon_frac, min_nesting_level, max_width, triplestack ): """ Lookahead until the last doc at the current indentation level. Pretty, but not as fast. """ chars_left = max_width while chars_left >= 0: if not triplestack: ...
[ "def", "smart_fitting_predicate", "(", "page_width", ",", "ribbon_frac", ",", "min_nesting_level", ",", "max_width", ",", "triplestack", ")", ":", "chars_left", "=", "max_width", "while", "chars_left", ">=", "0", ":", "if", "not", "triplestack", ":", "return", "...
Lookahead until the last doc at the current indentation level. Pretty, but not as fast.
[ "Lookahead", "until", "the", "last", "doc", "at", "the", "current", "indentation", "level", ".", "Pretty", "but", "not", "as", "fast", "." ]
6b405884b8085eaf867e81c02b7b662b463ac5a0
https://github.com/tommikaikkonen/prettyprinter/blob/6b405884b8085eaf867e81c02b7b662b463ac5a0/prettyprinter/layout.py#L124-L208
train
tommikaikkonen/prettyprinter
prettyprinter/color.py
set_default_style
def set_default_style(style): """Sets default global style to be used by ``prettyprinter.cpprint``. :param style: the style to set, either subclass of ``pygments.styles.Style`` or one of ``'dark'``, ``'light'`` """ global default_style if style == 'dark': style = default_d...
python
def set_default_style(style): """Sets default global style to be used by ``prettyprinter.cpprint``. :param style: the style to set, either subclass of ``pygments.styles.Style`` or one of ``'dark'``, ``'light'`` """ global default_style if style == 'dark': style = default_d...
[ "def", "set_default_style", "(", "style", ")", ":", "global", "default_style", "if", "style", "==", "'dark'", ":", "style", "=", "default_dark_style", "elif", "style", "==", "'light'", ":", "style", "=", "default_light_style", "if", "not", "issubclass", "(", "...
Sets default global style to be used by ``prettyprinter.cpprint``. :param style: the style to set, either subclass of ``pygments.styles.Style`` or one of ``'dark'``, ``'light'``
[ "Sets", "default", "global", "style", "to", "be", "used", "by", "prettyprinter", ".", "cpprint", "." ]
6b405884b8085eaf867e81c02b7b662b463ac5a0
https://github.com/tommikaikkonen/prettyprinter/blob/6b405884b8085eaf867e81c02b7b662b463ac5a0/prettyprinter/color.py#L134-L151
train
tommikaikkonen/prettyprinter
prettyprinter/utils.py
intersperse
def intersperse(x, ys): """ Returns an iterable where ``x`` is inserted between each element of ``ys`` :type ys: Iterable """ it = iter(ys) try: y = next(it) except StopIteration: return yield y for y in it: yield x yield y
python
def intersperse(x, ys): """ Returns an iterable where ``x`` is inserted between each element of ``ys`` :type ys: Iterable """ it = iter(ys) try: y = next(it) except StopIteration: return yield y for y in it: yield x yield y
[ "def", "intersperse", "(", "x", ",", "ys", ")", ":", "it", "=", "iter", "(", "ys", ")", "try", ":", "y", "=", "next", "(", "it", ")", "except", "StopIteration", ":", "return", "yield", "y", "for", "y", "in", "it", ":", "yield", "x", "yield", "y...
Returns an iterable where ``x`` is inserted between each element of ``ys`` :type ys: Iterable
[ "Returns", "an", "iterable", "where", "x", "is", "inserted", "between", "each", "element", "of", "ys" ]
6b405884b8085eaf867e81c02b7b662b463ac5a0
https://github.com/tommikaikkonen/prettyprinter/blob/6b405884b8085eaf867e81c02b7b662b463ac5a0/prettyprinter/utils.py#L5-L23
train
tommikaikkonen/prettyprinter
prettyprinter/__init__.py
pprint
def pprint( object, stream=_UNSET_SENTINEL, indent=_UNSET_SENTINEL, width=_UNSET_SENTINEL, depth=_UNSET_SENTINEL, *, compact=False, ribbon_width=_UNSET_SENTINEL, max_seq_len=_UNSET_SENTINEL, sort_dict_keys=_UNSET_SENTINEL, end='\n' ): """Pretty print a Python value ``obje...
python
def pprint( object, stream=_UNSET_SENTINEL, indent=_UNSET_SENTINEL, width=_UNSET_SENTINEL, depth=_UNSET_SENTINEL, *, compact=False, ribbon_width=_UNSET_SENTINEL, max_seq_len=_UNSET_SENTINEL, sort_dict_keys=_UNSET_SENTINEL, end='\n' ): """Pretty print a Python value ``obje...
[ "def", "pprint", "(", "object", ",", "stream", "=", "_UNSET_SENTINEL", ",", "indent", "=", "_UNSET_SENTINEL", ",", "width", "=", "_UNSET_SENTINEL", ",", "depth", "=", "_UNSET_SENTINEL", ",", "*", ",", "compact", "=", "False", ",", "ribbon_width", "=", "_UNSE...
Pretty print a Python value ``object`` to ``stream``, which defaults to ``sys.stdout``. The output will not be colored. :param indent: number of spaces to add for each level of nesting. :param stream: the output stream, defaults to ``sys.stdout`` :param width: a soft maximum allowed number of columns i...
[ "Pretty", "print", "a", "Python", "value", "object", "to", "stream", "which", "defaults", "to", "sys", ".", "stdout", ".", "The", "output", "will", "not", "be", "colored", "." ]
6b405884b8085eaf867e81c02b7b662b463ac5a0
https://github.com/tommikaikkonen/prettyprinter/blob/6b405884b8085eaf867e81c02b7b662b463ac5a0/prettyprinter/__init__.py#L142-L195
train
tommikaikkonen/prettyprinter
prettyprinter/__init__.py
cpprint
def cpprint( object, stream=_UNSET_SENTINEL, indent=_UNSET_SENTINEL, width=_UNSET_SENTINEL, depth=_UNSET_SENTINEL, *, compact=False, ribbon_width=_UNSET_SENTINEL, max_seq_len=_UNSET_SENTINEL, sort_dict_keys=_UNSET_SENTINEL, style=None, end='\n' ): """Pretty print a Py...
python
def cpprint( object, stream=_UNSET_SENTINEL, indent=_UNSET_SENTINEL, width=_UNSET_SENTINEL, depth=_UNSET_SENTINEL, *, compact=False, ribbon_width=_UNSET_SENTINEL, max_seq_len=_UNSET_SENTINEL, sort_dict_keys=_UNSET_SENTINEL, style=None, end='\n' ): """Pretty print a Py...
[ "def", "cpprint", "(", "object", ",", "stream", "=", "_UNSET_SENTINEL", ",", "indent", "=", "_UNSET_SENTINEL", ",", "width", "=", "_UNSET_SENTINEL", ",", "depth", "=", "_UNSET_SENTINEL", ",", "*", ",", "compact", "=", "False", ",", "ribbon_width", "=", "_UNS...
Pretty print a Python value ``object`` to ``stream``, which defaults to sys.stdout. The output will be colored and syntax highlighted. :param indent: number of spaces to add for each level of nesting. :param stream: the output stream, defaults to sys.stdout :param width: a soft maximum allowed numb...
[ "Pretty", "print", "a", "Python", "value", "object", "to", "stream", "which", "defaults", "to", "sys", ".", "stdout", ".", "The", "output", "will", "be", "colored", "and", "syntax", "highlighted", "." ]
6b405884b8085eaf867e81c02b7b662b463ac5a0
https://github.com/tommikaikkonen/prettyprinter/blob/6b405884b8085eaf867e81c02b7b662b463ac5a0/prettyprinter/__init__.py#L198-L257
train
tommikaikkonen/prettyprinter
prettyprinter/__init__.py
install_extras
def install_extras( include=ALL_EXTRAS, *, exclude=EMPTY_SET, raise_on_error=False, warn_on_error=True ): """Installs extras. Installing an extra means registering pretty printers for objects from third party libraries and/or enabling integrations with other python programs. - ``'a...
python
def install_extras( include=ALL_EXTRAS, *, exclude=EMPTY_SET, raise_on_error=False, warn_on_error=True ): """Installs extras. Installing an extra means registering pretty printers for objects from third party libraries and/or enabling integrations with other python programs. - ``'a...
[ "def", "install_extras", "(", "include", "=", "ALL_EXTRAS", ",", "*", ",", "exclude", "=", "EMPTY_SET", ",", "raise_on_error", "=", "False", ",", "warn_on_error", "=", "True", ")", ":", "# noqa", "include", "=", "set", "(", "include", ")", "exclude", "=", ...
Installs extras. Installing an extra means registering pretty printers for objects from third party libraries and/or enabling integrations with other python programs. - ``'attrs'`` - automatically pretty prints classes created using the ``attrs`` package. - ``'dataclasses'`` - automatically pretty pri...
[ "Installs", "extras", "." ]
6b405884b8085eaf867e81c02b7b662b463ac5a0
https://github.com/tommikaikkonen/prettyprinter/blob/6b405884b8085eaf867e81c02b7b662b463ac5a0/prettyprinter/__init__.py#L273-L341
train
tommikaikkonen/prettyprinter
prettyprinter/__init__.py
set_default_config
def set_default_config( *, style=_UNSET_SENTINEL, max_seq_len=_UNSET_SENTINEL, width=_UNSET_SENTINEL, ribbon_width=_UNSET_SENTINEL, depth=_UNSET_SENTINEL, sort_dict_keys=_UNSET_SENTINEL ): """ Sets the default configuration values used when calling `pprint`, `cpprint`, or `pforma...
python
def set_default_config( *, style=_UNSET_SENTINEL, max_seq_len=_UNSET_SENTINEL, width=_UNSET_SENTINEL, ribbon_width=_UNSET_SENTINEL, depth=_UNSET_SENTINEL, sort_dict_keys=_UNSET_SENTINEL ): """ Sets the default configuration values used when calling `pprint`, `cpprint`, or `pforma...
[ "def", "set_default_config", "(", "*", ",", "style", "=", "_UNSET_SENTINEL", ",", "max_seq_len", "=", "_UNSET_SENTINEL", ",", "width", "=", "_UNSET_SENTINEL", ",", "ribbon_width", "=", "_UNSET_SENTINEL", ",", "depth", "=", "_UNSET_SENTINEL", ",", "sort_dict_keys", ...
Sets the default configuration values used when calling `pprint`, `cpprint`, or `pformat`, if those values weren't explicitly provided. Only overrides the values provided in the keyword arguments.
[ "Sets", "the", "default", "configuration", "values", "used", "when", "calling", "pprint", "cpprint", "or", "pformat", "if", "those", "values", "weren", "t", "explicitly", "provided", ".", "Only", "overrides", "the", "values", "provided", "in", "the", "keyword", ...
6b405884b8085eaf867e81c02b7b662b463ac5a0
https://github.com/tommikaikkonen/prettyprinter/blob/6b405884b8085eaf867e81c02b7b662b463ac5a0/prettyprinter/__init__.py#L344-L382
train
bcdev/jpy
setup.py
package_maven
def package_maven(): """ Run maven package lifecycle """ if not os.getenv('JAVA_HOME'): # make sure Maven uses the same JDK which we have used to compile # and link the C-code os.environ['JAVA_HOME'] = jdk_home_dir mvn_goal = 'package' log.info("Executing Maven goal '" + mvn_goa...
python
def package_maven(): """ Run maven package lifecycle """ if not os.getenv('JAVA_HOME'): # make sure Maven uses the same JDK which we have used to compile # and link the C-code os.environ['JAVA_HOME'] = jdk_home_dir mvn_goal = 'package' log.info("Executing Maven goal '" + mvn_goa...
[ "def", "package_maven", "(", ")", ":", "if", "not", "os", ".", "getenv", "(", "'JAVA_HOME'", ")", ":", "# make sure Maven uses the same JDK which we have used to compile", "# and link the C-code", "os", ".", "environ", "[", "'JAVA_HOME'", "]", "=", "jdk_home_dir", "mv...
Run maven package lifecycle
[ "Run", "maven", "package", "lifecycle" ]
ae813df536807fb839650a0b359aa90f8344dd79
https://github.com/bcdev/jpy/blob/ae813df536807fb839650a0b359aa90f8344dd79/setup.py#L153-L184
train
bcdev/jpy
setup.py
_write_jpy_config
def _write_jpy_config(target_dir=None, install_dir=None): """ Write out a well-formed jpyconfig.properties file for easier Java integration in a given location. """ if not target_dir: target_dir = _build_dir() args = [sys.executable, os.path.join(target_dir, 'jpyutil.py'...
python
def _write_jpy_config(target_dir=None, install_dir=None): """ Write out a well-formed jpyconfig.properties file for easier Java integration in a given location. """ if not target_dir: target_dir = _build_dir() args = [sys.executable, os.path.join(target_dir, 'jpyutil.py'...
[ "def", "_write_jpy_config", "(", "target_dir", "=", "None", ",", "install_dir", "=", "None", ")", ":", "if", "not", "target_dir", ":", "target_dir", "=", "_build_dir", "(", ")", "args", "=", "[", "sys", ".", "executable", ",", "os", ".", "path", ".", "...
Write out a well-formed jpyconfig.properties file for easier Java integration in a given location.
[ "Write", "out", "a", "well", "-", "formed", "jpyconfig", ".", "properties", "file", "for", "easier", "Java", "integration", "in", "a", "given", "location", "." ]
ae813df536807fb839650a0b359aa90f8344dd79
https://github.com/bcdev/jpy/blob/ae813df536807fb839650a0b359aa90f8344dd79/setup.py#L216-L236
train
bcdev/jpy
jpyutil.py
_get_module_path
def _get_module_path(name, fail=False, install_path=None): """ Find the path to the jpy jni modules. """ import imp module = imp.find_module(name) if not module and fail: raise RuntimeError("can't find module '" + name + "'") path = module[1] if not path and fail: raise RuntimeE...
python
def _get_module_path(name, fail=False, install_path=None): """ Find the path to the jpy jni modules. """ import imp module = imp.find_module(name) if not module and fail: raise RuntimeError("can't find module '" + name + "'") path = module[1] if not path and fail: raise RuntimeE...
[ "def", "_get_module_path", "(", "name", ",", "fail", "=", "False", ",", "install_path", "=", "None", ")", ":", "import", "imp", "module", "=", "imp", ".", "find_module", "(", "name", ")", "if", "not", "module", "and", "fail", ":", "raise", "RuntimeError"...
Find the path to the jpy jni modules.
[ "Find", "the", "path", "to", "the", "jpy", "jni", "modules", "." ]
ae813df536807fb839650a0b359aa90f8344dd79
https://github.com/bcdev/jpy/blob/ae813df536807fb839650a0b359aa90f8344dd79/jpyutil.py#L99-L113
train
bcdev/jpy
jpyutil.py
init_jvm
def init_jvm(java_home=None, jvm_dll=None, jvm_maxmem=None, jvm_classpath=None, jvm_properties=None, jvm_options=None, config_file=None, config=None): """ Creates a configured Java virtual machine which will be used by jp...
python
def init_jvm(java_home=None, jvm_dll=None, jvm_maxmem=None, jvm_classpath=None, jvm_properties=None, jvm_options=None, config_file=None, config=None): """ Creates a configured Java virtual machine which will be used by jp...
[ "def", "init_jvm", "(", "java_home", "=", "None", ",", "jvm_dll", "=", "None", ",", "jvm_maxmem", "=", "None", ",", "jvm_classpath", "=", "None", ",", "jvm_properties", "=", "None", ",", "jvm_options", "=", "None", ",", "config_file", "=", "None", ",", "...
Creates a configured Java virtual machine which will be used by jpy. :param java_home: The Java JRE or JDK home directory used to search JVM shared library, if 'jvm_dll' is omitted. :param jvm_dll: The JVM shared library file. My be inferred from 'java_home'. :param jvm_maxmem: The JVM maximum heap space, ...
[ "Creates", "a", "configured", "Java", "virtual", "machine", "which", "will", "be", "used", "by", "jpy", "." ]
ae813df536807fb839650a0b359aa90f8344dd79
https://github.com/bcdev/jpy/blob/ae813df536807fb839650a0b359aa90f8344dd79/jpyutil.py#L411-L459
train
KeepSafe/android-resource-remover
android_clean_app.py
run_lint_command
def run_lint_command(): """ Run lint command in the shell and save results to lint-result.xml """ lint, app_dir, lint_result, ignore_layouts = parse_args() if not lint_result: if not distutils.spawn.find_executable(lint): raise Exception( '`%s` executable could no...
python
def run_lint_command(): """ Run lint command in the shell and save results to lint-result.xml """ lint, app_dir, lint_result, ignore_layouts = parse_args() if not lint_result: if not distutils.spawn.find_executable(lint): raise Exception( '`%s` executable could no...
[ "def", "run_lint_command", "(", ")", ":", "lint", ",", "app_dir", ",", "lint_result", ",", "ignore_layouts", "=", "parse_args", "(", ")", "if", "not", "lint_result", ":", "if", "not", "distutils", ".", "spawn", ".", "find_executable", "(", "lint", ")", ":"...
Run lint command in the shell and save results to lint-result.xml
[ "Run", "lint", "command", "in", "the", "shell", "and", "save", "results", "to", "lint", "-", "result", ".", "xml" ]
f2b4fb5a6822da79c9b166e3250ca6bdc6ee06e8
https://github.com/KeepSafe/android-resource-remover/blob/f2b4fb5a6822da79c9b166e3250ca6bdc6ee06e8/android_clean_app.py#L87-L105
train
KeepSafe/android-resource-remover
android_clean_app.py
parse_lint_result
def parse_lint_result(lint_result_path, manifest_path): """ Parse lint-result.xml and create Issue for every problem found except unused strings referenced in AndroidManifest """ unused_string_pattern = re.compile('The resource `R\.string\.([^`]+)` appears to be unused') mainfest_string_refs = get_m...
python
def parse_lint_result(lint_result_path, manifest_path): """ Parse lint-result.xml and create Issue for every problem found except unused strings referenced in AndroidManifest """ unused_string_pattern = re.compile('The resource `R\.string\.([^`]+)` appears to be unused') mainfest_string_refs = get_m...
[ "def", "parse_lint_result", "(", "lint_result_path", ",", "manifest_path", ")", ":", "unused_string_pattern", "=", "re", ".", "compile", "(", "'The resource `R\\.string\\.([^`]+)` appears to be unused'", ")", "mainfest_string_refs", "=", "get_manifest_string_refs", "(", "mani...
Parse lint-result.xml and create Issue for every problem found except unused strings referenced in AndroidManifest
[ "Parse", "lint", "-", "result", ".", "xml", "and", "create", "Issue", "for", "every", "problem", "found", "except", "unused", "strings", "referenced", "in", "AndroidManifest" ]
f2b4fb5a6822da79c9b166e3250ca6bdc6ee06e8
https://github.com/KeepSafe/android-resource-remover/blob/f2b4fb5a6822da79c9b166e3250ca6bdc6ee06e8/android_clean_app.py#L138-L163
train
KeepSafe/android-resource-remover
android_clean_app.py
remove_resource_file
def remove_resource_file(issue, filepath, ignore_layouts): """ Delete a file from the filesystem """ if os.path.exists(filepath) and (ignore_layouts is False or issue.elements[0][0] != 'layout'): print('removing resource: {0}'.format(filepath)) os.remove(os.path.abspath(filepath))
python
def remove_resource_file(issue, filepath, ignore_layouts): """ Delete a file from the filesystem """ if os.path.exists(filepath) and (ignore_layouts is False or issue.elements[0][0] != 'layout'): print('removing resource: {0}'.format(filepath)) os.remove(os.path.abspath(filepath))
[ "def", "remove_resource_file", "(", "issue", ",", "filepath", ",", "ignore_layouts", ")", ":", "if", "os", ".", "path", ".", "exists", "(", "filepath", ")", "and", "(", "ignore_layouts", "is", "False", "or", "issue", ".", "elements", "[", "0", "]", "[", ...
Delete a file from the filesystem
[ "Delete", "a", "file", "from", "the", "filesystem" ]
f2b4fb5a6822da79c9b166e3250ca6bdc6ee06e8
https://github.com/KeepSafe/android-resource-remover/blob/f2b4fb5a6822da79c9b166e3250ca6bdc6ee06e8/android_clean_app.py#L166-L172
train
KeepSafe/android-resource-remover
android_clean_app.py
remove_resource_value
def remove_resource_value(issue, filepath): """ Read an xml file and remove an element which is unused, then save the file back to the filesystem """ if os.path.exists(filepath): for element in issue.elements: print('removing {0} from resource {1}'.format(element, filepath)) ...
python
def remove_resource_value(issue, filepath): """ Read an xml file and remove an element which is unused, then save the file back to the filesystem """ if os.path.exists(filepath): for element in issue.elements: print('removing {0} from resource {1}'.format(element, filepath)) ...
[ "def", "remove_resource_value", "(", "issue", ",", "filepath", ")", ":", "if", "os", ".", "path", ".", "exists", "(", "filepath", ")", ":", "for", "element", "in", "issue", ".", "elements", ":", "print", "(", "'removing {0} from resource {1}'", ".", "format"...
Read an xml file and remove an element which is unused, then save the file back to the filesystem
[ "Read", "an", "xml", "file", "and", "remove", "an", "element", "which", "is", "unused", "then", "save", "the", "file", "back", "to", "the", "filesystem" ]
f2b4fb5a6822da79c9b166e3250ca6bdc6ee06e8
https://github.com/KeepSafe/android-resource-remover/blob/f2b4fb5a6822da79c9b166e3250ca6bdc6ee06e8/android_clean_app.py#L175-L189
train
KeepSafe/android-resource-remover
android_clean_app.py
remove_unused_resources
def remove_unused_resources(issues, app_dir, ignore_layouts): """ Remove the file or the value inside the file depending if the whole file is unused or not. """ for issue in issues: filepath = os.path.join(app_dir, issue.filepath) if issue.remove_file: remove_resource_file(is...
python
def remove_unused_resources(issues, app_dir, ignore_layouts): """ Remove the file or the value inside the file depending if the whole file is unused or not. """ for issue in issues: filepath = os.path.join(app_dir, issue.filepath) if issue.remove_file: remove_resource_file(is...
[ "def", "remove_unused_resources", "(", "issues", ",", "app_dir", ",", "ignore_layouts", ")", ":", "for", "issue", "in", "issues", ":", "filepath", "=", "os", ".", "path", ".", "join", "(", "app_dir", ",", "issue", ".", "filepath", ")", "if", "issue", "."...
Remove the file or the value inside the file depending if the whole file is unused or not.
[ "Remove", "the", "file", "or", "the", "value", "inside", "the", "file", "depending", "if", "the", "whole", "file", "is", "unused", "or", "not", "." ]
f2b4fb5a6822da79c9b166e3250ca6bdc6ee06e8
https://github.com/KeepSafe/android-resource-remover/blob/f2b4fb5a6822da79c9b166e3250ca6bdc6ee06e8/android_clean_app.py#L192-L201
train
aws/aws-encryption-sdk-python
src/aws_encryption_sdk/caches/__init__.py
_encryption_context_hash
def _encryption_context_hash(hasher, encryption_context): """Generates the expected hash for the provided encryption context. :param hasher: Existing hasher to use :type hasher: cryptography.hazmat.primitives.hashes.Hash :param dict encryption_context: Encryption context to hash :returns: Complete ...
python
def _encryption_context_hash(hasher, encryption_context): """Generates the expected hash for the provided encryption context. :param hasher: Existing hasher to use :type hasher: cryptography.hazmat.primitives.hashes.Hash :param dict encryption_context: Encryption context to hash :returns: Complete ...
[ "def", "_encryption_context_hash", "(", "hasher", ",", "encryption_context", ")", ":", "serialized_encryption_context", "=", "serialize_encryption_context", "(", "encryption_context", ")", "hasher", ".", "update", "(", "serialized_encryption_context", ")", "return", "hasher...
Generates the expected hash for the provided encryption context. :param hasher: Existing hasher to use :type hasher: cryptography.hazmat.primitives.hashes.Hash :param dict encryption_context: Encryption context to hash :returns: Complete hash :rtype: bytes
[ "Generates", "the", "expected", "hash", "for", "the", "provided", "encryption", "context", "." ]
d182155d5fb1ef176d9e7d0647679737d5146495
https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/caches/__init__.py#L51-L62
train
aws/aws-encryption-sdk-python
src/aws_encryption_sdk/caches/__init__.py
build_encryption_materials_cache_key
def build_encryption_materials_cache_key(partition, request): """Generates a cache key for an encrypt request. :param bytes partition: Partition name for which to generate key :param request: Request for which to generate key :type request: aws_encryption_sdk.materials_managers.EncryptionMaterialsReque...
python
def build_encryption_materials_cache_key(partition, request): """Generates a cache key for an encrypt request. :param bytes partition: Partition name for which to generate key :param request: Request for which to generate key :type request: aws_encryption_sdk.materials_managers.EncryptionMaterialsReque...
[ "def", "build_encryption_materials_cache_key", "(", "partition", ",", "request", ")", ":", "if", "request", ".", "algorithm", "is", "None", ":", "_algorithm_info", "=", "b\"\\x00\"", "else", ":", "_algorithm_info", "=", "b\"\\x01\"", "+", "request", ".", "algorith...
Generates a cache key for an encrypt request. :param bytes partition: Partition name for which to generate key :param request: Request for which to generate key :type request: aws_encryption_sdk.materials_managers.EncryptionMaterialsRequest :returns: cache key :rtype: bytes
[ "Generates", "a", "cache", "key", "for", "an", "encrypt", "request", "." ]
d182155d5fb1ef176d9e7d0647679737d5146495
https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/caches/__init__.py#L65-L86
train