DEF
```
--------------------------------
### Build documentation locally
Source: https://github.com/brightway-lca/brightway2-data/blob/main/README.md
Commands to set up the documentation environment and build the HTML output.
```bash
conda env create -f docs/environment.yml
```
```bash
conda activate sphinx_bw2data
```
```bash
sphinx-build docs _build/html --builder=html --jobs=auto --write-all; open _build/html/index.html
```
--------------------------------
### Build documentation locally
Source: https://github.com/brightway-lca/brightway2-data/blob/main/docs/content/contributing.md
Uses sphinx-build to generate documentation from the docs directory.
```console
# use docs as source and docs/_build as output
sphinx-build docs docs/_build
```
--------------------------------
### Retrieve activity by integer ID
Source: https://github.com/brightway-lca/brightway2-data/blob/main/CHANGES.md
Demonstrates retrieving an activity using its integer ID via get_activity or Database.get.
```python
>>> bw2data.get_activity(19014)
'treatment of aluminium in car shredder residue, municipal incineration' (kilogram, RoW, None)
>>> bw2data.Database("something").get(19014)
'treatment of aluminium in car shredder residue, municipal incineration' (kilogram, RoW, None)
```
--------------------------------
### Import necessary libraries
Source: https://github.com/brightway-lca/brightway2-data/blob/main/dev/Speed tests DataFrame creation.ipynb
Imports the wurst, bw2data, and pandas libraries required for data extraction and manipulation.
```python
import wurst
import bw2data as bd
import pandas as pd
```
--------------------------------
### Retrieve activity ID from key
Source: https://github.com/brightway-lca/brightway2-data/blob/main/CHANGES.md
Demonstrates how to resolve an activity or its key to an integer ID.
```python
>>> bw2data.get_id(a)
19014
>>> bw2data.get_id(a.key)
19014
```
--------------------------------
### Run test suite
Source: https://github.com/brightway-lca/brightway2-data/blob/main/docs/content/contributing.md
Executes the project's unit tests using the pytest framework.
```console
$ pytest
```
--------------------------------
### Create and compare DataFrame memory usage
Source: https://github.com/brightway-lca/brightway2-data/blob/main/dev/Speed tests DataFrame creation.ipynb
Creates two DataFrames using `as_naive_df`: one with categorical data and one without. It then compares their memory usage in megabytes to quantify the benefits of using categorical types.
```python
df_compressed = as_naive_df(data)
df_full = as_naive_df(data, False)
```
```python
df_compressed.memory_usage().sum() / 1024 ** 2, df_full.memory_usage().sum() / 1024 ** 2
```
--------------------------------
### Define Ecoinvent Cache Path
Source: https://github.com/brightway-lca/brightway2-data/blob/main/dev/Export-biosphere.ipynb
Sets the path to the Ecoinvent cache directory. Asserts that the directory exists before proceeding.
```python
from pathlib import Path
dp = Path("/Users/chrismutel/Library/Application Support/EcoinventInterface/cache/ecoinvent 3.6_consequential_ecoSpold02/MasterData")
assert dp.is_dir()
```
--------------------------------
### Set current Brightway2 project
Source: https://github.com/brightway-lca/brightway2-data/blob/main/dev/Speed tests DataFrame creation.ipynb
Sets the active project in Brightway2 to 'ei 3.8 cutoff'. This is a prerequisite for accessing specific database versions.
```python
bd.projects.set_current("ei 3.8 cutoff")
```
--------------------------------
### Script Tag with URL Parameters
Source: https://github.com/brightway-lca/brightway2-data/blob/main/tests/fixtures/naughty_strings.txt
Tests XSS by including URL parameters within a script source URL, which might be processed in unexpected ways.
```html
```
```html
```
--------------------------------
### Display DataFrame data types
Source: https://github.com/brightway-lca/brightway2-data/blob/main/dev/Speed tests DataFrame creation.ipynb
Prints the data types of the columns in the `df_compressed` DataFrame, which was created with categorical columns. This allows verification of the applied data type conversions.
```python
df_compressed.dtypes
```
--------------------------------
### Script Tag with Obfuscated Source Path
Source: https://github.com/brightway-lca/brightway2-data/blob/main/tests/fixtures/naughty_strings.txt
Tests XSS by using format string specifiers in script source paths, which might be interpreted by certain server-side or client-side parsers.
```html
```
```html
```
--------------------------------
### JavaScript String Termination and Comment
Source: https://github.com/brightway-lca/brightway2-data/blob/main/tests/fixtures/naughty_strings.txt
Tests XSS by using a string termination character followed by an alert and a comment, aiming to break out of existing script contexts.
```javascript
";alert('XSS');//
```
--------------------------------
### HTML Image Tag with Script Injection
Source: https://github.com/brightway-lca/brightway2-data/blob/main/tests/fixtures/naughty_strings.txt
Tests XSS by injecting a script tag directly after an image tag, using double quotes and angle brackets for obfuscation.
```html
![]()
">
```
--------------------------------
### HTML Anchor and Image Tags with Backtick Injection
Source: https://github.com/brightway-lca/brightway2-data/blob/main/tests/fixtures/naughty_strings.txt
Tests XSS by using backticks within an anchor tag's href and an image tag's alt attribute to inject script.
```html

>
```
--------------------------------
### HTML Script Tag with Nested Tags
Source: https://github.com/brightway-lca/brightway2-data/blob/main/tests/fixtures/naughty_strings.txt
Tests XSS by using nested script tags and comments to confuse parsers.
```html
<
```
--------------------------------
### XXE Injection (XML)
Source: https://github.com/brightway-lca/brightway2-data/blob/main/tests/fixtures/naughty_strings.txt
This XML string can be used to exploit XXE vulnerabilities in improperly configured XML parsers, potentially revealing system files like '/etc/passwd'.
```xml
]>
&xxe;
```
--------------------------------
### HTML Span Tag with Copy Event
Source: https://github.com/brightway-lca/brightway2-data/blob/main/tests/fixtures/naughty_strings.txt
Tests XSS by triggering a JavaScript alert via the 'oncopy' event on a span tag.
```html
Copy me
```
--------------------------------
### HTML Image Tag with Malformed Attributes
Source: https://github.com/brightway-lca/brightway2-data/blob/main/tests/fixtures/naughty_strings.txt
Tests XSS by using malformed attribute syntax and comments within an image tag to inject script.
```html
![javascript:alert(1)//"]()
```
--------------------------------
### HTML Iframe Tag with Incomplete Tag
Source: https://github.com/brightway-lca/brightway2-data/blob/main/tests/fixtures/naughty_strings.txt
Tests XSS by using an incomplete iframe tag, which might lead to parsing errors that expose vulnerabilities.
```html