# Path: medea/https.py
# def generateResponseBytes(url, headers=None, timeout=1.0, buf=None, bufferSize=defaultBufferSize):
#     _, _, host, path = url.split('/', 3)
#     buf, bufferSize
#     if buf is None:
#         buf = bytearray(bufferSize)
#     bufferSize = len(buf)
#     try:
#         addr = socket.getaddrinfo(host, 443)[0][-1]
#     except IndexError:
#         raise Exception("No Wifi")
#     s = socket.socket()
#     s.connect(addr)
#     if hasattr(s, 'settimeout'):
#         s.settimeout(timeout)
#     try:
#         s = ssl.wrap_socket(s)
#         s.write(b'GET /')
#         s.write(path.encode('ascii'))
#         s.write(b' HTTP/1.1\r\nHost: ')
#         s.write(host.encode('ascii'))
#         s.write(b'\r\nUser-Agent: Cockle\r\n')
#         if headers is not None:
#             for header in headers:
#                 s.write(header)
#         s.write(b'\r\n')
#         remaining = None
#         while True:
#             if sys.implementation.name == "micropython":
#                 if remaining is None or bufferSize < remaining:
#                     count = s.readinto(buf)
#                 else: # read into memoryview shorter than backing buffer
#                     count = s.readinto(memoryview(buf)[:remaining])
#             else:
#                 if remaining is None or bufferSize < remaining:
#                     count = s.read(bufferSize, buf)
#                 else:
#                     count = s.read(remaining, memoryview(buf)[:remaining])
#             pos = 0
#             if count > 0:
#                 while pos < count:
#                     msg = yield buf[pos]
#                     if type(msg) is int: # allow signalling content length
#                         remaining = msg + 1 # CH mystifying off-by-one error
#                         msg = True # byte will be replayed
#                     if msg is not True:
#                         pos += 1
#                         if remaining is not None:
#                             remaining -= 1
#             else:
#                 break
#     except StopIteration:
#         pass # this is OK, expected
#     except GeneratorExit:
#         pass  # this is OK, expected
#     except SocketTimeoutError:
#         pass  # gave up awaiting for more from the socket
#     except BaseException as e:
#         print("Unexpected exception")
#         print(e)
#         raise
#     finally:
#         s.close()
# 
# Path: medea/twitter.py
# def createTwitterUrl(apiPath, getParams):
# def createTwitterTimelineUrl(screen_name, count=1, **k):
# def createTwitterSearchUrl(text, count=1, **k):
# def generateTimelineBytes(account, count=1, buf=None):
# def generateSearchBytes(text, count=1, buf=None):
# def generateTweets(tokenizer, gen):
#     def fieldGeneratorFactory(fieldName, gen):


from medea.https import generateResponseBytes
from medea.twitter import twitterHeaders, createTwitterTimelineUrl
import sys

twitterUrl = createTwitterTimelineUrl('realDonaldTrump', tweet_mode="extended")
byteGenerator = generateResponseBytes(twitterUrl, twitterHeaders)

try:
    while True:
        sys.stdout.write(chr(next(byteGenerator)))
except StopIteration:

# Path: medea/https.py
# def generateResponseBytes(url, headers=None, timeout=1.0, buf=None, bufferSize=defaultBufferSize):
#     _, _, host, path = url.split('/', 3)
#     buf, bufferSize
#     if buf is None:
#         buf = bytearray(bufferSize)
#     bufferSize = len(buf)
#     try:
#         addr = socket.getaddrinfo(host, 443)[0][-1]
#     except IndexError:
#         raise Exception("No Wifi")
#     s = socket.socket()
#     s.connect(addr)
#     if hasattr(s, 'settimeout'):
#         s.settimeout(timeout)
#     try:
#         s = ssl.wrap_socket(s)
#         s.write(b'GET /')
#         s.write(path.encode('ascii'))
#         s.write(b' HTTP/1.1\r\nHost: ')
#         s.write(host.encode('ascii'))
#         s.write(b'\r\nUser-Agent: Cockle\r\n')
#         if headers is not None:
#             for header in headers:
#                 s.write(header)
#         s.write(b'\r\n')
#         remaining = None
#         while True:
#             if sys.implementation.name == "micropython":
#                 if remaining is None or bufferSize < remaining:
#                     count = s.readinto(buf)
#                 else: # read into memoryview shorter than backing buffer
#                     count = s.readinto(memoryview(buf)[:remaining])
#             else:
#                 if remaining is None or bufferSize < remaining:
#                     count = s.read(bufferSize, buf)
#                 else:
#                     count = s.read(remaining, memoryview(buf)[:remaining])
#             pos = 0
#             if count > 0:
#                 while pos < count:
#                     msg = yield buf[pos]
#                     if type(msg) is int: # allow signalling content length
#                         remaining = msg + 1 # CH mystifying off-by-one error
#                         msg = True # byte will be replayed
#                     if msg is not True:
#                         pos += 1
#                         if remaining is not None:
#                             remaining -= 1
#             else:
#                 break
#     except StopIteration:
#         pass # this is OK, expected
#     except GeneratorExit:
#         pass  # this is OK, expected
#     except SocketTimeoutError:
#         pass  # gave up awaiting for more from the socket
#     except BaseException as e:
#         print("Unexpected exception")
#         print(e)
#         raise
#     finally:
#         s.close()
# 
# Path: medea/twitter.py
# def createTwitterUrl(apiPath, getParams):
# def createTwitterTimelineUrl(screen_name, count=1, **k):
# def createTwitterSearchUrl(text, count=1, **k):
# def generateTimelineBytes(account, count=1, buf=None):
# def generateSearchBytes(text, count=1, buf=None):
# def generateTweets(tokenizer, gen):
#     def fieldGeneratorFactory(fieldName, gen):


# Path: examples/scripts/twitterTimelineDumpResponse.py
from medea.https import generateResponseBytes
from medea.twitter import twitterHeaders, createTwitterTimelineUrl
import sys


twitterUrl = createTwitterTimelineUrl('realDonaldTrump', tweet_mode="extended")
byteGenerator = generateResponseBytes(twitterUrl, twitterHeaders)

try:
    while True:
        sys.stdout.write(chr(next(byteGenerator)))
except StopIteration:

    pass