# Path: sc8pr/util.py
# def fileExt(fn, ext):
#     "Force file extension"
#     ext = [e.lower() for e in ([ext] if type(ext) is str else ext)]
#     if fn.split(".")[-1].lower() not in ext:
#         fn += "." + ext[0]
#     return fn


from threading import Thread
from io import BytesIO
from time import sleep
from urllib.request import urlopen
from urllib.parse import quote, urlparse
from os.path import abspath, isdir, isfile
from random import randint
from sc8pr.util import fileExt
import pygame
        s = e = p = 0
        for r in self._queue:
            if r.data is None: p += 1
            elif isinstance(r.data, Exception): e += 1
            else: s += 1
        return dict(success=s, error=e, pending=p)

    def flush(self):
        "Reset queue and return generator for response data"
        q = self._queue
        self._queue = []
        return self._iter(q, self._pySrf)

    @staticmethod
    def _iter(q, cb):
        "Iterate through response data"
        for item in q:
            item = item.wait().data
            try:
                if cb and isinstance(item, pygame.Surface): item = cb(item)
            except: pass
            yield item

    def _randName(self, ext=None):
        "Create a random file name"
        a = None
        v = self.index.values()
        letter = lambda: chr(ord('a') + randint(0, 25))
        while not a or a in v:
            a = "".join(letter() for i in range(8))

# Path: sc8pr/util.py
# def fileExt(fn, ext):
#     "Force file extension"
#     ext = [e.lower() for e in ([ext] if type(ext) is str else ext)]
#     if fn.split(".")[-1].lower() not in ext:
#         fn += "." + ext[0]
#     return fn


# Path: sc8pr/misc/webcache.py
from threading import Thread
from io import BytesIO
from time import sleep
from urllib.request import urlopen
from urllib.parse import quote, urlparse
from os.path import abspath, isdir, isfile
from random import randint
from sc8pr.util import fileExt
import pygame

        s = e = p = 0
        for r in self._queue:
            if r.data is None: p += 1
            elif isinstance(r.data, Exception): e += 1
            else: s += 1
        return dict(success=s, error=e, pending=p)

    def flush(self):
        "Reset queue and return generator for response data"
        q = self._queue
        self._queue = []
        return self._iter(q, self._pySrf)

    @staticmethod
    def _iter(q, cb):
        "Iterate through response data"
        for item in q:
            item = item.wait().data
            try:
                if cb and isinstance(item, pygame.Surface): item = cb(item)
            except: pass
            yield item

    def _randName(self, ext=None):
        "Create a random file name"
        a = None
        v = self.index.values()
        letter = lambda: chr(ord('a') + randint(0, 25))
        while not a or a in v:
            a = "".join(letter() for i in range(8))

            if ext is not None: a = fileExt(a, ext)