xasm 1.2.1__py310-none-any.whl → 1.2.1.dev0__py310-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
xasm/assemble.py CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env python
2
2
  import ast
3
3
  import re
4
- from typing import Any, List, Optional
4
+ from typing import Optional
5
5
 
6
6
  import xdis
7
7
  from xdis import get_opcode, load_module
@@ -21,7 +21,7 @@ class Instruction: # (Mbytecode.Instruction):
21
21
  s = "%4d: " % self.line_no
22
22
  else:
23
23
  s = " " * 6
24
- s += f"{self.opname:15}"
24
+ s += "%-15s" % self.opname
25
25
  if self.arg is not None:
26
26
  s += f"\t{self.arg}"
27
27
  return s
@@ -29,7 +29,7 @@ class Instruction: # (Mbytecode.Instruction):
29
29
  pass
30
30
 
31
31
 
32
- def is_int(s: Any) -> bool:
32
+ def is_int(s) -> bool:
33
33
  try:
34
34
  int(s)
35
35
  return True
@@ -41,7 +41,7 @@ def match_lineno(s: str):
41
41
  return re.match(r"^\d+:", s)
42
42
 
43
43
 
44
- def get_opname_operand(opc, fields: List[str]):
44
+ def get_opname_operand(opc, fields):
45
45
  assert len(fields) > 0
46
46
  opname = fields[0]
47
47
  if opc.opmap[opname] < opc.HAVE_ARGUMENT:
@@ -63,7 +63,7 @@ def get_opname_operand(opc, fields: List[str]):
63
63
 
64
64
 
65
65
  class Assembler:
66
- def __init__(self, python_version, is_pypy) -> None:
66
+ def __init__(self, python_version, is_pypy):
67
67
  self.opc = get_opcode(python_version, is_pypy)
68
68
  self.code_list = []
69
69
  self.codes = [] # FIXME use a better name
@@ -76,7 +76,7 @@ class Assembler:
76
76
  self.code = None
77
77
  self.siphash = None
78
78
 
79
- def code_init(self, python_version=None) -> None:
79
+ def code_init(self, python_version=None):
80
80
  if self.python_version is None and python_version:
81
81
  self.python_version = python_version
82
82
 
@@ -102,19 +102,19 @@ class Assembler:
102
102
 
103
103
  self.code.instructions = []
104
104
 
105
- def update_lists(self, co, label, backpatch) -> None:
105
+ def update_lists(self, co, label, backpatch):
106
106
  self.code_list.append(co)
107
107
  self.codes.append(self.code)
108
108
  self.label.append(label)
109
109
  self.backpatch.append(backpatch)
110
110
 
111
- def print_instructions(self) -> None:
111
+ def print_instructions(self):
112
112
  for inst in self.code.instructions:
113
113
  if inst.line_no:
114
114
  print()
115
115
  print(inst)
116
116
 
117
- def warn(self, mess: str) -> None:
117
+ def warn(self, mess: str):
118
118
  """
119
119
  Print an error message and record that we warned, unless we have already errored.
120
120
  """
@@ -122,7 +122,7 @@ class Assembler:
122
122
  if self.status != "errored":
123
123
  self.status = "warning"
124
124
 
125
- def err(self, mess: str) -> None:
125
+ def err(self, mess: str):
126
126
  """
127
127
  Print an error message and record that we errored.
128
128
  """
@@ -130,7 +130,7 @@ class Assembler:
130
130
  self.status = "errored"
131
131
 
132
132
 
133
- def asm_file(path) -> Optional[Assembler]:
133
+ def asm_file(path):
134
134
  offset = 0
135
135
  methods = {}
136
136
  method_name = None
@@ -413,7 +413,7 @@ def asm_file(path) -> Optional[Assembler]:
413
413
  return asm
414
414
 
415
415
 
416
- def member(fields, match_value) -> int:
416
+ def member(fields, match_value):
417
417
  for i, v in enumerate(fields):
418
418
  if v == match_value and type(v) == type(match_value):
419
419
  return i
