cpg2py 1.0.1__tar.gz → 1.0.3__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: cpg2py
3
- Version: 1.0.1
3
+ Version: 1.0.3
4
4
  Summary: A graph-based data structure designed for querying CSV files in Joern format in Python
5
5
  Home-page: https://github.com/YichaoXu/cpg2py
6
6
  Author: Yichao Xu
@@ -1,11 +1,24 @@
1
+ import os
1
2
  from pathlib import Path
2
3
  from csv import DictReader
3
4
  from .cpg import _Graph
4
5
  from .abc import *
5
6
 
7
+ def __remove_null_bytes(file_path: Path) -> Path:
8
+ """Create a new clean file without NULL bytes and return its path."""
9
+ clean_path = file_path.with_suffix(".clean.csv") # Create a temp clean file
10
+ if clean_path.exists(): os.remove(clean_path)
11
+ with open(file_path, "rb") as f:
12
+ content = f.read().replace(b"\x00", b"") # Remove NULL bytes
13
+ with open(clean_path, "wb") as f:
14
+ f.write(content)
15
+ return clean_path
16
+
6
17
  def cpg_graph(node_csv: Path, edge_csv: Path) -> _Graph:
18
+ # Clean files before reading
19
+ tmp_node_csv = __remove_null_bytes(node_csv)
7
20
  storage = Storage()
8
- with open(node_csv, 'r') as n_file:
21
+ with open(tmp_node_csv, 'r') as n_file:
9
22
  reader = DictReader(n_file, delimiter='\t')
10
23
  for node_props in reader:
11
24
  nid = node_props.get("id:int", None)
@@ -14,7 +27,9 @@ def cpg_graph(node_csv: Path, edge_csv: Path) -> _Graph:
14
27
  print(f"Node {nid} already exists in the graph")
15
28
  if not storage.set_node_props(nid, node_props):
16
29
  print(f"Failed to set properties for node {nid}")
17
- with open(edge_csv, 'r') as f:
30
+ if tmp_node_csv.exists(): os.remove(tmp_node_csv)
31
+ tmp_edge_csv = __remove_null_bytes(edge_csv)
32
+ with open(tmp_edge_csv, 'r') as f:
18
33
  reader = DictReader(f, delimiter='\t')
19
34
  for edge_props in reader:
20
35
  f_nid = str(edge_props.get("start", None) )
@@ -28,6 +43,7 @@ def cpg_graph(node_csv: Path, edge_csv: Path) -> _Graph:
28
43
  print(f"Edge {f_nid} -> {t_nid} already exists in the graph")
29
44
  if not storage.set_edge_props(edge_id, edge_props):
30
45
  print(f"Failed to set properties for edge {edge_id}")
46
+ if tmp_edge_csv.exists(): os.remove(tmp_edge_csv)
31
47
  return _Graph(storage)
32
48
 
33
49
 
@@ -1,12 +1,12 @@
1
- from typing import Optional, Iterable, Dict
1
+ from typing import Optional, Iterable, Dict, Tuple
2
2
 
3
3
 
4
4
  class Storage:
5
5
  """ A directed multi-graph implementation supporting multiple edges between nodes. """
6
6
 
7
7
  __NodeID = str
8
- __EdgeID = tuple[str, str, str]
9
- __Property = dict[str, any]
8
+ __EdgeID = Tuple[str, str, str]
9
+ __Property = Dict[str, any]
10
10
 
11
11
  def __init__(self):
12
12
  """ Initializes an empty directed graph. """
@@ -1,6 +1,5 @@
1
1
  from __future__ import annotations
2
2
  from typing import Optional, Tuple
3
- from enum import Enum
4
3
  from ..abc import AbcGraphQuerier, AbcEdgeQuerier
5
4
 
6
5
  class _Edge(AbcEdgeQuerier):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: cpg2py
3
- Version: 1.0.1
3
+ Version: 1.0.3
4
4
  Summary: A graph-based data structure designed for querying CSV files in Joern format in Python
5
5
  Home-page: https://github.com/YichaoXu/cpg2py
6
6
  Author: Yichao Xu
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "cpg2py"
7
- version = "1.0.1"
7
+ version = "1.0.3"
8
8
  description = "A graph-based data structure designed for querying CSV files in Joern format in Python"
9
9
  readme = "README.md"
10
10
  authors = [
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="cpg2py",
5
- version="1.0.1",
5
+ version="1.0.3",
6
6
  author="Yichao Xu",
7
7
  author_email="yxu166@jhu.edu",
8
8
  description="A graph-based data structure designed for querying CSV files in Joern format in Python",
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes