Skip to content

Commit c825ea0

Browse files
committed
about to upgrade pickleSocket
1 parent dbbb8b9 commit c825ea0

21 files changed

+57
-33
lines changed

book.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'''
2-
sys.argv[1] in ('sun', 'pad')
2+
A file system.
33
'''
44
print('Importing...')
55
import platform

cache_no_hash.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
'''
2+
Inefficiently cache and lookup function returns.
3+
'''
14
class cache:
25
def __init__(self, func):
36
self.func = func

console.py console/__init__.py

-3
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,3 @@ def console(namespace = {}, prompt = '>>> ', use_input = False, fixer = None):
166166
next(kernal)
167167
if result is not None:
168168
print(result)
169-
170-
if __name__ == '__main__':
171-
console({})

console/__main__.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from console import console
2+
console({})

kernal.py console/kernal.py

File renamed without changes.

forcemap.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'''
2-
Like dummy.Pool.map, but no limit of thread number.
2+
Like dummy.Pool.map, but no limit of number of threads.
33
'''
44
from threading import Thread, Lock, Condition
55
from queue import Queue

formula.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'''
2-
Evaluate beautiful formulas like √(2×3÷4)
2+
Evaluate beautiful formulas like √(2×3÷4)
33
'''
44
from console import console
55
from math import sqrt

friendly_time.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
'''
2+
Formatting time data in a friendly manner.
3+
'''
14
import time
25

36
def friendlyTime(raw_time=None):

lab.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
'''
2+
This is for me only.
3+
You won't get why this code is here.
4+
Give up.
5+
'''
16
from pickle_socket import PickleSocket
27
from io import BytesIO as IO
38
import socket

moretk.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'''
2-
by Daniel
2+
More tkinter gadgets
33
'''
44
import tkinter as tk
55
import threading
@@ -207,6 +207,9 @@ def insert(self, index, chars, *args):
207207
super(__class__,self).insert(index, chunk, *args)
208208

209209
def bilingualStringLen(string, fontsize = 18):
210+
'''
211+
counts a chinese character as length of 2.
212+
'''
210213
length = 0
211214
for char in string:
212215
if len(char.encode()) > 1:

my.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
'''
2+
My misc little tools.
3+
'''
14
class LockableInt(int):
25
def __init__(self, value = None):
36
super(__class__,self).__init__()

myfile.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
'''
2+
Unreliable file utils
3+
'''
14
import os
25
from os import path
36
from listen import listen

myhttp.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
'''
2+
Serves through a (super) simplified version of http protocol.
3+
Warning: Running this may expose your computer to attacks.
4+
Don't run this.
25
'''
36
from threading import Thread
47
from queue import Queue, Empty

mythread.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
'''
2+
My threading utils
3+
'''
14
from threading import Condition
25

36
class Safe(Condition):

oneship.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'''
22
一嗖传
3+
Transmit files over the internet / LAN
4+
No encryption! Consider everything you transmit broadcast to the entire network.
35
'''
46
print('importing...')
57
from recvfile import recvFile

pickle_preview.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
'''
2+
Preview a pickle file
3+
'''
14
import sys, pickle
25
from pprint import pprint
36

pickle_socket.py

+6-21
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,12 @@
11
'''
2-
WARNING: under Linux, socket.sendfile is overridden!!!
2+
A socket that supports object transmission.
33
'''
44
import socket
55
import pickle
66
from io import BytesIO
77
import sys
88
__all__ = ['PickleSocket', 'RemoteClosedUnexpectedly']
99

10-
if 'sendfile' not in dir(socket.socket):
11-
# Android
12-
def fakeSendfile(self, file, offset=0, count=None):
13-
start = file.tell()
14-
if offset != 0:
15-
file.seek(start + offset)
16-
read = file.read(4096)
17-
while read != b'':
18-
self.sendall(read)
19-
read = file.read(4096)
20-
return file.tell() - start - offset
21-
socket.socket.sendfile = fakeSendfile
22-
2310
class PickleSocket():
2411
def __init__(self,upon_this_socket=None):
2512
if upon_this_socket is None:
@@ -40,13 +27,11 @@ def shakeHands(self,banner='This is a pickleSocket by Daniel Chin. ',echo=True):
4027
input('Enter to exit...')
4128
sys.exit(1)
4229

43-
def bind(self,address,AB=False,dorm=False,local=False):
44-
'''if AB or dorm is True, address is no longer a tuple, but a port int.'''
45-
if AB:
46-
self.socket.bind(('10.209.1.45',address))
47-
elif dorm:
48-
self.socket.bind(('10.209.23.186',address))
49-
elif local:
30+
def bind(self,address,local=False):
31+
'''
32+
if `local` is True, address is no longer a tuple, but a port int.
33+
'''
34+
if local:
5035
self.socket.bind(('127.0.0.1',address))
5136
else:
5237
self.socket.bind(address)

port_forward.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'''
22
Provides fake p2p, port forwarding.
33
4-
54
Ignored the thread-danger of sockets.
65
Expect unexpected behaviors.
76
'''

readme.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
All the wheels I re-invented.
2+
3+
This repo has various useful python tools and utils.
4+
5+
I kinda documented them.
6+
7+
If you have questions or suggestions, please send email to [email protected]

recvall.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'''
2-
If no problem, del assert.
2+
Receive `size` bytes from `socket`. Blocks until gets all.
3+
Somehow doesn't handle socket closing.
4+
I will fix that when I have time.
35
'''
46

57
def recvall(socket, size, use_list = True):
@@ -14,6 +16,4 @@ def recvall(socket, size, use_list = True):
1416
recved = b''
1517
while len(recved) < size:
1618
recved += socket.recv(left)
17-
return recved
18-
assert len(recved) == size
19-
return result
19+
return recved

recvfile.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
'''
2+
receive a file from a socket with known length.
3+
'''
14
import jdt
25
from socket import socket as Socket
36

0 commit comments

Comments
 (0)