@@ -421,7 +421,7 @@ def member(fields, match_value) -> int:
421
421
  return -1
422
422
 
423
423
 
424
- def update_code_field(field_name: str, value, inst, opc) -> None:
424
+ def update_code_field(field_name, value, inst, opc):
425
425
  field_values = getattr(opc, field_name)
426
426
  # Can't use "in" because True == 1 and False == 0
427
427
  # if value in l:
@@ -433,7 +433,7 @@ def update_code_field(field_name: str, value, inst, opc) -> None:
433
433
  field_values.append(value)
434
434
 
435
435
 
436
- def update_code_tuple_field(field_name: str, code, lines: List[str], i: int):
436
+ def update_code_tuple_field(field_name, code, lines, i):
437
437
  count = 0
438
438
  while i < len(lines):
439
439
  line = lines[i]
@@ -454,12 +454,12 @@ def update_code_tuple_field(field_name: str, code, lines: List[str], i: int):
454
454
  return i
455
455
 
456
456
 
457
- def err(msg: str, inst, i: int):
457
+ def err(msg, inst, i):
458
458
  msg += ". Instruction %d:\n%s" % (i, inst)
459
459
  raise RuntimeError(msg)
460
460
 
461
461
 
462
- def warn(mess: str) -> None:
462
+ def warn(mess: str):
463
463
  """
464
464
  Print an error message and record that we warned.
465
465
  """
@@ -562,7 +562,7 @@ def is_code_ok(asm: Assembler) -> bool:
562
562
 
563
563
  def append_operand(
564
564
  bytecode: list, arg_value, extended_arg_shift, arg_max_value, extended_arg_op
565
- ) -> None:
565
+ ):
566
566
  """
567
567
  Write instruction operand adding EXTENDED_ARG instructions
568
568
  when necessary.
xasm/pyc_convert.py CHANGED
@@ -13,18 +13,13 @@ from xdis import disassemble_file, load_module, magic2int, write_bytecode_file
13
13
  from xdis.magics import magics
14
14
  from xdis.opcodes import opcode_27, opcode_33
15
15
 
16
- from xasm.assemble import (
17
- Assembler,
18
- Instruction,
19
- asm_file,
20
- create_code,
21
- decode_lineno_tab_old,
22
- )
16
+ from xasm.assemble import (Assembler, Instruction, asm_file, create_code,
17
+ decode_lineno_tab_old)
23
18
  from xasm.version import __version__
24
19
  from xasm.write_pyc import write_pycfile
25
20
 
26
21
 
27
- def add_credit(asm, src_version, dest_version) -> None:
22
+ def add_credit(asm, src_version, dest_version):
28
23
  stamp = "Converted from Python %s to %s by %s version %s" % (
29
24
  src_version,
30
25
  dest_version,
@@ -35,7 +30,7 @@ def add_credit(asm, src_version, dest_version) -> None:
35
30
  return
36
31
 
37
32
 
38
- def copy_magic_into_pyc(input_pyc, output_pyc, src_version, dest_version) -> None:
33
+ def copy_magic_into_pyc(input_pyc, output_pyc, src_version, dest_version):
39
34
  """Bytecodes are the same except the magic number, so just change
40
35
  that"""
41
36
  (version, timestamp, magic_int, co, is_pypy, source_size) = load_module(input_pyc)
@@ -48,7 +43,7 @@ def copy_magic_into_pyc(input_pyc, output_pyc, src_version, dest_version) -> Non
48
43
  return
49
44
 
50
45
 
51
- def xlate26_27(inst) -> None:
46
+ def xlate26_27(inst):
52
47
  """Between 2.6 and 2.7 opcode values changed
53
48
  Adjust for the differences by using the opcode name
