semvec/pypi-packages huggingface dataset:
pycbpf 0.0.2
convert cbpf code to C for BCC
Requires Python: >=3.7

### About pycbpf
---

Inspired by [cbpfc](https://github.com/cloudflare/cbpfc).

pycbpf2c converts tcpdump filter expression to C code which can be injected to a BCC script.

This aims to provide native python support, so BCC can import it directly.

And it provides a BCC script for dump filtered packet to pcap format.

### Simple usecase

You can save packets to a pcap file like below to sniffer packet from ```dev_queue_xmit```
```
python3 -m pycbpf.c2ebpf -i eth0 -w file.pcap <tcpdump expresion>
```

Or with no pcap file specified, you need to pipe output to tcpdump
```
python3 -m pycbpf.c2ebpf -i eth0 <tcpdump expresion> | tcpdump -r - -nev
```

### Examples of usage

Of course you can generate a C program from tcpdump expresion and implement your own BCC script.
Cmdline below will generate the C program, which can be used directly in BCC.
```
python3 -m pycbpf.cbpf2c <tcpdump expression>
```

Steps to use it in python:

1 - Install and import packages

```
pip3 install pycbpf
```

```
from bcc import BPF
from pycbpf import cbpf2c, filter2cbpf
```
2 - Generate cbpf and compile to C program, and enable BPF for trace. Write you test_text with space reserved for the generated code. Use the inline function ```cbpf_filter_func``` in you trace program and handle return value properly.
```
test_text = """

/* reserve space for the generated code cbpf_filter_func */
%s

your_func()
{
      u32 datalen = 0;
      u32 ret = 0;
      u8 *data;
      ...

      ret = cbpf_filter_func(data, data + datalen);
      if (!ret) {
            return 0;
      }

      filter_event.perf_submit(ctx, &e, sizeof(e));
}

"""

prog = filter2cbpf.CbpfProg(["ip"])
prog_c = cbpf2c.CbpfC(prog)
cfun = prog_c.compile_cbpf_to_c()
test_text = bpf_text%cfun
bpf_ctx = BPF(text=test_text, debug=0)
```
3 - write bcc perf event callback
```
def filter_events_cb(_cpu, data, _size):
      # print some data
      # or write to pcap files

bctx['filter_event'].open_perf_buffer(filter_events_cb)
```
---
### Further explain


As for the code generated from cbpf, for example, filter ```ip``` packets, will generate C program:
```
static inline u32
cbpf_filter_func (const u8 *const data, const u8 *const data_end) {
      __attribute__((unused)) u32 A, X, M[16];
      __attribute__((unused)) const u8 *indirect;

      if (data + 12 > data_end) { return 0; }
      A = bpf_ntohs(*((u16 *)(data + 12)));
      if (A != 0x800) {goto label3;}
      return 262144;
label3:
      return 0;
}
```

It follows what cbpf code tells us to do:
```
(000) ldh      [12]
(001) jeq      #0x800           jt 2	jf 3
(002) ret      #262144
(003) ret      #0
```
A little explain about the cbpf code and cbpf_filter_func above:

First read 2 byte at offset 12.

Test the data read, if equal to 0x0800, jump to 002, else jump to 003. We name the position to labelX, X is the PC value.

If label is right after last instruction, it will be ignored.
002 and 003 will return value and exit the function.


see ```c2ebpf.py``` as an example to save packets to pcap files



---
### LICENSE
pycbpf is MIT licensed, as found in the LICENSE file
pypi-mr 0.0.4
Check if package exists on pypi registry using simple API. Clean packages that belongs to closed/merged GitLab MRs
Requires Python: >=3.9

# pypi-mr
This package allows:
1. check if package exists on pypi registry using [simple API](https://warehouse.pypa.io/api-reference/legacy.html#simple-project-api).
2. clean packages that belongs to closed/merged GitLab MRs
batch-ingestion-client-py 1.0.4
A client for the BatchIngestion mediawiki API
Keywords: python,mediawiki,batchingestion,wikidata,wikibase,api,client


# BatchIngestion Python Client

This is a Python client library for the [BatchIngestion](https://gitlab.the-qa-company.com/FrozenMink/batchingestionextension) MediaWiki extension, which provides an API to ingest many entities at once. This library allows you to easily ingest entities in bulk, either by parsing them from JSON or by creating them using Python objects.

## Installation

You can install this library using [pip](https://pypi.org/project/batch-ingestion-client-py/):

```bash
pip install batch-ingestion-client-py==1.0.4
```

## Usage

```python
from batch_ingestion_client_py import (
    BatchIngestor,
    Entity,
    ValueInLanguage,
)

ingestor = BatchIngestor(
    base_url="https://your-wiki.com",
    username="your-username",
    password="your-password",
)

example1 = ingestor.ingest([
    Entity.parse({
        "type": "item",
        "labels": {
            "en": {
                "language": "en",
                "value": "Hello, world!",
            },
        },
    })
])

print(example1)

example2 = ingestor.ingest([
    Entity(
        type="item",
        labels={
            "en": ValueInLanguage(
                language="en",
                value="Hello, world!",
            ),
        },
    ),
])

print(example2)
```

## Contributing

If you'd like to contribute to this library, please feel free to submit a pull request.