pythonnative 0.31.0__py3-none-any.whl → 0.33.0__py3-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.
pythonnative/__init__.py CHANGED
@@ -60,7 +60,7 @@ Example:
60
60
  ```
61
61
  """
62
62
 
63
- __version__ = "0.31.0"
63
+ __version__ = "0.33.0"
64
64
 
65
65
  from . import appearance, diagnostics, gestures, images, runtime, sdk
66
66
  from .alerts import Alert
pythonnative/cli/pn.py CHANGED
@@ -98,6 +98,35 @@ def App():
98
98
  _GITIGNORE = "# PythonNative\n__pycache__/\n*.pyc\n.venv/\nbuild/\n.DS_Store\n"
99
99
 
100
100
 
101
+ _NAME_RE = re.compile(r"^[a-z][a-z0-9_-]*$")
102
+ """Legal ``pn init`` project names, in the spirit of ``flutter create`` / ``cargo new``."""
103
+
104
+ _FALLBACK_NAME = "my_app"
105
+
106
+
107
+ def _sanitize_name(name: str) -> str:
108
+ """Return a legal project name derived from ``name``.
109
+
110
+ Lowercases, collapses each run of illegal characters to one
111
+ underscore, trims leading and trailing ``_`` and ``-``, and prefixes
112
+ a name that doesn't start with a letter. The result always matches
113
+ ``_NAME_RE``, falling back to ``_FALLBACK_NAME`` when nothing usable
114
+ survives.
115
+
116
+ Args:
117
+ name: The rejected name, which may be empty.
118
+
119
+ Returns:
120
+ A name suitable for suggesting back to the user.
121
+ """
122
+ slug = re.sub(r"[^a-z0-9_-]+", "_", name.lower()).strip("_-")
123
+ if not slug:
124
+ return _FALLBACK_NAME
125
+ if not slug[0].isascii() or not slug[0].isalpha():
126
+ slug = f"app_{slug}"
127
+ return slug
128
+
129
+
101
130
  def _app_id_from_name(name: str) -> str:
102
131
  slug = re.sub(r"[^a-z0-9_]", "", name.lower())
103
132
  if not slug or not slug[0].isalpha():
@@ -113,9 +142,17 @@ def init_project(args: argparse.Namespace) -> None:
113
142
  it. Either way it writes ``app/main.py``, ``pythonnative.toml``, and
114
143
  ``.gitignore``.
115
144
 
116
- The name has to be a single directory name, so the project always lands
117
- inside the current directory. Anything that reads as a path, such as
118
- ``a/b``, ``..``, or ``/tmp/app``, is refused, and so is a name that
145
+ A name you pass has to match ``^[a-z][a-z0-9_-]*$``: lowercase letters,
146
+ digits, ``-``, and ``_``, starting with a letter. Anything else is
147
+ refused with a legal suggestion. That keeps the directory name and the
148
+ ``name`` field in the generated config identical, in the same spirit as
149
+ ``flutter create`` and ``cargo new``. The name taken from the current
150
+ directory when you pass none is used as-is, so an existing directory
151
+ with any name still works.
152
+
153
+ The name also has to be a single directory name, so the project always
154
+ lands inside the current directory. Anything that reads as a path, such
155
+ as ``a/b``, ``..``, or ``/tmp/app``, is refused, and so is a name that
119
156
  resolves somewhere else, such as a symlink to another directory.
120
157
 
121
158
  It won't scaffold into a target directory that already holds files, and it
@@ -137,6 +174,19 @@ def init_project(args: argparse.Namespace) -> None:
137
174
  print(f"Refusing to treat a path as a project name: {name!r}. Use a single directory name like my_app.")
138
175
  sys.exit(1)
139
176
 
177
+ # Charset check, still lexical, so it stays ahead of ``Path.cwd()`` below.
178
+ # ``is not None`` rather than truthiness: "" is invalid under the pattern,
179
+ # and falling through to the no-name path would silently scaffold here.
180
+ # ``fullmatch``, not ``match``: ``$`` also matches before a trailing
181
+ # newline, so ``match`` would accept "app\n" and create a directory
182
+ # whose name contains one.
183
+ if name is not None and not _NAME_RE.fullmatch(name):
184
+ print(
185
+ f"Invalid project name: {name!r}. Use lowercase letters, digits, '-', and '_', "
186
+ f"starting with a letter. Try: {_sanitize_name(name)}"
187
+ )
188
+ sys.exit(1)
189
+
140
190
  cwd = Path.cwd()
141
191
  target = cwd / name if name else cwd
142
192
  project_name: str = name or cwd.name
@@ -947,7 +997,11 @@ def _build_parser() -> argparse.ArgumentParser:
947
997
  subparsers = parser.add_subparsers()
948
998
 
949
999
  parser_init = subparsers.add_parser("init", help="Scaffold a new project")
950
- parser_init.add_argument("name", nargs="?", help="Project name; creates ./<name>/ (default: current directory)")
1000
+ parser_init.add_argument(
1001
+ "name",
1002
+ nargs="?",
1003
+ help="Project name, matching ^[a-z][a-z0-9_-]*$; creates ./<name>/ (default: current directory)",
1004
+ )
951
1005
  parser_init.add_argument("--force", action="store_true", help="Overwrite existing files or a non-empty directory")
952
1006
  parser_init.set_defaults(func=init_project)
953
1007
 
pythonnative/net.py CHANGED
@@ -77,6 +77,10 @@ class Response:
77
77
  """``True`` if the status is in the 2xx range."""
78
78
  return 200 <= self.status < 300
79
79
 
80
+ def __repr__(self) -> str:
81
+ cls = type(self).__name__
82
+ return f"{cls}(status={self.status}, url={self.url!r}, ok={self.ok}, content={len(self.content)} bytes)"
83
+
80
84
  def text(self, encoding: Optional[str] = None) -> str:
81
85
  """Decode ``content`` to ``str``.
82
86
 
@@ -226,12 +226,15 @@ def reset_keyboard_height() -> None:
226
226
  # that natural height. Forcing our own height threw off the pill
227
227
  # geometry, so the Android handler defers entirely to the system.
228
228
 
229
- #: UIKit HIG tab-bar content height in points. The total bar reaches
230
- #: ``IOS_TAB_BAR_BASE_HEIGHT_PT + safe_area_insets.bottom`` so the
231
- #: pill background can extend over the home indicator. Apple's HIG
232
- #: places the tab bar flush with the screen edge and lets UIKit
233
- #: render its own internal padding for the home indicator.
234
229
  IOS_TAB_BAR_BASE_HEIGHT_PT: float = 49.0
230
+ """UIKit HIG tab-bar content height in points.
231
+
232
+ The total bar reaches ``IOS_TAB_BAR_BASE_HEIGHT_PT +
233
+ safe_area_insets.bottom`` so the pill background can extend over the
234
+ home indicator. Apple's HIG places the tab bar flush with the screen
235
+ edge and lets UIKit render its own internal padding for the home
236
+ indicator.
237
+ """
235
238
 
236
239
 
237
240
  def ios_tab_bar_height() -> float:
@@ -586,9 +586,52 @@ def entrypoint_to_module(entry_point: str) -> str:
586
586
  return normalized or "app.main"
587
587
 
588
588
 
589
+ # TOML v1.0.0 basic strings must escape the quotation mark, the backslash,
590
+ # and every control character except tab: U+0000-U+0008, U+000A-U+001F, and
591
+ # U+007F. Tab is legal raw, and U+000B has no compact escape, so anything
592
+ # without one falls through to \uXXXX.
593
+ _TOML_COMPACT_ESCAPES = {
594
+ "\\": "\\\\",
595
+ '"': '\\"',
596
+ "\b": "\\b",
597
+ "\f": "\\f",
598
+ "\n": "\\n",
599
+ "\r": "\\r",
600
+ }
601
+
602
+
603
+ def _toml_escape(value: str) -> str:
604
+ """Escape ``value`` for use inside a TOML basic string.
605
+
606
+ Applied at the render boundary rather than relying on the caller,
607
+ since this module is public API and reachable without ``pn init``'s
608
+ name validation in front of it.
609
+
610
+ Args:
611
+ value: The raw string to embed between double quotes.
612
+
613
+ Returns:
614
+ The escaped text, without the surrounding quotes.
615
+ """
616
+ out = []
617
+ for char in value:
618
+ escaped = _TOML_COMPACT_ESCAPES.get(char)
619
+ if escaped is not None:
620
+ out.append(escaped)
621
+ elif char != "\t" and (char < "\x20" or char == "\x7f"):
622
+ out.append(f"\\u{ord(char):04X}")
623
+ else:
624
+ out.append(char)
625
+ return "".join(out)
626
+
627
+
589
628
  def render_default_toml(*, name: str, app_id: str, python_version: str = "3.11") -> str:
590
629
  """Render a starter ``pythonnative.toml`` for ``pn init``.
591
630
 
631
+ Every interpolated value is escaped for a TOML basic string, so a
632
+ name containing a quote, a backslash, or a control character still
633
+ produces a parseable file.
634
+
592
635
  Args:
593
636
  name: Project name.
594
637
  app_id: Reverse-DNS app identifier.
@@ -599,6 +642,10 @@ def render_default_toml(*, name: str, app_id: str, python_version: str = "3.11")
599
642
  for the optional tables.
600
643
  """
601
644
  display = name.replace("_", " ").replace("-", " ").strip().title() or name
645
+ name = _toml_escape(name)
646
+ display = _toml_escape(display)
647
+ app_id = _toml_escape(app_id)
648
+ python_version = _toml_escape(python_version)
602
649
  return f"""# PythonNative project configuration.
603
650
  # Docs: https://pythonnative.com/guides/configuration/
604
651
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pythonnative
3
- Version: 0.31.0
3
+ Version: 0.33.0
4
4
  Summary: Cross-platform native UI toolkit for Android and iOS
5
5
  Author: Owen Carey
6
6
  License: MIT License
@@ -47,26 +47,6 @@ Provides-Extra: ios
47
47
  Requires-Dist: rubicon-objc<0.5.0,>=0.4.6; extra == "ios"
48
48
  Provides-Extra: build
49
49
  Requires-Dist: Pillow>=10.0; extra == "build"
50
- Provides-Extra: docs
51
- Requires-Dist: mkdocs>=1.5; extra == "docs"
52
- Requires-Dist: mkdocs-material[imaging]>=9.5; extra == "docs"
53
- Requires-Dist: mkdocstrings[python]>=0.24; extra == "docs"
54
- Requires-Dist: mkdocs-autorefs>=1.0; extra == "docs"
55
- Requires-Dist: pymdown-extensions>=10.7; extra == "docs"
56
- Provides-Extra: dev
57
- Requires-Dist: black>=24.0; extra == "dev"
58
- Requires-Dist: ruff>=0.5; extra == "dev"
59
- Requires-Dist: mypy>=1.10; extra == "dev"
60
- Requires-Dist: pytest>=8.0; extra == "dev"
61
- Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
62
- Requires-Dist: Pillow>=10.0; extra == "dev"
63
- Provides-Extra: ci
64
- Requires-Dist: black>=24.0; extra == "ci"
65
- Requires-Dist: ruff>=0.5; extra == "ci"
66
- Requires-Dist: mypy>=1.10; extra == "ci"
67
- Requires-Dist: pytest>=8.0; extra == "ci"
68
- Requires-Dist: pytest-asyncio>=0.23; extra == "ci"
69
- Requires-Dist: Pillow>=10.0; extra == "ci"
70
50
  Dynamic: license-file
71
51
 
72
52
  <p align="center">
@@ -1,4 +1,4 @@
1
- pythonnative/__init__.py,sha256=NYhhv97vyRgN8SNgJM-O864UVk1rDOAg8lgja3EKvyc,8680
1
+ pythonnative/__init__.py,sha256=PUlL-bChx_z_MlxnV4gI0NyFoCORX9ppQ93aAWc-8p8,8680
2
2
  pythonnative/_ios_log.py,sha256=Oi7V28VxcVoZyrpAirvLeEmUW18McqnU87V4d37Zzlw,2582
3
3
  pythonnative/alerts.py,sha256=mIANysFlaHwL5EqKnvNcyiJN9rGiZi9XDrD9Jpz1RFM,9340
4
4
  pythonnative/animated.py,sha256=A4IOBf_GD6lUn0H8ArFH6URf0-m0PG__8uaxcw6-ECE,60373
@@ -14,9 +14,9 @@ pythonnative/images.py,sha256=JFjBJdZzZoQmAOfQ7QHqi7dYJ75XTs3u2lweQHGbdPc,6466
14
14
  pythonnative/layout.py,sha256=Ck_FCLSk0g4hdOzHo0c50cbvLe8Q8caQAxywXgnFhKM,49077
15
15
  pythonnative/mutations.py,sha256=whmxO6ENWjm-yYH0QteoCV1Gdw_v-fJrhicMQJ5A0rk,3827
16
16
  pythonnative/navigation.py,sha256=TCDD6MGCEW9qBDZFCJhymUVEtoeNPhQgvio8IbgL0pU,36552
17
- pythonnative/net.py,sha256=8D7EyEC8-JkYxlrtVfTDApOGzzdcA4P4kaCdYBBZI8E,8082
17
+ pythonnative/net.py,sha256=nzYi8GPnxXCSzEtE_q_U4oEjgraB_iQe3nPP_DPlxvQ,8261
18
18
  pythonnative/platform.py,sha256=WtjxR04CqVhSnjJu-3upk8bwXYaSWr2N0MOVoNov-h0,4994
19
- pythonnative/platform_metrics.py,sha256=1r1kMbgS9LcVTbdpP5qRD4oHEvw70te5BXEyd_16Ihc,8961
19
+ pythonnative/platform_metrics.py,sha256=IoWbhp-BW2ourHVOK6JCp2n8_N3weyOEkMoFGObrprM,8954
20
20
  pythonnative/preview.py,sha256=RoZv1s142GWj9xpg9v5Kh-0YuuhpEfwwb_JdnzboRLw,19355
21
21
  pythonnative/reconciler.py,sha256=DAgGS-iEDTnJ7t_GtZ41XbLiToFaHkdBIEqLhwksBXU,97689
22
22
  pythonnative/runtime.py,sha256=m4MllJcApoor822LrceIWNLa2YPbd5lgeijQd3yqp0c,25701
@@ -27,7 +27,7 @@ pythonnative/suspense.py,sha256=IxWGXFP3Odriy0uQe9zhrNrObdKer0_WT6v9Vi8Vatg,1466
27
27
  pythonnative/utils.py,sha256=-hwe_YS19ebpjeygdl3dGeVsYzO4G74rYD53svSi0rI,7593
28
28
  pythonnative/virtual_rows.py,sha256=4YK3CeZobW-6F6GCXzGNFfmOaAiigmH4HXtqjYDRbyU,5056
29
29
  pythonnative/cli/__init__.py,sha256=NM1psvKe8jT0vzp8Ak4MMoygZz4P_msk5g-YEsY8xLk,232
30
- pythonnative/cli/pn.py,sha256=FCNAjbWrOWnm5rEE0n9k2Ys1AY3O11ZuCqV1vaq9-SM,38269
30
+ pythonnative/cli/pn.py,sha256=YGv8Qt5Wf_-5kaLNOhChxXPLN2WrIH2l0hp5POTP6wI,40401
31
31
  pythonnative/native_modules/__init__.py,sha256=pgigpHuzT-rqwcjlwJvu93_4L8Nozal1HJid0S_JlmM,2636
32
32
  pythonnative/native_modules/app_state.py,sha256=CKAwDQIwoGElSLE3l7Bekk0qRbFVFOTSuSCBybumZEk,2742
33
33
  pythonnative/native_modules/battery.py,sha256=-lJu8LURw-yEObXUyhNq_jHFDa1_33lgzbJzXaGqUL4,4429
@@ -51,7 +51,7 @@ pythonnative/native_views/ios.py,sha256=cZNc5F9q01WLWhjNJu-24EZDK5SvtSuuSc3mxJL4
51
51
  pythonnative/project/__init__.py,sha256=kAhWLONs53H1L7xVtczLmzYcQSOOkdRZTAJnIMhpBts,2064
52
52
  pythonnative/project/android.py,sha256=ynRQwVvv1trFB2eFaUv38-48q4m0_Z4cTbAFEOiKnhE,19797
53
53
  pythonnative/project/builder.py,sha256=TTN_ymdSyF4wVtSRRwOnSmc91LMn_g_M7_jTI0NtbVU,23946
54
- pythonnative/project/config.py,sha256=CmN6VojcuDRVnLwKFnQyd9B20_HL9l0RWDnO91G_JaY,25001
54
+ pythonnative/project/config.py,sha256=LkA5iHQNS_ofTMwodE5-69121O-XThaCDDwS9pA-DqQ,26479
55
55
  pythonnative/project/devices.py,sha256=zH0v95vOqWxXGdeTDljrZTA0RWBuU79v3zTQSaXkDh8,10106
56
56
  pythonnative/project/doctor.py,sha256=cNCUWyzu4WBJ9peARIgQ2AyoAGp81NKKM5VkIx7dpFE,8623
57
57
  pythonnative/project/icons.py,sha256=GaXpktQ9v4v2JZPM3ppueNPmwjTuFiLanHJDaZbLGuo,7945
@@ -116,9 +116,9 @@ pythonnative/templates/ios_template/ios_template.xcodeproj/project.xcworkspace/x
116
116
  pythonnative/templates/ios_template/ios_templateTests/ios_templateTests.swift,sha256=YnwzZx7yXB13xKAXEGNgz17VuhWeqkHTRTtBJ2Vu3_E,1238
117
117
  pythonnative/templates/ios_template/ios_templateUITests/ios_templateUITests.swift,sha256=HLRr3cmouRqQeXG13WrZ2XSAmgMgCsNXfZpbwkxeFcs,1385
118
118
  pythonnative/templates/ios_template/ios_templateUITests/ios_templateUITestsLaunchTests.swift,sha256=f5JrG0uVtLMeJQy26Yyz7Om-JUkT220osqcbeIVkj2g,815
119
- pythonnative-0.31.0.dist-info/licenses/LICENSE,sha256=A69iG7TIAe6KkGQf6xoVHkc5JSZtOr5eRSvC5iuivnI,1067
120
- pythonnative-0.31.0.dist-info/METADATA,sha256=XvvvqmJj-vvntCv003W8cuH9I7dSJ5SvSlM8KDHi1r0,11895
121
- pythonnative-0.31.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
122
- pythonnative-0.31.0.dist-info/entry_points.txt,sha256=iUtDawWSAJAEyWTycpZxDuYz73ol31butpzDIEAgPO0,48
123
- pythonnative-0.31.0.dist-info/top_level.txt,sha256=kT4SEATY2ywzrZ2Pgea6_zxyym44Q_PbOsUoOYjJLFE,13
124
- pythonnative-0.31.0.dist-info/RECORD,,
119
+ pythonnative-0.33.0.dist-info/licenses/LICENSE,sha256=A69iG7TIAe6KkGQf6xoVHkc5JSZtOr5eRSvC5iuivnI,1067
120
+ pythonnative-0.33.0.dist-info/METADATA,sha256=HWmbMvt16ZuecGlGtfP4g5QYOwVoLd0ozCEwPxfJqsM,11036
121
+ pythonnative-0.33.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
122
+ pythonnative-0.33.0.dist-info/entry_points.txt,sha256=iUtDawWSAJAEyWTycpZxDuYz73ol31butpzDIEAgPO0,48
123
+ pythonnative-0.33.0.dist-info/top_level.txt,sha256=kT4SEATY2ywzrZ2Pgea6_zxyym44Q_PbOsUoOYjJLFE,13
124
+ pythonnative-0.33.0.dist-info/RECORD,,