modules

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2025 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package modules provides the io module for M28

Package modules provides Go-implemented standard library modules for M28.

Package modules provides the sys module for M28

Package modules provides the warnings module for M28 Implements Python's warning system for deprecations and other warnings

Index

Constants

View Source
const (
	TYPE_NULL        = '0'
	TYPE_NONE        = 'N'
	TYPE_FALSE       = 'F'
	TYPE_TRUE        = 'T'
	TYPE_INT         = 'i'
	TYPE_FLOAT       = 'f'
	TYPE_STRING      = 's'
	TYPE_TUPLE       = '('
	TYPE_LIST        = '['
	TYPE_DICT        = '{'
	TYPE_CODE        = 'c'
	TYPE_UNICODE     = 'u'
	TYPE_BYTES       = 's' // Same as string in marshal
	TYPE_SHORT_ASCII = 'z'
	TYPE_SMALL_TUPLE = ')'
)

Marshal format type codes (matching CPython's marshal.c)

Variables

This section is empty.

Functions

func GetBuiltinModule

func GetBuiltinModule(name string) (*core.DictValue, bool)

GetBuiltinModule returns a builtin module by name if it exists

func InitAbcModule added in v0.3.0

func InitAbcModule() *core.DictValue

InitAbcModule creates the _abc module This provides C-level support for abstract base classes

func InitCodecsModule added in v0.3.0

func InitCodecsModule() *core.DictValue

InitCodecsModule initializes the _codecs C extension stub module This provides minimal codec support for Python stdlib modules

func InitCollectionsModule added in v0.3.0

func InitCollectionsModule() *core.DictValue

InitCollectionsModule creates and returns the collections module

func InitEnumModule added in v0.3.0

func InitEnumModule() *core.DictValue

InitEnumModule initializes a stub enum module This provides minimal enum support for Python stdlib modules like re

func InitErrnoModule added in v0.3.0

func InitErrnoModule() *core.DictValue

InitErrnoModule creates the errno module with error codes

func InitIOModule added in v0.3.0

func InitIOModule() *core.DictValue

InitIOModule registers the io module

func InitItertoolsModule added in v0.3.0

func InitItertoolsModule() *core.DictValue

InitItertoolsModule creates and returns the itertools module

func InitMarshalModule added in v0.3.0

func InitMarshalModule() *core.DictValue

InitMarshalModule creates and returns the marshal module Implements Python's marshal module for bytecode serialization

func InitMathModule

func InitMathModule() *core.DictValue

InitMathModule creates and returns the math module with comprehensive CPython compatibility This C extension module provides mathematical functions as defined in CPython's mathmodule.c

func InitOSModule

func InitOSModule() *core.DictValue

InitOSModule creates and initializes the os module

func InitOpcodeModule added in v0.3.0

func InitOpcodeModule() *core.DictValue

InitOpcodeModule creates the _opcode module with bytecode opcodes

func InitOperatorModule added in v0.3.0

func InitOperatorModule() *core.DictValue

InitOperatorModule creates the _operator module Note: Most operator functionality is in the pure Python operator.py module This C extension just provides a few optimized functions

func InitPosixModule added in v0.3.0

func InitPosixModule() *core.DictValue

InitPosixModule creates the posix C extension module stub This is used by Python's os.py to get platform-specific functions

func InitStatModule added in v0.3.0

func InitStatModule() *core.DictValue

InitStatModule creates the _stat module with file mode constants

func InitStructModule added in v0.3.0

func InitStructModule() *core.DictValue

InitStructModule creates and returns the _struct module This implements Python's _struct C extension for binary data packing/unpacking

func InitSysModule added in v0.3.0

func InitSysModule() *core.DictValue

InitSysModule registers the sys module

func InitThreadModule added in v0.3.0

func InitThreadModule() *core.DictValue

InitThreadModule initializes the _thread C extension module This provides threading support for Python stdlib modules

func InitTimeModule

func InitTimeModule() *core.DictValue

RegisterTimeModule registers the time module

func InitUnicodedataModule added in v0.3.0

func InitUnicodedataModule() *core.DictValue

InitUnicodedataModule creates a minimal stub for the unicodedata C extension module This is needed by test.support.os_helper for filename normalization on macOS We provide minimal stubs to allow test imports to work

func InitWarningsModule added in v0.3.0

func InitWarningsModule() *core.DictValue

InitWarningsModule registers the warnings module

func InitWeakrefModule added in v0.3.0

func InitWeakrefModule() *core.DictValue

InitWeakrefModule initializes the _weakref C extension stub module This provides minimal weak reference support for Python stdlib modules

func Init_ASTModule added in v0.3.0

func Init_ASTModule() *core.DictValue

Init_ASTModule creates and returns the _ast module stub This is a minimal stub implementation of Python's _ast C extension module It provides empty classes for AST node types to allow ast.py to import

func Init_CompatPickleModule added in v0.3.0

func Init_CompatPickleModule() *core.DictValue

Init_CompatPickleModule creates a stub for _compat_pickle that bypasses assertions This module is used by pickle to map Python 2 names to Python 3 names

func Init_FunctoolsModule added in v0.3.0

func Init_FunctoolsModule() *core.DictValue

Init_FunctoolsModule creates and returns the _functools C extension stub This provides the C functions that Python's functools.py imports

func Init_ImpModule added in v0.3.0

func Init_ImpModule() *core.DictValue

Init_ImpModule creates and returns the _imp module stub This is a minimal stub implementation of Python's _imp C extension module It provides the internal import machinery

func Init_REParserModule added in v0.3.0

func Init_REParserModule() *core.DictValue

Init_REParserModule initializes the re._parser stub module This provides minimal regex parser support for the re module

func Init_SREModule added in v0.3.0

func Init_SREModule() *core.DictValue

Init_SREModule initializes the _sre C extension stub module This provides minimal regex engine support for Python stdlib modules

func Init_SignalModule added in v0.3.0

func Init_SignalModule() *core.DictValue

Init_SignalModule creates and returns the _signal C extension stub This provides signal constants and basic signal handling functions

func Init_StringModule added in v0.3.0

func Init_StringModule() *core.DictValue

Init_StringModule creates the _string C extension module stub This provides C-accelerated string functions for Python's string.py

func Init_TokenizeModule added in v0.3.0

func Init_TokenizeModule() *core.DictValue

Init_TokenizeModule creates and returns the _tokenize module

func Init_WarningsModule added in v0.3.0

func Init_WarningsModule() *core.DictValue

Init_WarningsModule creates and returns the _warnings module stub This is a minimal stub implementation of Python's _warnings C extension module

func IsBuiltinModule

func IsBuiltinModule(name string) bool

IsBuiltinModule checks if a name corresponds to a builtin module

func ListBuiltinModules

func ListBuiltinModules() []string

ListBuiltinModules returns a list of all available builtin module names

func LoadPythonModule added in v0.3.0

func LoadPythonModule(name string, ctx *core.Context, evalFunc func(core.Value, *core.Context) (core.Value, error), partialModule *core.DictValue) (*core.DictValue, error)

LoadPythonModule attempts to load a Python module by name Returns (*DictValue, error) to match ModuleLoader interface If partialModule is provided, it will be populated during evaluation for circular import support

func Warn added in v0.3.0

func Warn(message string, category string, ctx *core.Context) error

Warn is a helper function to emit warnings from Go code

Types

type BytesIO added in v0.3.0

type BytesIO struct {
	// contains filtered or unexported fields
}

BytesIO is an in-memory bytes stream

type CatchWarnings added in v0.3.0

type CatchWarnings struct {
	// contains filtered or unexported fields
}

CatchWarnings implements the catch_warnings context manager

type Counter added in v0.3.0

type Counter struct {
	// contains filtered or unexported fields
}

Counter is a dict subclass for counting hashable objects

func NewCounter added in v0.3.0

func NewCounter() *Counter

NewCounter creates a new Counter

func (*Counter) Elements added in v0.3.0

func (c *Counter) Elements() core.Value

Elements returns an iterator over elements repeating each as many times as its count

func (*Counter) GetAttr added in v0.3.0

func (c *Counter) GetAttr(name string) (core.Value, bool)

GetAttr implements attribute access

func (*Counter) MostCommon added in v0.3.0

func (c *Counter) MostCommon(n int) core.Value

MostCommon returns a list of the n most common elements and their counts

func (*Counter) SetAttr added in v0.3.0

func (c *Counter) SetAttr(name string, value core.Value) error

SetAttr implements attribute setting

func (*Counter) String added in v0.3.0

func (c *Counter) String() string

String implements Value.String

func (*Counter) Total added in v0.3.0

func (c *Counter) Total() core.Value

Total returns the sum of all counts

func (*Counter) Type added in v0.3.0

func (c *Counter) Type() core.Type

Type implements Value.Type

func (*Counter) Update added in v0.3.0

func (c *Counter) Update(args []core.Value)

Update adds counts from an iterable or mapping

type DefaultDict added in v0.3.0

type DefaultDict struct {
	// contains filtered or unexported fields
}

DefaultDict is a dict subclass that calls a factory function for missing keys

func NewDefaultDict added in v0.3.0

func NewDefaultDict(factory core.Value) *DefaultDict

NewDefaultDict creates a new defaultdict

func (*DefaultDict) Get added in v0.3.0

func (dd *DefaultDict) Get(key core.Value, ctx *core.Context) (core.Value, error)

Get returns the value for a key, calling the factory if missing

func (*DefaultDict) GetAttr added in v0.3.0

func (dd *DefaultDict) GetAttr(name string) (core.Value, bool)

GetAttr implements attribute access

func (*DefaultDict) SetAttr added in v0.3.0

func (dd *DefaultDict) SetAttr(name string, value core.Value) error

SetAttr implements attribute setting

func (*DefaultDict) String added in v0.3.0

func (dd *DefaultDict) String() string

String implements Value.String

func (*DefaultDict) Type added in v0.3.0

func (dd *DefaultDict) Type() core.Type

Type implements Value.Type

type Deque added in v0.3.0

type Deque struct {
	// contains filtered or unexported fields
}

Deque is a double-ended queue

func NewDeque added in v0.3.0

func NewDeque() *Deque

NewDeque creates a new deque

func (*Deque) Append added in v0.3.0

func (dq *Deque) Append(item core.Value)

Append adds an element to the right side

func (*Deque) AppendLeft added in v0.3.0

func (dq *Deque) AppendLeft(item core.Value)

AppendLeft adds an element to the left side

func (*Deque) GetAttr added in v0.3.0

func (dq *Deque) GetAttr(name string) (core.Value, bool)

GetAttr implements attribute access

func (*Deque) Pop added in v0.3.0

func (dq *Deque) Pop() (core.Value, error)

Pop removes and returns an element from the right side

func (*Deque) PopLeft added in v0.3.0

func (dq *Deque) PopLeft() (core.Value, error)

PopLeft removes and returns an element from the left side

func (*Deque) Rotate added in v0.3.0

func (dq *Deque) Rotate(n int)

Rotate rotates the deque n steps to the right (negative for left)

func (*Deque) SetAttr added in v0.3.0

func (dq *Deque) SetAttr(name string, value core.Value) error

SetAttr implements attribute setting

func (*Deque) String added in v0.3.0

func (dq *Deque) String() string

String implements Value.String

func (*Deque) Type added in v0.3.0

func (dq *Deque) Type() core.Type

Type implements Value.Type

type DequeIterator added in v0.3.0

type DequeIterator struct {
	// contains filtered or unexported fields
}

DequeIterator is an iterator over deque elements

func NewDequeIterator added in v0.3.0

func NewDequeIterator(dq *Deque) *DequeIterator

NewDequeIterator creates a new deque iterator

func (*DequeIterator) Iterator added in v0.3.0

func (di *DequeIterator) Iterator() core.Iterator

Iterator implements Iterable.Iterator

func (*DequeIterator) Next added in v0.3.0

func (di *DequeIterator) Next() (core.Value, bool)

Next implements Iterator.Next

func (*DequeIterator) Reset added in v0.3.0

func (di *DequeIterator) Reset()

Reset implements Iterator.Reset

func (*DequeIterator) String added in v0.3.0

func (di *DequeIterator) String() string

String implements Value.String

func (*DequeIterator) Type added in v0.3.0

func (di *DequeIterator) Type() core.Type

Type implements Value.Type

type KwargsOSStat added in v0.3.0

type KwargsOSStat struct {
	core.BaseObject
}

KwargsOSStat implements os.stat with follow_symlinks keyword argument support

func (*KwargsOSStat) Call added in v0.3.0

func (f *KwargsOSStat) Call(args []core.Value, ctx *core.Context) (core.Value, error)

Call implements regular Call interface

func (*KwargsOSStat) CallWithKeywords added in v0.3.0

func (f *KwargsOSStat) CallWithKeywords(args []core.Value, kwargs map[string]core.Value, ctx *core.Context) (core.Value, error)

CallWithKeywords implements keyword argument support

func (*KwargsOSStat) String added in v0.3.0

func (f *KwargsOSStat) String() string

func (*KwargsOSStat) Type added in v0.3.0

func (f *KwargsOSStat) Type() core.Type

type KwargsPosixStat added in v0.3.0

type KwargsPosixStat struct {
	core.BaseObject
	// contains filtered or unexported fields
}

KwargsPosixStat implements posix.stat with follow_symlinks keyword argument support

func (*KwargsPosixStat) Call added in v0.3.0

func (f *KwargsPosixStat) Call(args []core.Value, ctx *core.Context) (core.Value, error)

Call implements regular Call interface

func (*KwargsPosixStat) CallWithKeywords added in v0.3.0

func (f *KwargsPosixStat) CallWithKeywords(args []core.Value, kwargs map[string]core.Value, ctx *core.Context) (core.Value, error)

CallWithKeywords implements keyword argument support

func (*KwargsPosixStat) String added in v0.3.0

func (f *KwargsPosixStat) String() string

func (*KwargsPosixStat) Type added in v0.3.0

func (f *KwargsPosixStat) Type() core.Type

type ModuleInitializer

type ModuleInitializer func() *core.DictValue

ModuleInitializer is a function that creates and returns a module dictionary

type OrderedDict added in v0.3.0

type OrderedDict struct {
	// contains filtered or unexported fields
}

OrderedDict is a dictionary that maintains insertion order Since M28's DictValue already maintains order, this is essentially a wrapper

func NewOrderedDict added in v0.3.0

func NewOrderedDict() *OrderedDict

NewOrderedDict creates a new OrderedDict

func (*OrderedDict) GetAttr added in v0.3.0

func (od *OrderedDict) GetAttr(name string) (core.Value, bool)

GetAttr implements attribute access

func (*OrderedDict) SetAttr added in v0.3.0

func (od *OrderedDict) SetAttr(name string, value core.Value) error

SetAttr implements attribute setting

func (*OrderedDict) String added in v0.3.0

func (od *OrderedDict) String() string

String implements Value.String

func (*OrderedDict) Type added in v0.3.0

func (od *OrderedDict) Type() core.Type

Type implements Value.Type

type PythonModuleFinder added in v0.3.0

type PythonModuleFinder struct {
	// contains filtered or unexported fields
}

PythonModuleFinder locates Python modules in the standard library

func GetPythonFinder added in v0.3.0

func GetPythonFinder() (*PythonModuleFinder, error)

GetPythonFinder returns the global PythonModuleFinder instance

func NewPythonModuleFinder added in v0.3.0

func NewPythonModuleFinder() (*PythonModuleFinder, error)

NewPythonModuleFinder creates a new Python module finder

func (*PythonModuleFinder) Find added in v0.3.0

func (f *PythonModuleFinder) Find(moduleName string) (string, bool, error)

Find locates a Python module by name Returns (path, isPackage, error) - path: full path to .py file or __init__.py - isPackage: true if module is a package (has __init__.py)

func (*PythonModuleFinder) FindWithExtraPaths added in v0.3.0

func (f *PythonModuleFinder) FindWithExtraPaths(moduleName string, extraPaths []string) (string, bool, error)

FindWithExtraPaths locates a Python module, checking extraPaths first, then default paths

func (*PythonModuleFinder) GetSearchPaths added in v0.3.0

func (f *PythonModuleFinder) GetSearchPaths() []string

GetSearchPaths returns the list of Python search paths

type PythonModuleTranspiler added in v0.3.0

type PythonModuleTranspiler struct {
	// contains filtered or unexported fields
}

PythonModuleTranspiler transpiles Python source to M28 AST

func GetPythonTranspiler added in v0.3.0

func GetPythonTranspiler() *PythonModuleTranspiler

GetPythonTranspiler returns the global transpiler instance

func (*PythonModuleTranspiler) ClearCache added in v0.3.0

func (t *PythonModuleTranspiler) ClearCache()

ClearCache clears the transpiler cache

func (*PythonModuleTranspiler) RemoveFromCache added in v0.3.0

func (t *PythonModuleTranspiler) RemoveFromCache(pyPath string)

RemoveFromCache removes a specific file from the cache

func (*PythonModuleTranspiler) Transpile added in v0.3.0

func (t *PythonModuleTranspiler) Transpile(pyPath string) (ast.ASTNode, error)

Transpile parses a Python file and returns its AST as a block

type StringIO added in v0.3.0

type StringIO struct {
	// contains filtered or unexported fields
}

StringIO is an in-memory text stream

type TextIOWrapper added in v0.3.0

type TextIOWrapper struct {
	// contains filtered or unexported fields
}

TextIOWrapper wraps a binary stream and provides text I/O

type ThreadLock added in v0.3.0

type ThreadLock struct {
	// contains filtered or unexported fields
}

ThreadLock represents a lock object

func (*ThreadLock) Equals added in v0.3.0

func (l *ThreadLock) Equals(other core.Value) bool

func (*ThreadLock) GetAttr added in v0.3.0

func (l *ThreadLock) GetAttr(name string) (core.Value, bool)

Implement methods for the lock

func (*ThreadLock) Repr added in v0.3.0

func (l *ThreadLock) Repr() string

func (*ThreadLock) SetAttr added in v0.3.0

func (l *ThreadLock) SetAttr(name string, value core.Value) error

func (*ThreadLock) String added in v0.3.0

func (l *ThreadLock) String() string

func (*ThreadLock) Type added in v0.3.0

func (l *ThreadLock) Type() core.Type

type TokenizerIter added in v0.3.0

type TokenizerIter struct {
	// contains filtered or unexported fields
}

TokenizerIter implements the _tokenize.TokenizerIter class This is a stub implementation that provides basic tokenization for Python code

func (*TokenizerIter) GetAttr added in v0.3.0

func (t *TokenizerIter) GetAttr(name string) (core.Value, bool)

func (*TokenizerIter) String added in v0.3.0

func (t *TokenizerIter) String() string

func (*TokenizerIter) Type added in v0.3.0

func (t *TokenizerIter) Type() core.Type

type TupleGetter added in v0.3.0

type TupleGetter struct {
	// contains filtered or unexported fields
}

TupleGetter is a callable that retrieves a specific index from a tuple This is used by namedtuple for field access

func NewTupleGetter added in v0.3.0

func NewTupleGetter(index int, doc string) *TupleGetter

NewTupleGetter creates a new TupleGetter

func (*TupleGetter) Call added in v0.3.0

func (tg *TupleGetter) Call(args []core.Value, ctx *core.Context) (core.Value, error)

Call implements Callable.Call

func (*TupleGetter) GetAttr added in v0.3.0

func (tg *TupleGetter) GetAttr(name string) (core.Value, bool)

GetAttr implements attribute access

func (*TupleGetter) SetAttr added in v0.3.0

func (tg *TupleGetter) SetAttr(name string, value core.Value) error

SetAttr implements attribute setting

func (*TupleGetter) String added in v0.3.0

func (tg *TupleGetter) String() string

String implements Value.String

func (*TupleGetter) Type added in v0.3.0

func (tg *TupleGetter) Type() core.Type

Type implements Value.Type

type WarningFilter added in v0.3.0

type WarningFilter struct {
	Action   string // "default", "error", "ignore", "always", "module", "once"
	Category core.Value
	Module   string
	Lineno   int
}

WarningFilter represents a single warning filter

type WarningRegistry added in v0.3.0

type WarningRegistry struct {
	// contains filtered or unexported fields
}

WarningRegistry manages warning filters and state

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL