python类flush()的实例源码

utils.py 文件源码 项目:quartz-browser 作者: ksharindam 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def print_status(progress, file_size, start):
    """
    This function - when passed as `on_progress` to `Video.download` - prints
    out the current download progress.

    :params progress:
        The lenght of the currently downloaded bytes.
    :params file_size:
        The total size of the video.
    :params start:
        The time when started
    """

    percent_done = int(progress) * 100. / file_size
    done = int(50 * progress / int(file_size))
    dt = (clock() - start)
    if dt > 0:
        stdout.write("\r  [%s%s][%3.2f%%] %s at %s/s " %
                     ('=' * done, ' ' * (50 - done), percent_done,
                      sizeof(file_size), sizeof(progress // dt)))
    stdout.flush()
run_network.py 文件源码 项目:Primate_Visual_System 作者: pablomc88 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def parallel_cone(pipe,cells,time,cone_input,cone_layer,Vis_dark,Vis_resting_potential):
    # Initialize array of cone_response copying cone_input
    cone_response = cone_input

    for cell in cells:
        if multiprocessing.current_process().name=="root":
            progress = 100*(cell-cells[0])/len(cells)
            stdout.write("\r progress: %d %%"% progress)
            stdout.flush()

        # Time-driven simulation
        for t in np.arange(0,time):
            # Update dynamics of the model
            cone_layer[cell].feedInput(cone_input[cell,t])
            cone_layer[cell].update()
            # Record response
            cone_response[cell,t] = (cone_layer[cell].LF_taum.last_values[0] -\
            cone_layer[cell].LF_tauh.last_values[0] - Vis_dark - Vis_resting_potential)

    pipe.send(cone_response[cells,:])
    pipe.close()

#! ================
#! Class runNetwork
#! ================
frying.py 文件源码 项目:DeepFryBot 作者: asdvek 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def fry(img):
    coords = find_chars(img)
    img = add_b_emojis(img, coords)
    img = add_laughing_emojis(img, 5)
    eyecoords = find_eyes(img)
    img = add_flares(img, eyecoords)

    # bulge at random coordinates
    [w, h] = [img.width - 1, img.height - 1]
    w *= np.random.random(1)
    h *= np.random.random(1)
    r = int(((img.width + img.height) / 10) * (np.random.random(1)[0] + 1))
    img = bulge(img, np.array([int(w), int(h)]), r, 3, 5, 1.8)

    # some finishing touches
    # print("Adding some finishing touches... ", end='')
    stdout.flush()
    img = add_noise(img, 0.2)
    img = change_contrast(img, 200)
    # print("Done")

    return img


# Downloads image from url to RAM, fries it and saves to disk
client.py 文件源码 项目:2FAssassin 作者: maxwellkoh 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def main():
    """
    Connect to an SNI-enabled server and request a specific hostname, specified
    by argv[1], of it.
    """
    if len(argv) < 2:
        print 'Usage: %s <hostname>' % (argv[0],)
        return 1

    client = socket()

    print 'Connecting...',
    stdout.flush()
    client.connect(('127.0.0.1', 8443))
    print 'connected', client.getpeername()

    client_ssl = Connection(Context(TLSv1_METHOD), client)
    client_ssl.set_connect_state()
    client_ssl.set_tlsext_host_name(argv[1])
    client_ssl.do_handshake()
    print 'Server subject is', client_ssl.get_peer_certificate().get_subject()
    client_ssl.close()
server.py 文件源码 项目:2FAssassin 作者: maxwellkoh 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def main():
    """
    Run an SNI-enabled server which selects between a few certificates in a
    C{dict} based on the handshake request it receives from a client.
    """
    port = socket()
    port.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
    port.bind(('', 8443))
    port.listen(3)

    print 'Accepting...',
    stdout.flush()
    server, addr = port.accept()
    print 'accepted', addr

    server_context = Context(TLSv1_METHOD)
    server_context.set_tlsext_servername_callback(pick_certificate)

    server_ssl = Connection(server_context, server)
    server_ssl.set_accept_state()
    server_ssl.do_handshake()
    server.close()
main.py 文件源码 项目:DaNet-Tensorflow 作者: khaotik 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test(self, dataset, subset='test', name='Test'):
        global g_args
        train_writer = tf.summary.FileWriter(
            os.path.join(hparams.SUMMARY_DIR,
                         str(datetime.datetime.now().strftime("%m%d_%H%M%S")) + ' ' + hparams.SUMMARY_TITLE), g_sess.graph)
        cli_report = {}
        for data_pt in dataset.epoch(
                subset, hparams.BATCH_SIZE * hparams.MAX_N_SIGNAL):
            # note: this disables dropout during test
            to_feed = dict(
                zip(self.train_feed_keys, (
                    np.reshape(data_pt[0], [hparams.BATCH_SIZE, hparams.MAX_N_SIGNAL, -1, hparams.FEATURE_SIZE]),
                    1.)))
            step_summary, step_fetch = g_sess.run(
                self.valid_fetches, to_feed)[:2]
            train_writer.add_summary(step_summary)
            stdout.write('.')
            stdout.flush()
            _dict_add(cli_report, step_fetch)
        stdout.write(name + ': %s\n' % (
            _dict_format(cli_report)))
engine.py 文件源码 项目:CAAPR 作者: Stargrazer82301 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def printStats(self):

        """ Print generation statistics
        :rtype: the printed statistics as string
        .. versionchanged:: 0.6
           The return of *printStats* method.
        """

        percent = self.currentGeneration * 100 / float(self.nGenerations)
        message = "Gen. %d (%.2f%%):" % (self.currentGeneration, percent)
        log.info(message)
        print(message,)
        sys_stdout.flush()
        self.internalPop.statistics()
        stat_ret = self.internalPop.printStats()
        return message + stat_ret

    # -----------------------------------------------------------------
engine.py 文件源码 项目:CAAPR 作者: Stargrazer82301 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def printStats(self):

        """ Print generation statistics
        :rtype: the printed statistics as string
        .. versionchanged:: 0.6
           The return of *printStats* method.
        """

        percent = self.currentGeneration * 100 / float(self.nGenerations)
        message = "Gen. %d (%.2f%%):" % (self.currentGeneration, percent)
        log.info(message)
        print(message,)
        sys_stdout.flush()
        self.internalPop.statistics()
        stat_ret = self.internalPop.printStats()
        return message + stat_ret

    # -----------------------------------------------------------------
rn_rnn_char.py 文件源码 项目:rngru 作者: rneilson 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def build_onehots(self, vocab_size=None):
        """Build one-hot encodings of each sequence."""

        # If we're passed a charset size, great - if not, fall back to inferring vocab size
        if vocab_size:
            self.charsize = vocab_size
            vocab = vocab_size
        else:
            vocab = self.charsize

        stderr.write("Constructing one-hot vector data...")
        stderr.flush()

        time1 = time.time()

        # These can be large, so we don't necessarily want them on the GPU
        # Thus they're not Theano shared vars
        # Also, numpy fancy indexing is fun!
        self.x_onehots = np.eye(vocab, dtype=th.config.floatX)[self.x_array]
        self.y_onehots = np.eye(vocab, dtype=th.config.floatX)[self.y_array]

        time2 = time.time()

        stderr.write("done!\nTook {0:.4f} ms.\n".format((time2 - time1) * 1000.0))
vis_graph.py 文件源码 项目:pyvisgraph 作者: TaipanRex 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _vis_graph(graph, points, worker, status):
    total_points = len(points)
    visible_edges = []
    if status:
        t0 = default_timer()
        points_done = 0
    for p1 in points:
        for p2 in visible_vertices(p1, graph, scan='half'):
            visible_edges.append(Edge(p1, p2))
        if status:
            points_done += 1
            avg_time = round((default_timer() - t0) / points_done, 3)
            time_stat = (points_done, total_points-points_done, avg_time)
            status = '\r\033[' + str(21*worker) + 'C[{:4}][{:4}][{:5.3f}] \r'
            stdout.write(status.format(*time_stat))
            stdout.flush()
    return visible_edges
fcrack.py 文件源码 项目:Python-Pentest-Tools 作者: proxyanon 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def run_chars(strhash, initial, final, chars, types):
    starttime = gmtime()[5]
    for n in range(initial, final + 1):
        for xs in product(chars, repeat=n):
            string=''.join(xs)
            if types == "md5" or types == "MD5":
                password = md5(string).hexdigest()
            elif types == "sha1" or types == "SHA1":
                password = sha1(string).hexdigest()
            elif types == "sha512" or types == "SHA512":
                password = sha512(string).hexdigest()
            else:
                print "[-] Este formato nao esta incluso no script, talvez voce tenha que fazer isso manualmente"
                exit()
            if strhash == password:
                final = gmtime()[5] - starttime
                print "\n[+] Crackeada => %s\n"%(string)
                print "[+] Duracao => %i segundos\n"%(final)
                print "\a"
                stdout.flush()
                exit()
            else:
                print "[-] Tentando => %s"%(string)
    final = gmtime()[5] - starttime
    print "\n[+] Duracao => %i segundos\n"%(final)
brouter.py 文件源码 项目:Python-Pentest-Tools 作者: proxyanon 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def bruteforce(host, port, uname, wordlist):
    try:
        lista = open(wordlist, "r")
    except IOError:
        stdout.write(colored(" [x] Error opening word list\n", "red", attrs=['bold']))
        exit()
    url = "http://"+host+":"+port+"/"
    init = time()
    for l in lista:
        pwd = l.strip()
        try:
            r=get(url, auth=(uname, pwd), timeout=3)
        except:
            stdout.write(colored("\n [-] There was an error connecting to the router %s\n"%(host), "red", attrs=['bold']))
            exit()
        if r.status_code == 200:
            stdout.write(colored("\n\n [+] Cracked => %s:%s\n [+] Duration => %s seconds\n\n"%(uname, pwd, time() - init), "green", attrs=['bold']))
            lista.close()
            exit()
        else:
            stdout.write(colored("\r [-] Current login %s:%s"%(uname, pwd), "yellow", attrs=['bold']))
            stdout.flush()
    print ""
    lista.close()
wd_generator.py 文件源码 项目:Python-Pentest-Tools 作者: proxyanon 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def generator(min_lenght, max_lenght, chars, name):
    lines = 0
    try:
        file=open(name, "w")
    except IOError:
        print "\n[x] Error : %s este caminho nao existe\n"%(name)
        exit()
    file_stats(max_lenght)
    print ""
    for n in range(min_lenght, max_lenght + 1):
        for xs in product(chars, repeat=n):
            lines = lines + 1
            string=''.join(xs)
            file.write(string + "\n")
            stdout.write('\r[+] Saving character `%s`' % string)
            stdout.flush()
    print "\a"
    file.close()
wd_generator.py 文件源码 项目:Python-Pentest-Tools 作者: proxyanon 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def generator_param(min_lenght, max_lenght, chars, name, param, value):
    try:
        file=open(name, "w")
    except IOError:
        print "\n[x] Error : %s este caminho nao existe\n"%(name)
        exit()
    file_stats(max_lenght)
    print ""
    for n in range(min_lenght, max_lenght + 1):
        for xs in product(chars, repeat=n):
            string=''.join(xs)
            if param == "-pre":
                file.write(value+string + "\n")
            elif param == "-pos":
                file.write(string+value + "\n")
            else:
                return 1
            if param == "-pre":
                stdout.write('\r[+] Saving character `%s%s`'%(value,string))
            elif param == "-pos":
                stdout.write('\r[+] Saving character `%s%s`'%(string,value))
            stdout.flush()
    print "\a"
    file.close()
deploy.py 文件源码 项目:lain-cli 作者: laincloud 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def check_deploy_result(operation, console, appname, auth_header):
    i = 0
    while True:
        s = (i % 3 + 1) * '.'
        if len(s) < 3:
            s = s + (3 - len(s)) * ' '
        i += 1
        stdout.write("\r%s... %s " % (operation, s))
        stdout.flush()
        sleep(0.5)
        result = app_status(console, appname, auth_header)
        if result:
            stdout.write("\r%s... %s. " % (operation, result))
            stdout.flush()
            stdout.write("\n")
            return result
download_save_and_freeze_mobilenet.py 文件源码 项目:imagenet_models_flask 作者: alesolano 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def download_and_uncompress_tarball(base_url, filename, data_dir):

  def _progress(count, block_size, total_size):
    stdout.write('\r>> Downloading %s %.1f%%' % (
        filename, float(count * block_size) / float(total_size) * 100.0))
    stdout.flush()

  tarball_url = base_url + filename
  filepath = osp.join(data_dir, filename)

  if not tf.gfile.Exists( osp.join(download_dir, model_dl) ):
    filepath, _ = urllib.request.urlretrieve(tarball_url, filepath, _progress)
    print()
    statinfo = stat(filepath)
    print('Successfully downloaded', filename, statinfo.st_size, 'bytes.')
  else:
    print('{} tarball already exists -- not downloading'.format(filename))

  tarfile.open(filepath, 'r:*').extractall(data_dir)
_optim_tf.py 文件源码 项目:AdaptiveOptim 作者: tomMoral 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def optimize(self, X, lmbd, Z=None, max_iter=1, tol=1e-5):
        if Z is None:
            batch_size = X.shape[0]
            K = self.D.shape[0]
            z_curr = np.zeros((batch_size, K))
        else:
            z_curr = np.copy(Z)
        self.train_cost, self.train_z = [], []
        feed = {self.X: X, self.Z: z_curr, self.lmbd: lmbd}
        for k in range(max_iter):
            z_curr[:], dz, cost = self.session.run(
                [self.step_optim, self.dz, self._cost], feed_dict=feed)
            self.train_cost += [cost]
            self.train_z += [np.copy(z_curr)]
            if dz < tol:
                print("\r{} reached optimal solution in {}-iteration"
                      .format(self.name, k))
                break
            out.write("\rIterative optimization ({}): {:7.1%} - {:.4e}"
                      "".format(self.name, k/max_iter, dz))
            out.flush()
        self.train_cost += [self.session.run(self._cost, feed_dict=feed)]
        print("\rIterative optimization ({}): {:7}".format(self.name, "done"))
        return z_curr
inputdevices.py 文件源码 项目:rticonnextdds-logparser 作者: rticommunity 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def print_progress(self, threshold=0, decimals=1, barLength=100):
        """Print a terminal progress bar."""
        # Based on @Greenstick's reply (https://stackoverflow.com/a/34325723)
        iteration = self.stream.tell()
        if iteration > self.file_size:
            return
        total = self.file_size
        if total == 0:
            return

        progress = 100.0 * iteration / total
        if self.progress and progress - self.progress < threshold:
            return

        self.progress = progress
        percents = ("%03." + str(decimals) + "f") % progress
        filledLength = int(round(barLength * iteration / float(total)))

        barText = '*' * filledLength + '-' * (barLength - filledLength)
        stdout.write('%s| %s%% Completed\r' % (barText, percents))
        stdout.flush()
bot.py 文件源码 项目:PixelCanvasBot 作者: RogerioBlanco 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def wait_time(self, data={'waitSeconds': None}):
        def complete(i, wait):
            return ((100 * (float(i) / float(wait))) * 50) / 100

        if data['waitSeconds'] is not None:
            wait = data['waitSeconds'] + (random.randint(2, 4) / 3.33)
            print(I18n.get('Waiting %s seconds') % str(wait))

            c = i = 0
            while c < 50:
                c = complete(i, wait)
                time.sleep(wait - i if i == int(wait) else 1)
                out.write("[{}]\0\r".format('+' * int(c) + '-' * (50 - int(c))))
                out.flush()
                i += 1
            out.write("\n")
            out.flush()
            return data['waitSeconds']
        return 99999999
pig.py 文件源码 项目:kali-linux-repo 作者: DynamicDesignz 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def LOG(message=None,type=None):
    if VERBOSITY<=0:
        return
    elif VERBOSITY==1:
        #minimal verbosity ...   dot style output
        if type in MSGSCHEME_MIN:
            message = MSGSCHEME_MIN[type]
            if DO_COLOR and type in COLORSCHEME:
                message = COLORSCHEME[type]%message
            stdout.write("%s"%message)
            stdout.flush()
    else:
        if type in MSGSCHEME:
            message = MSGSCHEME[type]%message
        if DO_COLOR and type in COLORSCHEME:
            message = COLORSCHEME[type]%message
        if MODE_FUZZ:
            stdout.write("[FUZZ] %s\n"% (message))
        else:
            stdout.write("%s\n"% (message))
        stdout.flush()
tests.py 文件源码 项目:SynthDB 作者: shawnrushefsky 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def try_it(qu):
    stdout.write("\r{} ---> ".format(qu))
    stdout.flush()
    passed = 0
    req = None
    try:
        req = qu.run(c)
        if basic_test(req):
            passed = 1
            stdout.write("PASS\n")
        else:
            fails.append(err_format(q, req))
            stdout.write("FAIL\n")
            print err_format(q, req)
            exit()
    except (preqlerrors.TopologyError, preqlerrors.ValueTypeError, preqlerrors.NonexistenceError) as e:
        errors.append(err_format(q, str(e.msg)))
        stdout.write("ERROR\n")
    stdout.flush()
    return passed, 1, req
blocklists_simple.py 文件源码 项目:exabgp-edgerouter 作者: infowolfe 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def fetch():
    a = IPSet([])
    for blocklist in blocklists:
        r = requests.get(blocklist)
        for line in r.iter_lines():
            if linefilter(line):
                a.add(makeprefix(linefilter(line)))

    for prefix in b:
        if b.len() > 0 and b.__contains__(prefix) and not a.__contains__(prefix):
            a.discard(prefix)
            stdout.write('withdraw route ' + str(prefix) + nexthop)
            stdout.flush()

    for prefix in a:
        if a.__contains__(prefix) and not b.__contains__(prefix):
            stdout.write('announce route ' + str(prefix) + nexthop)
            stdout.flush()

    b.add(a)
fballprofilepic.py 文件源码 项目:Facebook-Scripts 作者: Sunil02324 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def process_photos(photos):
  if 'error' in photos:
    print "Error = ", error
    raise Exception("Error in Response")

  no_of_photos = 0
  if 'data' not in photos:
    return
  while len(photos['data']) > 0:
    for photo in photos['data']:
      if 'tags' in photo:
        process_photo_tags(photo['tags'])
      if 'comments' in photo:
        process_photo_comments(photo['comments'])
      no_of_photos += 1
      stdout.write("\rNumber of Photos Processed = %d" % no_of_photos)
      stdout.flush()
    if 'paging' in photos and 'next' in photos['paging']:
      request_str = photos['paging']['next'].replace('https://graph.facebook.com/', '')
      request_str = request_str.replace('limit=25', 'limit=200')
      photos = graph.get(request_str)
    else:
      photos['data'] = []
connect4_play.py 文件源码 项目:mittmcts 作者: dbravender 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def dump_state(state, children=None, move=None):
    if children is None:
        children = []

    if state.current_player == 0:
        overall_percent = (sum(child.wins_by_player[0]
                               for child in children) / 1000.0) * 100
    else:
        overall_percent = None

    children = {
        child.move: {'ucb': child.ucb1(child.parent.current_player),
                     'visits': child.visits,
                     'wins': child.wins_by_player[child.parent.current_player]}
        for child in children}

    print(dumps({'state': state.__dict__,
                 'children': children,
                 'overall_percent': overall_percent,
                 'error': None},
                cls=GameEncoder))
    stdout.flush()
Client.py 文件源码 项目:Sample-Code 作者: meigrafd 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def update(self):
        while self.running:
            # Read the length of the image as a 32-bit unsigned int.
            data_len = struct.unpack('<L', self.connection.read(struct.calcsize('<L')))[0]
            if data_len:
                printD('Updating...')
                printD('data_len: %s' % data_len)
                data = self.connection.read(data_len)
                deserialized_data = msgpack.unpackb(data, object_hook=msgpack_numpy.decode)
                printD('Frame received')
                #print(deserialized_data)
                #stdout.flush()
                img = Image.fromarray(deserialized_data)
                newImage = ImageTk.PhotoImage(img)
                self.gui.stream_label.configure(image=newImage)
                self.gui.stream_label.image = newImage
                printD("image updated")
            else:
                time.sleep(0.001)
Client.py 文件源码 项目:Sample-Code 作者: meigrafd 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def update_2(self):
        if self.running == False:
            return
        # Read the length of the image as a 32-bit unsigned int.
        data_len = struct.unpack('<L', self.connection.read(struct.calcsize('<L')))[0]
        if data_len:
            printD('Updating...')
            printD('data_len: %s' % data_len)
            data = self.connection.read(data_len)
            deserialized_data = msgpack.unpackb(data, object_hook=msgpack_numpy.decode)
            printD('Frame received')
            #print(deserialized_data)
            #stdout.flush()
            img = Image.fromarray(deserialized_data)
            newImage = ImageTk.PhotoImage(img)
            self.gui.stream_label.configure(image=newImage)
            self.gui.stream_label.image = newImage
        self.gui.master.after(70, self.update_2)
Server.py 文件源码 项目:Sample-Code 作者: meigrafd 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def start(self):
        printD("streamserver: start")
        self.running = True
        while self.running:
            frame = self.videostream.read()
            serialized_data = msgpack.packb(frame, default=msgpack_numpy.encode)
            # Write the length of the capture to the stream and flush to ensure it actually gets sent
            data_len = len(serialized_data)
            printD("data_len: %d" % data_len)
            self.connection.write(struct.pack('<L', data_len))
            self.connection.flush()
            # Send the image data over the wire
            self.connection.write(serialized_data)
            self.connection.flush()
            printD("send.")
            sleep(0.001)
terminalwriter.py 文件源码 项目:py 作者: pytest-dev 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__(self, file=None, stringio=False, encoding=None):
        if file is None:
            if stringio:
                self.stringio = file = py.io.TextIO()
            else:
                from sys import stdout as file
        elif py.builtin.callable(file) and not (
             hasattr(file, "write") and hasattr(file, "flush")):
            file = WriteFile(file, encoding=encoding)
        if hasattr(file, "isatty") and file.isatty() and colorama:
            file = colorama.AnsiToWin32(file).stream
        self.encoding = encoding or getattr(file, 'encoding', "utf-8")
        self._file = file
        self.hasmarkup = should_do_markup(file)
        self._lastlen = 0
        self._chars_on_current_line = 0
terminalwriter.py 文件源码 项目:py 作者: pytest-dev 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def write_out(fil, msg):
    # XXX sometimes "msg" is of type bytes, sometimes text which
    # complicates the situation.  Should we try to enforce unicode?
    try:
        # on py27 and above writing out to sys.stdout with an encoding
        # should usually work for unicode messages (if the encoding is
        # capable of it)
        fil.write(msg)
    except UnicodeEncodeError:
        # on py26 it might not work because stdout expects bytes
        if fil.encoding:
            try:
                fil.write(msg.encode(fil.encoding))
            except UnicodeEncodeError:
                # it might still fail if the encoding is not capable
                pass
            else:
                fil.flush()
                return
        # fallback: escape all unicode characters
        msg = msg.encode("unicode-escape").decode("ascii")
        fil.write(msg)
    fil.flush()
client.py 文件源码 项目:cliFBChat 作者: blcc 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def _get(self, url, query=None, timeout=30):
        payload=self._generatePayload(query)
        a = 0
        while 1:
            try:
                a = self._session.get(url, headers=self._header, params=payload, timeout=timeout)
            except :
                #print(exc_info())
                a = a+1
                if self.listening:
                    stdout.write("_get "+url+" failed, retrying..."+str(a)+"\r")
                    stdout.flush()
                    continue
            break
        stdout.write("                                                                 \r")
        stdout.flush()
        return a


问题


面经


文章

微信
公众号

扫码关注公众号