code string | signature string | docstring string | loss_without_docstring float64 | loss_with_docstring float64 | factor float64 |
|---|---|---|---|---|---|
# Avoid wasting time and bandwidth if we known that conversion will fail.
if not self.overwrite and os.path.exists(self.output):
raise ConversionError("File %s already exist and --overwrite not specified" % self.output)
video = self.download_video()
raw_slides = sel... | def create_presentation(self) | Create the presentation.
The audio track is mixed with the slides. The resulting file is saved as self.output
DownloadError is raised if some resources cannot be fetched.
ConversionError is raised if the final video cannot be created. | 8.221507 | 7.034091 | 1.168809 |
rvideo_path = self.presentation.metadata['video_path']
if self.presentation.client.cache:
video_path = self.presentation.client.cache.get_path(rvideo_path)
if not video_path:
video_path = self.download_video_no_cache()
self.presentation.c... | def download_video(self) | Downloads the video.
If self.client.cache_enabled is True, then the disk cache is used.
Returns:
The path where the video has been saved.
Raises:
DownloadError: If the video cannot be downloaded. | 2.792648 | 3.03799 | 0.919242 |
video_url = self.presentation.metadata['video_url']
video_path = self.presentation.metadata['video_path']
# After a while, when downloading a long video (> 1h), the RTMP server seems to reset the connection (rtmpdump
# returns exit code 2). The only way to get the full stream i... | def download_video_no_cache(self) | Downloads the video.
Returns:
The path where the video has been saved.
Raises:
DownloadError: If the video cannot be downloaded. | 3.978016 | 4.098183 | 0.970678 |
return self.presentation.client.download_all(self.presentation.metadata['slides'], self.tmp_dir) | def download_slides(self) | Download all SWF slides.
The location of the slides files are returned.
A DownloadError is raised if at least one of the slides cannot be download.. | 13.20704 | 13.504626 | 0.977964 |
url = get_url("/login.action", scheme="https")
params = {
'username': username,
'password': password,
'submit-login': '',
}
with contextlib.closing(self.opener.open(url, urllib.parse.urlencode(params))) as response:
if not "loginAc... | def login(self, username, password) | Log in.
AuthenticationFailedException exception is raised if authentication fails. | 3.986413 | 4.24486 | 0.939115 |
try:
with contextlib.closing(self.opener.open(url)) as response:
# InfoQ does not send a 404 but a 302 redirecting to a valid URL...
if response.code != 200 or response.url == INFOQ_404_URL:
raise DownloadError("%s not found" % url)
... | def fetch_no_cache(self, url) | Fetch the resource specified and return its content.
DownloadError is raised if the resource cannot be fetched. | 4.192702 | 4.29391 | 0.97643 |
if not filename:
filename = url.rsplit('/', 1)[1]
path = os.path.join(dir_path, filename)
content = self.fetch(url)
with open(path, "wb") as f:
f.write(content)
return path | def download(self, url, dir_path, filename=None) | Download the resources specified by url into dir_path. The resulting
file path is returned.
DownloadError is raised the resources cannot be downloaded. | 2.144767 | 2.286066 | 0.938191 |
# TODO: Implement parallel download
filenames = []
try:
for url in urls:
filenames.append(self.download(url, dir_path))
except DownloadError as e:
for filename in filenames:
os.remove(filename)
raise e
... | def download_all(self, urls, dir_path) | Download all the resources specified by urls into dir_path. The resulting
file paths is returned.
DownloadError is raised if at least one of the resources cannot be downloaded.
In the case already downloaded resources are erased. | 3.023194 | 3.047638 | 0.991979 |
# FIXME: self.system_stack_pointer -= 1
stack_pointer.decrement(1)
addr = stack_pointer.value
# log.info(
# log.error(
# "%x|\tpush $%x to %s stack at $%x\t|%s",
# self.last_op_address, byte, stack_pointer.name, addr,
# self.cfg.mem_info.... | def push_byte(self, stack_pointer, byte) | pushed a byte onto stack | 7.118391 | 7.104758 | 1.001919 |
addr = stack_pointer.value
byte = self.memory.read_byte(addr)
# log.info(
# log.error(
# "%x|\tpull $%x from %s stack at $%x\t|%s",
# self.last_op_address, byte, stack_pointer.name, addr,
# self.cfg.mem_info.get_shortest(self.last_op_address)
# ... | def pull_byte(self, stack_pointer) | pulled a byte from stack | 7.187656 | 7.121922 | 1.00923 |
assert register in (self.system_stack_pointer, self.user_stack_pointer)
def push(register_str, stack_pointer):
register_obj = self.register_str2object[register_str]
data = register_obj.value
# log.debug("\tpush %s with data $%x", register_obj.name, data)
... | def instruction_PSH(self, opcode, m, register) | All, some, or none of the processor registers are pushed onto stack
(with the exception of stack pointer itself).
A single register may be placed on the stack with the condition codes
set by doing an autodecrement store onto the stack (example: STX ,--S).
source code forms: b7 b6 b5 b4... | 3.151216 | 3.159732 | 0.997305 |
assert register in (self.system_stack_pointer, self.user_stack_pointer)
def pull(register_str, stack_pointer):
reg_obj = self.register_str2object[register_str]
reg_width = reg_obj.WIDTH # 8 / 16
if reg_width == 8:
data = self.pull_byte(stack... | def instruction_PUL(self, opcode, m, register) | All, some, or none of the processor registers are pulled from stack
(with the exception of stack pointer itself).
A single register may be pulled from the stack with condition codes set
by doing an autoincrement load from the stack (example: LDX ,S++).
source code forms: b7 b6 b5 b4 b3... | 2.862656 | 2.948564 | 0.970864 |
# Check if we have websocket proxy configured
websocket_proxy = request.registry.settings.get("pyramid_notebook.websocket_proxy", "")
if websocket_proxy.strip():
r = DottedNameResolver()
websocket_proxy = r.maybe_resolve(websocket_proxy)
if "upgrade" in request.headers.get("connec... | def proxy_it(request, port) | Proxy HTTP request to upstream IPython Notebook Tornado server. | 6.160785 | 6.052133 | 1.017953 |
if not notebook_context:
notebook_context = {}
# Override notebook Jinja templates
if "extra_template_paths" not in notebook_context:
notebook_context["extra_template_paths"] = [os.path.join(os.path.dirname(__file__), "server", "templates")]
# Furious invalid state follows if we ... | def prepare_notebook_context(request, notebook_context) | Fill in notebook context with default values. | 4.319164 | 4.263725 | 1.013002 |
security_check(request, username)
settings = request.registry.settings
notebook_folder = settings.get("pyramid_notebook.notebook_folder", None)
if not notebook_folder:
raise RuntimeError("Setting missing: pyramid_notebook.notebook_folder")
kill_timeout = settings.get("pyramid_noteboo... | def launch_on_demand(request, username, notebook_context) | See if we have notebook already running this context and if not then launch new one. | 3.012435 | 2.974335 | 1.01281 |
security_check(request, username)
manager = get_notebook_manager(request)
notebook_info = manager.get_context(username)
if not notebook_info:
raise HTTPInternalServerError("Apparently IPython Notebook daemon process is not running for {}".format(username))
if 'http_port' not in noteb... | def notebook_proxy(request, username) | Renders a IPython Notebook frame wrapper.
Starts or reattachs ot an existing Notebook session. | 7.672078 | 7.717363 | 0.994132 |
# The notebook manage now tries too hard to get the port allocated for the notebook user, making it slow
# TODO: Manage a proper state e.g. using Redis
notebook_info = launch_on_demand(request, username, notebook_context)
# Jump to the detault notebook
proxy_route = request.route_url("notebook... | def launch_notebook(request, username, notebook_context) | Renders a IPython Notebook frame wrapper.
Starts or reattachs ot an existing Notebook session. | 11.963227 | 12.485236 | 0.95819 |
manager = get_notebook_manager(request)
if manager.is_running(username):
manager.stop_notebook(username) | def shutdown_notebook(request, username) | Stop any running notebook for a user. | 3.997187 | 3.595927 | 1.111587 |
if isinstance(o, (set, tuple, list)):
return tuple([make_dict_hash(e) for e in o])
elif not isinstance(o, dict):
return hash(o)
new_o = copy.deepcopy(o)
for k, v in new_o.items():
new_o[k] = make_dict_hash(v)
return hash(tuple(frozenset(sorted(new_o.items())))) | def make_dict_hash(o) | Make a hash from a dictionary, list, tuple or set to any level, containing
only other hashable types (including any lists, tuples, sets, and dictionaries). | 1.918185 | 1.927128 | 0.995359 |
# Do we need to route IPython Notebook request from a different location
alternative_domain = request.registry.settings.get("pyramid_notebook.alternative_domain", "").strip()
if alternative_domain:
url = url.replace(request.host_url, alternative_domain)
return url | def route_to_alt_domain(request, url) | Route URL to a different subdomain.
Used to rewrite URLs to point to websocket serving domain. | 6.297433 | 7.117783 | 0.884746 |
r = index.row()
c = index.column()
if c > 0x10:
return (0x10 * r) + c - 0x11
else:
return (0x10 * r) + c | def qindex2index(index) | from a QIndex (row/column coordinate system), get the buffer index of the byte | 3.321239 | 2.593436 | 1.280632 |
r = index // 0x10
c = index % 0x10
return self.index(r, c) | def index2qindexb(self, index) | from a buffer index, get the QIndex (row/column coordinate system) of the byte pane | 5.177477 | 3.947152 | 1.311699 |
r = (index // 0x10)
c = index % 0x10 + 0x11
return self.index(r, c) | def index2qindexc(self, index) | from a buffer index, get the QIndex (row/column coordinate system) of the char pane | 5.442453 | 4.632208 | 1.174915 |
selection.select(self._model.index2qindexb(start_bindex), self._model.index2qindexb(end_bindex))
selection.select(self._model.index2qindexc(start_bindex), self._model.index2qindexc(end_bindex)) | def _bselect(self, selection, start_bindex, end_bindex) | add the given buffer indices to the given QItemSelection, both byte and char panes | 2.794919 | 2.24182 | 1.246718 |
self.select(QItemSelection(), QItemSelectionModel.Clear)
if start_bindex > end_bindex:
start_bindex, end_bindex = end_bindex, start_bindex
selection = QItemSelection()
if row_number(end_bindex) - row_number(start_bindex) == 0:
# all on one line
... | def _do_select(self, start_bindex, end_bindex) | select the given range by buffer indices
selects items like this:
..................
......xxxxxxxxxxxx
xxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxx
xxxxxxxxxxxx......
..................
*not* like this:
..................
... | 1.979495 | 2.079259 | 0.952019 |
m = self.model()
self._do_select(m.qindex2index(qindex1), m.qindex2index(qindex2)) | def _update_selection(self, qindex1, qindex2) | select the given range by qmodel indices | 5.177818 | 4.050082 | 1.278448 |
menu = QMenu(self)
index = self.view.indexAt(qpoint)
def add_action(menu, text, handler, icon=None):
a = None
if icon is None:
a = QAction(text, self)
else:
a = QAction(icon, text, self)
a.triggered.connect... | def get_context_menu(self, qpoint) | override this method to customize the context menu | 2.918469 | 2.894447 | 1.008299 |
utils.activate_user(activation_key)
# if not activated
success_url = utils.get_settings('REGISTRATION_API_ACTIVATION_SUCCESS_URL')
if success_url is not None:
return HttpResponseRedirect(success_url) | def activate(request, activation_key=None) | Given an an activation key, look up and activate the user
account corresponding to that key (if possible). | 4.788689 | 5.036966 | 0.950709 |
return {
REG_X: self.index_x.value,
REG_Y: self.index_y.value,
REG_U: self.user_stack_pointer.value,
REG_S: self.system_stack_pointer.value,
REG_PC: self.program_counter.value,
REG_A: self.accu_a.value,
REG_B: self.a... | def get_state(self) | used in unittests | 4.386695 | 4.274083 | 1.026348 |
self.index_x.set(state[REG_X])
self.index_y.set(state[REG_Y])
self.user_stack_pointer.set(state[REG_U])
self.system_stack_pointer.set(state[REG_S])
self.program_counter.set(state[REG_PC])
self.accu_a.set(state[REG_A])
self.accu_b.set(state[REG_B])
... | def set_state(self, state) | used in unittests | 3.041169 | 3.048176 | 0.997701 |
self.sync_callbacks_cyles[callback] = 0
self.sync_callbacks.append([callback_cycles, callback])
if self.quickest_sync_callback_cycles is None or \
self.quickest_sync_callback_cycles > callback_cycles:
self.quickest_sync_callback_cycles = callback_cycl... | def add_sync_callback(self, callback_cycles, callback) | Add a CPU cycle triggered callback | 3.126541 | 3.221058 | 0.970657 |
current_cycles = self.cycles
for callback_cycles, callback in self.sync_callbacks:
# get the CPU cycles count of the last call
last_call_cycles = self.sync_callbacks_cyles[callback]
if current_cycles - last_call_cycles > callback_cycles:
# th... | def call_sync_callbacks(self) | Call every sync callback with CPU cycles trigger | 4.374883 | 3.701743 | 1.181844 |
# https://wiki.python.org/moin/PythonSpeed/PerformanceTips#Avoiding_dots...
get_and_call_next_op = self.get_and_call_next_op
for __ in range(self.outer_burst_op_count):
for __ in range(self.inner_burst_op_count):
get_and_call_next_op()
self.call... | def burst_run(self) | Run CPU as fast as Python can... | 5.888181 | 5.452019 | 1.08 |
op_address, opcode2 = self.read_pc_byte()
paged_opcode = opcode * 256 + opcode2
# log.debug("$%x *** call paged opcode $%x" % (
# self.program_counter, paged_opcode
# ))
self.call_instruction_func(op_address - 1, paged_opcode) | def instruction_PAGE(self, opcode) | call op from page 2 or 3 | 7.065083 | 6.713645 | 1.052347 |
a = register.value
r = a + m + self.C
register.set(r)
# log.debug("$%x %02x ADC %s: %i + %i + %i = %i (=$%x)" % (
# self.program_counter, opcode, register.name,
# a, m, self.C, r, r
# ))
self.clear_HNZVC()
self.update_HNZVC_8(a, m, r) | def instruction_ADC(self, opcode, m, register) | Adds the contents of the C (carry) bit and the memory byte into an 8-bit
accumulator.
source code forms: ADCA P; ADCB P
CC bits "HNZVC": aaaaa | 5.744799 | 6.435113 | 0.892727 |
assert register.WIDTH == 16
old = register.value
r = old + m
register.set(r)
# log.debug("$%x %02x %02x ADD16 %s: $%02x + $%02x = $%02x" % (
# self.program_counter, opcode, m,
# register.name,
# old, m, r
# ))
self.clear_NZV... | def instruction_ADD16(self, opcode, m, register) | Adds the 16-bit memory value into the 16-bit accumulator
source code forms: ADDD P
CC bits "HNZVC": -aaaa | 4.045199 | 4.539795 | 0.891053 |
assert register.WIDTH == 8
old = register.value
r = old + m
register.set(r)
# log.debug("$%x %02x %02x ADD8 %s: $%02x + $%02x = $%02x" % (
# self.program_counter, opcode, m,
# register.name,
# old, m, r
# ))
self.clear_... | def instruction_ADD8(self, opcode, m, register) | Adds the memory byte into an 8-bit accumulator.
source code forms: ADDA P; ADDB P
CC bits "HNZVC": aaaaa | 4.757864 | 5.122667 | 0.928787 |
value = ~value # the bits of m inverted
self.clear_NZ()
self.update_NZ01_8(value)
return value | def COM(self, value) | CC bits "HNZVC": -aa01 | 31.464209 | 26.306648 | 1.196055 |
r = self.COM(value=m)
# log.debug("$%x COM memory $%x to $%x" % (
# self.program_counter, m, r,
# ))
return ea, r & 0xff | def instruction_COM_memory(self, opcode, ea, m) | Replaces the contents of memory location M with its logical complement.
source code forms: COM Q | 8.145715 | 9.131278 | 0.892067 |
register.set(self.COM(value=register.value)) | def instruction_COM_register(self, opcode, register) | Replaces the contents of accumulator A or B with its logical complement.
source code forms: COMA; COMB | 19.438749 | 24.72967 | 0.78605 |
a = self.accu_a.value
correction_factor = 0
a_hi = a & 0xf0 # MSN - Most Significant Nibble
a_lo = a & 0x0f # LSN - Least Significant Nibble
if a_lo > 0x09 or self.H: # cc & 0x20:
correction_factor |= 0x06
if a_hi > 0x80 and a_lo > 0x09:
... | def instruction_DAA(self, opcode) | The sequence of a single-byte add instruction on accumulator A (either
ADDA or ADCA) and a following decimal addition adjust instruction
results in a BCD addition with an appropriate carry bit. Both values to
be added must be in proper BCD form (each nibble such that: 0 <= nibble
<= 9). ... | 4.431305 | 3.999977 | 1.107833 |
r = a - 1
self.clear_NZV()
self.update_NZ_8(r)
if r == 0x7f:
self.V = 1
return r | def DEC(self, a) | Subtract one from the register. The carry bit is not affected, thus
allowing this instruction to be used as a loop counter in multiple-
precision computations. When operating on unsigned values, only BEQ and
BNE branches can be expected to behave consistently. When operating on
twos comp... | 8.962482 | 8.131034 | 1.102256 |
r = self.DEC(m)
# log.debug("$%x DEC memory value $%x -1 = $%x and write it to $%x \t| %s" % (
# self.program_counter,
# m, r, ea,
# self.cfg.mem_info.get_shortest(ea)
# ))
return ea, r & 0xff | def instruction_DEC_memory(self, opcode, ea, m) | Decrement memory location | 8.737802 | 8.600321 | 1.015986 |
a = register.value
r = self.DEC(a)
# log.debug("$%x DEC %s value $%x -1 = $%x" % (
# self.program_counter,
# register.name, a, r
# ))
register.set(r) | def instruction_DEC_register(self, opcode, register) | Decrement accumulator | 6.265666 | 6.534917 | 0.958798 |
a = register.value
r = self.INC(a)
r = register.set(r) | def instruction_INC_register(self, opcode, register) | Adds to the register. The carry bit is not affected, thus allowing this
instruction to be used as a loop counter in multiple-precision
computations. When operating on unsigned values, only the BEQ and BNE
branches can be expected to behave consistently. When operating on twos
complement ... | 9.645203 | 10.62326 | 0.907932 |
r = self.INC(m)
return ea, r & 0xff | def instruction_INC_memory(self, opcode, ea, m) | Adds to the register. The carry bit is not affected, thus allowing this
instruction to be used as a loop counter in multiple-precision
computations. When operating on unsigned values, only the BEQ and BNE
branches can be expected to behave consistently. When operating on twos
complement ... | 15.390609 | 23.229427 | 0.662548 |
# log.debug("$%04x LEA %s: Set %s to $%04x \t| %s" % (
# self.program_counter,
# register.name, register.name, ea,
# self.cfg.mem_info.get_shortest(ea)
# ))
register.set(ea)
self.Z = 0
self.set_Z16(ea) | def instruction_LEA_register(self, opcode, ea, register) | see instruction_LEA_pointer
LEAX and LEAY affect the Z (zero) bit to allow use of these registers
as counters and for MC6800 INX/DEX compatibility.
LEAX 10,X X+10 -> X Adds 5-bit constant 10 to X
LEAX 500,X X+500 -> X Adds 16-bit constant 500 to X
LEAY A,Y Y+A -... | 6.784484 | 7.264758 | 0.93389 |
r = self.accu_a.value * self.accu_b.value
self.accu_d.set(r)
self.Z = 1 if r == 0 else 0
self.C = 1 if r & 0x80 else 0 | def instruction_MUL(self, opcode) | Multiply the unsigned binary numbers in the accumulators and place the
result in both accumulators (ACCA contains the most-significant byte of
the result). Unsigned multiply allows multiple-precision operations.
The C (carry) bit allows rounding the most-significant byte through the
seq... | 3.3439 | 3.446276 | 0.970294 |
x = register.value
r = x * -1 # same as: r = ~x + 1
register.set(r)
# log.debug("$%04x NEG %s $%02x to $%02x" % (
# self.program_counter, register.name, x, r,
# ))
self.clear_NZVC()
self.update_NZVC_8(0, x, r) | def instruction_NEG_register(self, opcode, register) | Replaces the register with its twos complement. The C (carry) bit
represents a borrow and is set to the inverse of the resulting binary
carry. Note that 80 16 is replaced by itself and only in this case is
the V (overflow) bit set. The value 00 16 is also replaced by itself,
and only in ... | 5.786266 | 6.507107 | 0.889223 |
if opcode == 0x0 and ea == 0x0 and m == 0x0:
self._wrong_NEG += 1
if self._wrong_NEG > 10:
raise RuntimeError("Wrong PC ???")
else:
self._wrong_NEG = 0
r = m * -1 # same as: r = ~m + 1
# log.debug("$%04x NEG $%02x from %04x to... | def instruction_NEG_memory(self, opcode, ea, m) | Negate memory | 5.749314 | 5.771071 | 0.99623 |
a = register.value
r = a - m - self.C
register.set(r)
# log.debug("$%x %02x SBC %s: %i - %i - %i = %i (=$%x)" % (
# self.program_counter, opcode, register.name,
# a, m, self.C, r, r
# ))
self.clear_NZVC()
self.update_NZVC_8(a, m, r) | def instruction_SBC(self, opcode, m, register) | Subtracts the contents of memory location M and the borrow (in the C
(carry) bit) from the contents of the designated 8-bit register, and
places the result in that register. The C bit represents a borrow and is
set to the inverse of the resulting binary carry.
source code forms: SBCA P;... | 4.921041 | 5.57303 | 0.88301 |
b = self.accu_b.value
if b & 0x80 == 0:
self.accu_a.set(0x00)
d = self.accu_d.value
# log.debug("SEX: b=$%x ; $%x&0x80=$%x ; d=$%x", b, b, (b & 0x80), d)
self.clear_NZ()
self.update_NZ_16(d) | def instruction_SEX(self, opcode) | This instruction transforms a twos complement 8-bit value in accumulator
B into a twos complement 16-bit value in the D accumulator.
source code forms: SEX
CC bits "HNZVC": -aa0-
// 0x1d SEX inherent
case 0x1d:
WREG_A = (RREG_B & 0x80) ? 0xff : 0;
... | 4.738966 | 4.810562 | 0.985117 |
r = register.value
r_new = r - m
register.set(r_new)
# log.debug("$%x SUB8 %s: $%x - $%x = $%x (dez.: %i - %i = %i)" % (
# self.program_counter, register.name,
# r, m, r_new,
# r, m, r_new,
# ))
self.clear_NZVC()
if register... | def instruction_SUB(self, opcode, m, register) | Subtracts the value in memory location M from the contents of a
register. The C (carry) bit represents a borrow and is set to the
inverse of the resulting binary carry.
source code forms: SUBA P; SUBB P; SUBD P
CC bits "HNZVC": uaaaa | 3.597273 | 3.813245 | 0.943363 |
high, low = divmod(m, 16)
dst_reg = self._get_register_obj(low)
src_reg = self._get_register_obj(high)
src_value = convert_differend_width(src_reg, dst_reg)
dst_reg.set(src_value) | def instruction_TFR(self, opcode, m) | source code forms: TFR R1, R2
CC bits "HNZVC": ccccc | 4.710369 | 4.593257 | 1.025497 |
high, low = divmod(m, 0x10)
reg1 = self._get_register_obj(high)
reg2 = self._get_register_obj(low)
new_reg1_value = convert_differend_width(reg2, reg1)
new_reg2_value = convert_differend_width(reg1, reg2)
reg1.set(new_reg1_value)
reg2.set(new_reg2_value... | def instruction_EXG(self, opcode, m) | source code forms: EXG R1,R2
CC bits "HNZVC": ccccc | 3.279339 | 3.169501 | 1.034655 |
assert isinstance(data, binary_type), (
"is type: %s and not bytes/str: %s" % (type(data), repr(data))
)
addr = 0
lines = []
run = True
line_width = 4 + (width * 3) + 1
while run:
if add_addr:
line = ["%04i" % addr]
else:
line = []
... | def bin2hexline(data, add_addr=True, width=16) | Format binary data to a Hex-Editor like format...
e.g.:
with open("C:\Python27\python.exe", "rb") as f:
data = f.read(150)
print("\n".join(bin2hexline(data, width=16)))
0000 4d 5a 90 00 03 00 00 00 04 00 00 00 ff ff 00 00 MZ..............
0016 b8 00 00 00 00 00 00 00 40 00 00 00 00 00 00 ... | 2.833864 | 2.942301 | 0.963145 |
self.N = 0
self.Z = 1
self.V = 0
self.C = 0 | def update_0100(self) | CC bits "HNZVC": -0100 | 5.71738 | 3.28593 | 1.739958 |
values = []
for name in obj._attribs:
val = getattr(obj, name)
if isinstance(val, str):
val = repr(val)
val = str(val) if len(str(val)) < 10 else "(...)"
values.append((name, val))
values = ", ".join("{}={}".format(k, v) for k, v in values)
return "{}({})... | def _str(obj) | Show nicely the generic object received. | 2.750829 | 2.618309 | 1.050613 |
vals = ", ".join("{}={!r}".format(
name, getattr(obj, name)) for name in obj._attribs)
if vals:
t = "{}(name={}, {})".format(obj.__class__.__name__, obj.name, vals)
else:
t = "{}(name={})".format(obj.__class__.__name__, obj.name)
return t | def _repr(obj) | Show the received object as precise as possible. | 2.78548 | 2.809577 | 0.991423 |
klass = type(name, (SWFObject,),
{'__str__': _str, '__repr__': _repr, 'name': name})
return klass() | def _make_object(name) | Create a generic object for the tags. | 6.884912 | 6.116389 | 1.12565 |
with open(filename, 'rb') as fh:
return SWFParser(fh, read_twips) | def parsefile(filename, read_twips=True) | Parse a SWF.
If you have a file object already, just use SWFParser directly.
read_twips: True - return values as read from the SWF
False - return values in pixels (at 100% zoom) | 5.109832 | 4.180491 | 1.222304 |
fh = self._src
obj = _make_object("Header")
# first part of the header
obj.Signature = sign = "".join(chr(unpack_ui8(fh)) for _ in range(3))
obj.Version = self._version = unpack_ui8(fh)
obj.FileLength = file_length = unpack_ui32(fh)
# deal with compress... | def _get_header(self) | Parse the SWF header. | 4.738191 | 4.262652 | 1.111559 |
tags = []
while True:
tag_bf = unpack_ui16(self._src)
tag_type = tag_bf >> 6 # upper 10 bits
if tag_type == 0:
# the end
break
tag_len = tag_bf & 0x3f # last 6 bits
if tag_len == 0x3f:
... | def _process_tags(self) | Get a sequence of tags. | 3.344415 | 3.281062 | 1.019309 |
obj.CharacterID = unpack_ui16(self._src)
obj.TextBounds = self._get_struct_rect()
obj.TextMatrix = self._get_struct_matrix()
obj.GlyphBits = glyph_bits = unpack_ui8(self._src)
obj.AdvanceBits = advance_bits = unpack_ui8(self._src)
# textrecords
obj.TextR... | def _generic_definetext_parser(self, obj, rgb_struct) | Generic parser for the DefineTextN tags. | 2.774675 | 2.736405 | 1.013986 |
obj = _make_object("DefineText")
self._generic_definetext_parser(obj, self._get_struct_rgb)
return obj | def _handle_tag_definetext(self) | Handle the DefineText tag. | 18.503628 | 14.515374 | 1.274761 |
obj = _make_object("DefineText2")
self._generic_definetext_parser(obj, self._get_struct_rgba)
return obj | def _handle_tag_definetext2(self) | Handle the DefineText2 tag. | 17.495083 | 14.09333 | 1.241373 |
obj = _make_object("DefineEditText")
obj.CharacterID = unpack_ui16(self._src)
obj.Bounds = self._get_struct_rect()
bc = BitConsumer(self._src)
obj.HasText = bc.u_get(1)
obj.WordWrap = bc.u_get(1)
obj.Multiline = bc.u_get(1)
obj.Password = bc.u_ge... | def _handle_tag_defineedittext(self) | Handle the DefineEditText tag. | 2.215895 | 2.168938 | 1.021649 |
bc = BitConsumer(self._src)
obj.PlaceFlagHasClipActions = bc.u_get(1)
obj.PlaceFlagHasClipDepth = bc.u_get(1)
obj.PlaceFlagHasName = bc.u_get(1)
obj.PlaceFlagHasRatio = bc.u_get(1)
obj.PlaceFlagHasColorTransform = bc.u_get(1)
obj.PlaceFlagHasMatrix = bc.u... | def _generic_placeobject_parser(self, obj, version) | A generic parser for several PlaceObjectX. | 2.111942 | 2.073545 | 1.018517 |
obj = _make_object("DefineSprite")
obj.CharacterID = unpack_ui16(self._src)
obj.FrameCount = unpack_ui16(self._src)
tags = self._process_tags()
obj.ControlTags = tags
return obj | def _handle_tag_definesprite(self) | Handle the DefineSprite tag. | 7.114536 | 6.365517 | 1.117668 |
actions = []
while True:
action_code = unpack_ui8(self._src)
if action_code == 0:
break
action_name = ACTION_NAMES[action_code]
if action_code > 128:
# have a payload!
action_len = unpack_ui16(self.... | def _generic_action_parser(self) | Generic parser for Actions. | 4.012421 | 3.956204 | 1.01421 |
obj = _make_object("FileAttributes")
bc = BitConsumer(self._src)
bc.u_get(1) # reserved
obj.UseDirectBlit = bc.u_get(1)
obj.UseGPU = bc.u_get(1)
obj.HasMetadata = bc.u_get(1)
obj.ActionScript3 = bc.u_get(1)
bc.u_get(2) # reserved
obj.Us... | def _handle_tag_fileattributes(self) | Handle the FileAttributes tag. | 4.606323 | 4.310875 | 1.068536 |
obj = _make_object("DefineSceneAndFrameLabelData")
obj.SceneCount = self._get_struct_encodedu32()
for i in range(1, obj.SceneCount + 1):
setattr(obj, 'Offset{}'.format(i), self._get_struct_encodedu32())
setattr(obj, 'Name{}'.format(i), self._get_struct_string())
... | def _handle_tag_definesceneandframelabeldata(self) | Handle the DefineSceneAndFrameLabelData tag. | 2.477517 | 2.337731 | 1.059795 |
obj = _make_object("DefineShape4")
obj.ShapeId = unpack_ui16(self._src)
obj.ShapeBounds = self._get_struct_rect()
obj.EdgeBounds = self._get_struct_rect()
bc = BitConsumer(self._src)
bc.u_get(5) # reserved
obj.UsesFillWindingRule = bc.u_get(1)
o... | def _handle_tag_defineshape4(self) | Handle the DefineShape4 tag. | 5.318985 | 5.023209 | 1.058882 |
obj = _make_object("DefineMorphShape2")
obj.CharacterId = unpack_ui16(self._src)
obj.StartBounds = self._get_struct_rect()
obj.EndBounds = self._get_struct_rect()
obj.StartEdgeBounds = self._get_struct_rect()
obj.EndEdgeBounds = self._get_struct_rect()
b... | def _handle_tag_definemorphshape2(self) | Handle the DefineMorphShape2 tag. | 5.07902 | 4.896287 | 1.037321 |
obj = _make_object("RemoveObject")
obj.CharacterId = unpack_ui16(self._src)
obj.Depth = unpack_ui16(self._src)
return obj | def _handle_tag_removeobject(self) | Handle the RemoveObject tag. | 8.347514 | 7.112046 | 1.173715 |
obj = _make_object("RemoveObject2")
obj.Depth = unpack_ui16(self._src)
return obj | def _handle_tag_removeobject2(self) | Handle the RemoveObject2 tag. | 15.64525 | 12.676917 | 1.234153 |
obj = _make_object("DefineShape")
obj.ShapeId = unpack_ui16(self._src)
obj.ShapeBounds = self._get_struct_rect()
obj.Shapes = self._get_struct_shapewithstyle(1)
return obj | def _handle_tag_defineshape(self) | Handle the DefineShape tag. | 8.814453 | 7.783271 | 1.132487 |
obj.FontID = unpack_ui16(self._src)
bc = BitConsumer(self._src)
obj.FontFlagsHasLayout = bc.u_get(1)
obj.FontFlagsShiftJIS = bc.u_get(1)
obj.FontFlagsSmallText = bc.u_get(1)
obj.FontFlagsANSI = bc.u_get(1)
obj.FontFlagsWideOffsets = bc.u_get(1)
o... | def _generic_definefont_parser(self, obj) | A generic parser for several DefineFontX. | 2.562168 | 2.542907 | 1.007575 |
obj = _make_object("DefineButton2")
obj.ButtonId = unpack_ui16(self._src)
bc = BitConsumer(self._src)
bc.ReservedFlags = bc.u_get(7)
bc.TrackAsMenu = bc.u_get(1)
obj.ActionOffset = unpack_ui16(self._src)
# characters
obj.Characters = characters... | def _handle_tag_definebutton2(self) | Handle the DefineButton2 tag. | 3.084023 | 3.051301 | 1.010724 |
obj = _make_object("EnableDebugger2")
obj.Reserved = unpack_ui16(self._src)
obj.Password = self._get_struct_string()
return obj | def _handle_tag_enabledebugger2(self) | Handle the EnableDebugger2 tag. | 13.67708 | 11.992919 | 1.14043 |
obj = _make_object("ScriptLimits")
obj.MaxRecursionDepth = unpack_ui16(self._src)
obj.ScriptTimeoutSeconds = unpack_ui16(self._src)
return obj | def _handle_tag_scriptlimits(self) | Handle the ScriptLimits tag. | 6.814363 | 6.029456 | 1.130179 |
obj = _make_object("JPEGTables")
assert self._src.read(2) == b'\xFF\xD8' # SOI marker
eoimark1 = eoimark2 = None
allbytes = [b'\xFF\xD8']
while not (eoimark1 == b'\xFF' and eoimark2 == b'\xD9'):
newbyte = self._src.read(1)
allbytes.append(newbyte... | def _handle_tag_jpegtables(self) | Handle the JPEGTables tag. | 4.459273 | 4.238343 | 1.052127 |
obj = _make_object("DefineFontAlignZones")
obj.FontId = unpack_ui16(self._src)
bc = BitConsumer(self._src)
obj.CSMTableHint = bc.u_get(2)
obj.Reserved = bc.u_get(6)
obj.ZoneTable = zone_records = []
glyph_count = self._last_defined_glyphs_quantity
... | def _handle_tag_definefontalignzones(self) | Handle the DefineFontAlignZones tag. | 3.352465 | 3.304233 | 1.014597 |
obj = _make_object("DefineFontName")
obj.FontId = unpack_ui16(self._src)
obj.FontName = self._get_struct_string()
obj.FontCopyright = self._get_struct_string()
return obj | def _handle_tag_definefontname(self) | Handle the DefineFontName tag. | 5.84445 | 5.496569 | 1.06329 |
obj = _make_object("CSMTextSettings")
obj.TextId = unpack_ui16(self._src)
bc = BitConsumer(self._src)
obj.UseFlashType = bc.u_get(2)
obj.GridFit = bc.u_get(3)
obj.Reserved1 = bc.u_get(3)
obj.Thickness = unpack_float(self._src)
obj.Sharpness = unpa... | def _handle_tag_csmtextsettings(self) | Handle the CSMTextSettings tag. | 5.001838 | 4.790742 | 1.044063 |
bc = BitConsumer(self._src)
nbits = bc.u_get(5)
if self._read_twips:
return tuple(bc.s_get(nbits) for _ in range(4))
else:
return tuple(bc.s_get(nbits) / 20.0 for _ in range(4)) | def _get_struct_rect(self) | Get the RECT structure. | 6.316193 | 5.84701 | 1.080243 |
getter = unpack_ui16 if font_flags_wide_codes else unpack_ui8
data = {}
data['FontKerningCode1'] = getter(self._src)
data['FontKerningCode2'] = getter(self._src)
data['FontKerningAdjustment'] = unpack_si16(self._src)
return data | def _get_struct_kerningrecord(self, font_flags_wide_codes) | Get the KERNINGRECORD structure. | 3.792205 | 3.763475 | 1.007634 |
obj = _make_object("ClipActions")
# In SWF 5 and earlier, these are 2 bytes wide; in SWF 6
# and later 4 bytes
clipeventflags_size = 2 if self._version <= 5 else 4
clipactionend_size = 2 if self._version <= 5 else 4
all_zero = b"\x00" * clipactionend_size
... | def _get_struct_clipactions(self) | Get the several CLIPACTIONRECORDs. | 6.899096 | 6.726784 | 1.025616 |
data = []
while True:
t = self._src.read(1)
if t == b'\x00':
break
data.append(t)
val = b''.join(data)
return val.decode("utf8") | def _get_struct_string(self) | Get the STRING structure. | 3.461226 | 2.993404 | 1.156284 |
obj = _make_object("Matrix")
bc = BitConsumer(self._src)
# scale
obj.HasScale = bc.u_get(1)
if obj.HasScale:
obj.NScaleBits = n_scale_bits = bc.u_get(5)
obj.ScaleX = bc.fb_get(n_scale_bits)
obj.ScaleY = bc.fb_get(n_scale_bits)
... | def _get_struct_matrix(self) | Get the values for the MATRIX record. | 2.598207 | 2.507634 | 1.036119 |
obj = _make_object("CXformWithAlpha")
bc = BitConsumer(self._src)
obj.HasAddTerms = bc.u_get(1)
obj.HasMultTerms = bc.u_get(1)
obj.NBits = nbits = bc.u_get(4)
if obj.HasMultTerms:
obj.RedMultTerm = bc.s_get(nbits)
obj.GreenMultTerm = bc.... | def _get_struct_cxformwithalpha(self) | Get the values for the CXFORMWITHALPHA record. | 2.520759 | 2.390547 | 1.05447 |
shape_records = []
bc = BitConsumer(self._src)
while True:
type_flag = bc.u_get(1)
if type_flag:
# edge record
straight_flag = bc.u_get(1)
num_bits = bc.u_get(4)
if straight_flag:
... | def _get_shaperecords(self, num_fill_bits,
num_line_bits, shape_number) | Return an array of SHAPERECORDS. | 2.719214 | 2.702115 | 1.006328 |
obj = _make_object("Shape")
bc = BitConsumer(self._src)
obj.NumFillBits = n_fill_bits = bc.u_get(4)
obj.NumLineBits = n_line_bits = bc.u_get(4)
obj.ShapeRecords = self._get_shaperecords(
n_fill_bits, n_line_bits, 0)
return obj | def _get_struct_shape(self) | Get the values for the SHAPE record. | 6.758439 | 5.740908 | 1.177242 |
obj = _make_object("FillStyle")
obj.FillStyleType = style_type = unpack_ui8(self._src)
if style_type == 0x00:
if shape_number <= 2:
obj.Color = self._get_struct_rgb()
else:
obj.Color = self._get_struct_rgba()
if style_typ... | def _get_struct_fillstyle(self, shape_number) | Get the values for the FILLSTYLE record. | 2.63643 | 2.60018 | 1.013941 |
obj = _make_object("FillStyleArray")
obj.FillStyleCount = count = unpack_ui8(self._src)
if count == 0xFF:
obj.FillStyleCountExtended = count = unpack_ui16(self._src)
obj.FillStyles = [self._get_struct_fillstyle(shape_number)
for _ in range(c... | def _get_struct_fillstylearray(self, shape_number) | Get the values for the FILLSTYLEARRAY record. | 4.659026 | 4.47906 | 1.040179 |
obj = _make_object("LineStyleArray")
obj.LineStyleCount = count = unpack_ui8(self._src)
if count == 0xFF:
obj.LineStyleCountExtended = count = unpack_ui16(self._src)
obj.LineStyles = line_styles = []
for _ in range(count):
if shape_number <= 3:
... | def _get_struct_linestylearray(self, shape_number) | Get the values for the LINESTYLEARRAY record. | 2.722586 | 2.676835 | 1.017092 |
useful = []
while True:
byte = ord(self._src.read(1))
useful.append(byte)
if byte < 127:
# got all the useful bytes
break
# transform into bits reordering the bytes
useful = ['00000000' + bin(b)[2:] for b in us... | def _get_struct_encodedu32(self) | Get a EncodedU32 number. | 8.753782 | 8.066998 | 1.085135 |
obj = _make_object("ShapeWithStyle")
obj.FillStyles = self._get_struct_fillstylearray(shape_number)
obj.LineStyles = self._get_struct_linestylearray(shape_number)
bc = BitConsumer(self._src)
obj.NumFillBits = n_fill_bits = bc.u_get(4)
obj.NumlineBits = n_line_bit... | def _get_struct_shapewithstyle(self, shape_number) | Get the values for the SHAPEWITHSTYLE record. | 4.069268 | 3.973426 | 1.024121 |
obj = _make_object("Gradient")
bc = BitConsumer(self._src)
obj.SpreadMode = bc.u_get(2)
obj.InterpolationMode = bc.u_get(2)
obj.NumGradients = bc.u_get(4)
obj.GradientRecords = gradient_records = []
for _ in range(obj.NumGradients):
record = ... | def _get_struct_gradient(self, shape_number) | Get the values for the GRADIENT record. | 4.739174 | 4.505877 | 1.051776 |
obj = _make_object("FilterList")
obj.NumberOfFilters = unpack_ui8(self._src)
obj.Filter = filters = []
# how to decode each filter type (and name), according to the filter id
filter_type = [
("DropShadowFilter", self._get_struct_dropshadowfilter), # 0
... | def _get_struct_filterlist(self) | Get the values for the FILTERLIST record. | 3.159046 | 3.102274 | 1.0183 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.