




SCREAMING_SNAKE_CASE__       :      Optional[Any]  =   'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'

def      A      (      _SCREAMING_SNAKE_CASE    )	-> bytes:
       # Make sure the supplied data is a bytes-like object
       if not isinstance(_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE    ):
              lowerCamelCase   :      int			 =					f'''a bytes-like object is required, not \'{data.__class__.__name__}\''''
              raise TypeError(_SCREAMING_SNAKE_CASE    )

       lowerCamelCase   :      Optional[int]			 =					"".join(bin(_SCREAMING_SNAKE_CASE    )[2:].zfill(8    ) for byte in data    )

       lowerCamelCase   :      List[str]			 =					len(_SCREAMING_SNAKE_CASE    ) % 6 != 0

       if padding_needed:
              # The padding that will be added later
              lowerCamelCase   :      Optional[int]			 =					B"=" * ((6 - len(_SCREAMING_SNAKE_CASE    ) % 6) // 2)

              # Append binary_stream with arbitrary binary digits (0's by default) to make its
              # length a multiple of 6.
              binary_stream += "0" * (6 - len(_SCREAMING_SNAKE_CASE    ) % 6)
       else:
              lowerCamelCase   :      List[Any]			 =					B""

       # Encode every 6 binary digits to their corresponding Base64 character
       return (
           "".join(
               B64_CHARSET[int(binary_stream[index : index + 6] ,2    )]
               for index in range(0 ,len(_SCREAMING_SNAKE_CASE    ) ,6    )    ).encode()
           + padding
       )

def      A      (      _SCREAMING_SNAKE_CASE    )	-> bytes:
       # Make sure encoded_data is either a string or a bytes-like object
       if not isinstance(_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE    ) and not isinstance(_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE    ):
              lowerCamelCase   :      List[Any]			 =					(
                  "argument should be a bytes-like object or ASCII string, "
                  f'''not \'{encoded_data.__class__.__name__}\''''
              )
              raise TypeError(_SCREAMING_SNAKE_CASE    )

       # In case encoded_data is a bytes-like object, make sure it contains only
       # ASCII characters so we convert it to a string object
       if isinstance(_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE    ):
              try:
                     lowerCamelCase   :      Optional[Any]			 =					encoded_data.decode("utf-8"    )
              except UnicodeDecodeError:
                     raise ValueError("base64 encoded data should only contain ASCII characters"    )

       lowerCamelCase   :      Optional[Any]			 =					encoded_data.count("="    )

       # Check if the encoded string contains non base64 characters
       if padding:
              assert all(
                  char in B64_CHARSET for char in encoded_data[:-padding]    ), "Invalid base64 character(s) found."
       else:
              assert all(
                  char in B64_CHARSET for char in encoded_data    ), "Invalid base64 character(s) found."

       # Check the padding
       assert len(_SCREAMING_SNAKE_CASE    ) % 4 == 0 and padding < 3, "Incorrect padding"

       if padding:
              # Remove padding if there is one
              lowerCamelCase   :      Optional[Any]			 =					encoded_data[:-padding]

              lowerCamelCase   :      Tuple			 =					"".join(
                  bin(B64_CHARSET.index(_SCREAMING_SNAKE_CASE    )    )[2:].zfill(6    ) for char in encoded_data    )[: -padding * 2]
       else:
              lowerCamelCase   :      Dict			 =					"".join(
                  bin(B64_CHARSET.index(_SCREAMING_SNAKE_CASE    )    )[2:].zfill(6    ) for char in encoded_data    )

       lowerCamelCase   :      int			 =					[
           int(binary_stream[index : index + 8] ,2    )
           for index in range(0 ,len(_SCREAMING_SNAKE_CASE    ) ,8    )
       ]

       return bytes(_SCREAMING_SNAKE_CASE    )


if __name__ == "__main__":
       import doctest

       doctest.testmod()












from __future__ import annotations

import requests

def      A      (      _SCREAMING_SNAKE_CASE    )	-> dict:
       lowerCamelCase   :      Tuple			 =					f'''https://hacker-news.firebaseio.com/v0/item/{story_id}.json?print=pretty'''
       return requests.get(_SCREAMING_SNAKE_CASE    ).json()

def      A      (      _SCREAMING_SNAKE_CASE = 10    )	-> list[dict]:
       lowerCamelCase   :      str			 =					"https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty"
       lowerCamelCase   :      Any			 =					requests.get(_SCREAMING_SNAKE_CASE    ).json()[:max_stories]
       return [get_hackernews_story(_SCREAMING_SNAKE_CASE    ) for story_id in story_ids]

def      A      (      _SCREAMING_SNAKE_CASE = 10    )	-> str:
       lowerCamelCase   :      str			 =					hackernews_top_stories(_SCREAMING_SNAKE_CASE    )
       return "\n".join("* [{title}]({url})".format(**_SCREAMING_SNAKE_CASE    ) for story in stories    )


if __name__ == "__main__":
       print(hackernews_top_stories_as_markdown())






