'Get a token from the input stream (or from stack if it\'s nonempty)'

def get_token(self):

    if self.pushback:
        tok = self.pushback.popleft()
        if (self.debug >= 1):
            print ('shlex:    popping    token    ' + repr(tok))
        return tok
    raw = self.read_token()
    if (self.source is not None):
        while (raw == self.source):
            spec = self.sourcehook(self.read_token())
            if spec:
                (newfile, newstream) = spec
                self.push_source(newstream, newfile)
            raw = self.get_token()
    while (raw == self.eof):
        if (not self.filestack):
            return self.eof
        else:
            self.pop_source()
            raw = self.get_token()
    if (self.debug >= 1):
        if (raw != self.eof):
            print ('shlex:    token=' + repr(raw))
        else:
            print 'shlex:    token=EOF'
    return raw