54
49
  """
@@ -146,9 +141,7 @@ def transform_33_32(inst, new_inst, i, n, offset, instructions, new_asm):
146
141
  return 0
147
142
 
148
143
 
149
- def transform_asm(
150
- asm: Assembler | None, conversion_type, src_version, dest_version
151
- ) -> Assembler:
144
+ def transform_asm(asm, conversion_type, src_version, dest_version):
152
145
  new_asm = Assembler(dest_version, is_pypy=False)
153
146
  for field in "code size".split():
154
147
  setattr(new_asm, field, copy(getattr(asm, field)))
@@ -166,9 +159,7 @@ def transform_asm(
166
159
  new_asm.backpatch.append(copy(asm.backpatch[j]))
167
160
  new_asm.label.append(copy(asm.label[j]))
168
161
  new_asm.codes.append(copy(code))
169
- new_asm.code.co_lnotab = decode_lineno_tab_old(
170
- code.co_lnotab, code.co_firstlineno
171
- )
162
+ new_asm.code.co_lnotab = decode_lineno_tab_old(code.co_lnotab, code.co_firstlineno)
172
163
  instructions = asm.codes[j].instructions
173
164
  new_asm.code.instructions = []
174
165
  i, offset, n = 0, 0, len(instructions)
@@ -220,7 +211,7 @@ UPWARD_COMPATIBLE = tuple("20-21 21-22 23-24 24-23".split())
220
211
  @click.argument(
221
212
  "output_pyc", type=click.Path(writable=True), required=False, nargs=1, default=None
222
213
  )
223
- def main(conversion_type, input_pyc, output_pyc) -> None:
214
+ def main(conversion_type, input_pyc, output_pyc):
224
215
  """Convert Python bytecode from one version to another.
225
216
 
226
217
  INPUT_PYC contains the input bytecode path name
xasm/version.py CHANGED
@@ -5,4 +5,4 @@
5
5
  # space around "=" below.
6
6
 
7
7
  # fmt: off
8
- __version__="1.2.1" # noqa
8
+ __version__="1.2.1.dev0" # noqa
xasm/xasm_cli.py CHANGED
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env python
2
2
  import os
3
3
  import sys
4
- from typing import List
5
4
 
6
5
  import click
7
6
  import xdis
@@ -14,7 +13,7 @@ from xasm.write_pyc import write_pycfile
14
13
  @click.command()
15
14
  @click.option("--pyc-file", default=None)
16
15
  @click.argument("asm-path", type=click.Path(exists=True, readable=True), required=True)
