Skip to content

Commit

Permalink
Upgrade version of Black
Browse files Browse the repository at this point in the history
  • Loading branch information
russss committed Nov 19, 2021
1 parent 5f74a1b commit a808603
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 26 deletions.
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
flake8==3.8.4
black==20.8b1
black==21.10b0
pytest==6.1.2
16 changes: 9 additions & 7 deletions emv/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@


class Card(object):
""" High-level card manipulation API """
"""High-level card manipulation API"""

def __init__(self, connection):
self.tp = TransmissionProtocol(connection)

def get_mf(self):
""" Get the master file (MF). """
"""Get the master file (MF)."""
return self.tp.exchange(SelectCommand(file_identifier=[0x3F, 0x00]))

def get_pse(self):
""" Get the Payment System Environment (PSE) file """
"""Get the Payment System Environment (PSE) file"""
return self.tp.exchange(SelectCommand("1PAY.SYS.DDF01"))

def list_applications(self):
""" List applications on the card """
"""List applications on the card"""
try:
return self._list_applications_sfi()
except ErrorResponse:
Expand Down Expand Up @@ -146,15 +146,15 @@ def get_application_data(self, afl):
return data

def verify_pin(self, pin):
""" Verify the PIN, raising an exception if it fails."""
"""Verify the PIN, raising an exception if it fails."""
res = self.tp.exchange(VerifyCommand(pin))
if type(res) == WarningResponse:
raise InvalidPINException(str(res))

return res

def generate_cap_value(self, pin, challenge=None, value=None):
""" Perform a transaction to generate the EMV CAP (Pinsentry) value. """
"""Perform a transaction to generate the EMV CAP (Pinsentry) value."""
apps = self.list_applications()

if len(apps) == 0:
Expand Down Expand Up @@ -182,7 +182,9 @@ def generate_cap_value(self, pin, challenge=None, value=None):
# It appears that Belgian cards use their own silliness.
# https://github.com/zoobab/EMVCAP/blob/master/EMV-CAP#L512
if Tag.IPB not in app_data:
raise EMVProtocolError("Issuer Proprietary Bitmap not found in application file")
raise EMVProtocolError(
"Issuer Proprietary Bitmap not found in application file"
)

self.verify_pin(pin)

Expand Down
10 changes: 3 additions & 7 deletions emv/command/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def get_reader(reader):


def run():
" Command line entrypoint "
"Command line entrypoint"
cli(obj={})


Expand Down Expand Up @@ -138,9 +138,7 @@ def info(ctx):
"1PAY.SYS.DDF01 not available (this is normal on some cards)", fg="yellow"
)
except Exception as e:
click.secho(
"Error reading 1PAY.SYS.DDF01 (may be normal): " + str(e), fg="red"
)
click.secho("Error reading 1PAY.SYS.DDF01 (may be normal): " + str(e), fg="red")

click.secho("\n2PAY.SYS.DDF01 (Index of apps for contactless payments)", bold=True)
try:
Expand All @@ -150,9 +148,7 @@ def info(ctx):
"2PAY.SYS.DDF01 not available (this is normal on some cards)", fg="yellow"
)
except Exception as e:
click.secho(
"Error reading 2PAY.SYS.DDF01 (may be normal): " + str(e), fg="red"
)
click.secho("Error reading 2PAY.SYS.DDF01 (may be normal): " + str(e), fg="red")

for app in apps:
click.secho(
Expand Down
4 changes: 2 additions & 2 deletions emv/protocol/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def __init__(self, pin):


class GenerateApplicationCryptogramCommand(CAPDU):
""" Defined in: EMV 4.3 Book 3 section 6.5.5 """
"""Defined in: EMV 4.3 Book 3 section 6.5.5"""

name = "Generate Application Cryptogram"

Expand All @@ -211,7 +211,7 @@ def __init__(self, crypto_type, data, cda_sig=False):


class GetProcessingOptions(CAPDU):
""" Defined in: EMV 4.3 Book 3 section 6.5.8 """
"""Defined in: EMV 4.3 Book 3 section 6.5.8"""

name = "Get Processing Opts"

Expand Down
6 changes: 3 additions & 3 deletions emv/protocol/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ def is_two_byte(val):


def is_continuation(val):
""" Any subsequent byte is a continuation byte if the MSB is set. """
"""Any subsequent byte is a continuation byte if the MSB is set."""
return val & 0b10000000 == 0b10000000


def is_constructed(val):
""" Check if a tag represents a "constructed" value, i.e. another TLV """
"""Check if a tag represents a "constructed" value, i.e. another TLV"""
return val & 0b00100000 == 0b00100000


Expand Down Expand Up @@ -74,7 +74,7 @@ def read_length(data):

@total_ordering
class Tag(object):
""" Represents a data tag. Provides ordering and pretty rendering."""
"""Represents a data tag. Provides ordering and pretty rendering."""

def __init__(self, value):
if type(value) in (list, tuple) and len(value) == 1:
Expand Down
10 changes: 5 additions & 5 deletions emv/protocol/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class DOL(OrderedDict):

@classmethod
def unmarshal(cls, data):
""" Construct a DOL object from the binary representation (as a list of bytes) """
"""Construct a DOL object from the binary representation (as a list of bytes)"""
dol = cls()
i = 0
while i < len(data):
Expand All @@ -152,11 +152,11 @@ def unmarshal(cls, data):
return dol

def size(self):
""" Total size of the resulting structure in bytes. """
"""Total size of the resulting structure in bytes."""
return sum(self.values())

def unserialise(self, data):
""" Parse an input stream of bytes and return a TLV object. """
"""Parse an input stream of bytes and return a TLV object."""
if self.size() != len(data):
raise Exception(
"Incorrect input size (expecting %s bytes, got %s)"
Expand Down Expand Up @@ -190,7 +190,7 @@ def serialise(self, data):


class TagList(list):
""" A list of tags. """
"""A list of tags."""

@classmethod
def unmarshal(cls, data):
Expand All @@ -204,7 +204,7 @@ def unmarshal(cls, data):


class CVMRule(object):
""" EMV 4.3 book 3 appendix C3 """
"""EMV 4.3 book 3 appendix C3"""

RULES = {
# 0b00000000: "Fail CVM processing",
Expand Down
2 changes: 1 addition & 1 deletion emv/transmission.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class TransmissionProtocol(object):
"""

def __init__(self, connection):
""" Connection should be a pyscard connection. """
"""Connection should be a pyscard connection."""
self.log = logging.getLogger(__name__)
self.connection = connection
self.connection.connect(connection.T0_protocol)
Expand Down

0 comments on commit a808603

Please sign in to comment.