17
- def main(pyc_file: List[str], asm_path):
16
+ def main(pyc_file, asm_path):
18
17
  """
19
18
  Create Python bytecode from a Python assembly file.
20
19
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xasm
3
- Version: 1.2.1
3
+ Version: 1.2.1.dev0
4
4
  Summary: Python cross-version byte-code assembler
5
5
  Home-page: https://github.com/rocky/python-xasm/
6
6
  Author: Rocky Bernstein
@@ -41,7 +41,7 @@ Dynamic: summary
41
41
  xasm
42
42
  ====
43
43
 
44
- *NOTE: this is in beta.*
44
+ *NOTE: this is in beta*
45
45
 
46
46
  A cross-version Python bytecode assembler
47
47
 
@@ -93,7 +93,7 @@ A GNU makefile is also provided so ``make install`` (possibly as root or
93
93
  sudo) will do the steps above.
94
94
 
95
95
 
96
- *If you are using Python before 3.11*, do not install using PyPI, but instead install using a file in the `GitHub Releases section <https://github.com/rocky/python-xasm/releases>`_. Older Python used to use `easy_install <https://python101.pythonlibrary.org/chapter29_pip.html#using-easy-install>`_. But this is no longer supported in PyPi or newer Python versions. And vice versa, *poetry* nor *pip*, (the newer ways) are not supported on older Pythons.
96
+ *If you are using Python before 3.11*, do not install using PyPI, but instead install using a file in the [GitHub Releases section](https://github.com/rocky/python-xasm/releases). Older Python used to use `easy_install <https://python101.pythonlibrary.org/chapter29_pip.html#using-easy-install>`_. But this is no longer supported in PyPi or newer Python versions. And vice versa, *poetry* nor *pip*, (the newer ways) are not supported on older Pythons.
97
97
 
98
98
  If the Python version you are running xasm is between Python 3.6 through 3.11, use a tarball called xasm_36-*x.y.z*.tar.gz.
99
99
 
@@ -0,0 +1,13 @@
1
+ xasm/__init__.py,sha256=gz94OZ_Jc1WozfOYH1pjQeg7IgB1L9wv5fyytJ2XgZU,174
2
+ xasm/assemble.py,sha256=gczajReJGCeCRGv7jZLWBsICZjzvJviXdMAwsRMOUWI,26257
3
+ xasm/pyc_convert.py,sha256=6XtMK0Q--KW1wQqSXGfKNSxyFAl5a--Q9jvRoALQRyk,9090
4
+ xasm/version.py,sha256=Fnb8SlddvYMcMFqKBfEsy6fBYxfxlGXDxelFtq6CwfM,211
5
+ xasm/write_pyc.py,sha256=ZoqjupN9rEjJ5o49SZcX9rbEhaImnqsJKkNzLnT9j4c,1455
6
+ xasm/xasm_cli.py,sha256=aGSypYaU2zotX-VXcVuZkPP45GzsQrlxGh0PwANBLK0,1754
7
+ xasm-1.2.1.dev0.dist-info/licenses/LICENSE.gpl2,sha256=2ylvL381vKOhdO-w6zkrOxe9lLNBhRQpo9_0EbHC_HM,18046
8
+ xasm-1.2.1.dev0.dist-info/METADATA,sha256=5BP-ch-Ko0W87cTNrIY2JsVZwlvnJ7xfqC9ef3gHOJs,7431
9
+ xasm-1.2.1.dev0.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
10
+ xasm-1.2.1.dev0.dist-info/entry_points.txt,sha256=Ypclbf0sCcywW8uPxxHAQv2pUujiKHx5OfcAYbSks98,84
11
+ xasm-1.2.1.dev0.dist-info/top_level.txt,sha256=24UNOItB5o_EJoJ9nqhPZEC5GiSaYtHll3F6mJXzOkA,5
12
+ xasm-1.2.1.dev0.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
13
+ xasm-1.2.1.dev0.dist-info/RECORD,,
@@ -1,13 +0,0 @@
1
- xasm/__init__.py,sha256=gz94OZ_Jc1WozfOYH1pjQeg7IgB1L9wv5fyytJ2XgZU,174
2
- xasm/assemble.py,sha256=GIf2cfvHa8QFyq0w820-c__Wpj5DeOtKtgicg9XbEjU,26420
3
- xasm/pyc_convert.py,sha256=s2UixbgUQZFHv9nmtvOV7TYohLBev2lcet0GIE9g6GM,9177
4
- xasm/version.py,sha256=xEuuftKJb_Pe2D5lJpTv3HxDgx6Bd1-lH_6HBGWFguw,206
5
- xasm/write_pyc.py,sha256=ZoqjupN9rEjJ5o49SZcX9rbEhaImnqsJKkNzLnT9j4c,1455
6
- xasm/xasm_cli.py,sha256=4EYRZVejspzBvoNaXsWgGbN7qRU5p-MPrt05IYu1kGc,1789
7
- xasm-1.2.1.dist-info/licenses/LICENSE.gpl2,sha256=2ylvL381vKOhdO-w6zkrOxe9lLNBhRQpo9_0EbHC_HM,18046
8
- xasm-1.2.1.dist-info/METADATA,sha256=ttOzLNtFPOn_c015VJhuv-E9sNCXsYGiojLM23FAZ8k,7429
9
- xasm-1.2.1.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
10
- xasm-1.2.1.dist-info/entry_points.txt,sha256=Ypclbf0sCcywW8uPxxHAQv2pUujiKHx5OfcAYbSks98,84
11
- xasm-1.2.1.dist-info/top_level.txt,sha256=24UNOItB5o_EJoJ9nqhPZEC5GiSaYtHll3F6mJXzOkA,5
12
- xasm-1.2.1.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
13
- xasm-1.2.1.dist-info/RECORD,,