or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

execution.mdindex.mditerator-dict.mdmetaclass.mdmoves.mdstring-bytes.mdtesting.mdversion-detection.md

moves.mddocs/

0

# Moves Module

1

2

The `six.moves` module provides unified access to standard library modules and functions that were moved or renamed between Python 2 and 3. It supports 70+ relocated imports through a lazy loading system that dynamically maps old Python 2 locations to new Python 3 locations.

3

4

## Capabilities

5

6

### Main Moves Module

7

8

The central module object that provides access to all relocated imports.

9

10

```python { .api }

11

moves: ModuleType # Main moves module providing access to relocated imports

12

```

13

14

**Usage Examples:**

15

16

```python

17

import six

18

19

# Access relocated modules

20

from six.moves import urllib

21

from six.moves import configparser

22

from six.moves import queue

23

24

# Use as module attributes

25

http_client = six.moves.http_client

26

builtins_module = six.moves.builtins

27

```

28

29

### Dynamic Move Management

30

31

Functions to add or remove items from the moves module at runtime.

32

33

```python { .api }

34

def add_move(item: MovedAttribute | MovedModule) -> None

35

"""Add an item to six.moves at runtime."""

36

37

def remove_move(name: str) -> None

38

"""Remove an item from six.moves by name."""

39

```

40

41

**Usage Examples:**

42

43

```python

44

import six

45

46

# Add a custom moved attribute

47

custom_move = six.MovedAttribute("custom_name", "old.module", "new.module", "old_attr", "new_attr")

48

six.add_move(custom_move)

49

50

# Remove a moved attribute

51

six.remove_move("custom_name")

52

```

53

54

## Available Moved Items

55

56

### Standard Library Modules

57

58

Core standard library modules that were renamed or reorganized:

59

60

```python

61

# Import examples

62

from six.moves import builtins # __builtin__ → builtins

63

from six.moves import configparser # ConfigParser → configparser

64

from six.moves import copyreg # copy_reg → copyreg

65

from six.moves import queue # Queue → queue

66

from six.moves import socketserver # SocketServer → socketserver

67

from six.moves import xmlrpc_client # xmlrpclib → xmlrpc.client

68

from six.moves import xmlrpc_server # SimpleXMLRPCServer → xmlrpc.server

69

```

70

71

### HTTP Modules

72

73

HTTP-related modules that were reorganized in Python 3:

74

75

```python

76

from six.moves import http_client # httplib → http.client

77

from six.moves import http_cookies # Cookie → http.cookies

78

from six.moves import http_cookiejar # cookielib → http.cookiejar

79

```

80

81

### urllib Package

82

83

Complete urllib package with all submodules:

84

85

```python

86

from six.moves import urllib # Complete urllib package

87

from six.moves.urllib import parse # urlparse → urllib.parse

88

from six.moves.urllib import request # urllib2 → urllib.request

89

from six.moves.urllib import error # urllib2 → urllib.error

90

from six.moves.urllib import response # urllib2 → urllib.response

91

from six.moves.urllib.parse import urlparse, urljoin, quote

92

from six.moves.urllib.request import urlopen, Request

93

```

94

95

### Tkinter Modules

96

97

Complete Tkinter GUI framework modules:

98

99

```python

100

from six.moves import tkinter # Tkinter → tkinter

101

from six.moves import tkinter_dialog # tkSimpleDialog → tkinter.simpledialog

102

from six.moves import tkinter_filedialog # tkFileDialog → tkinter.filedialog

103

from six.moves import tkinter_scrolledtext # ScrolledText → tkinter.scrolledtext

104

from six.moves import tkinter_simpledialog # tkSimpleDialog → tkinter.simpledialog

105

from six.moves import tkinter_tix # Tix → tkinter.tix

106

from six.moves import tkinter_ttk # ttk → tkinter.ttk

107

from six.moves import tkinter_constants # Tkconstants → tkinter.constants

108

from six.moves import tkinter_dnd2 # Tkdnd → tkinter.dnd

109

from six.moves import tkinter_tkfiledialog # tkFileDialog → tkinter.filedialog

110

from six.moves import tkinter_tksimpledialog # tkSimpleDialog → tkinter.simpledialog

111

from six.moves import tkinter_tkcolorchooser # tkColorChooser → tkinter.colorchooser

112

from six.moves import tkinter_tkcommonDialog # tkCommonDialog → tkinter.commondialog

113

from six.moves import tkinter_messagebox # tkMessageBox → tkinter.messagebox

114

from six.moves import tkinter_font # tkFont → tkinter.font

115

```

116

117

### Email MIME Modules

118

119

Email MIME handling modules:

120

121

```python

122

from six.moves import email_mime_base # email.MIMEBase → email.mime.base

123

from six.moves import email_mime_image # email.MIMEImage → email.mime.image

124

from six.moves import email_mime_multipart # email.MIMEMultipart → email.mime.multipart

125

from six.moves import email_mime_nonmultipart # email.MIMENonMultipart → email.mime.nonmultipart

126

from six.moves import email_mime_text # email.MIMEText → email.mime.text

127

```

128

129

### Built-in Functions and Types

130

131

Individual functions and types that moved:

132

133

```python

134

from six.moves import filter # Built-in filter (returns iterator in PY3)

135

from six.moves import input # raw_input → input

136

from six.moves import map # Built-in map (returns iterator in PY3)

137

from six.moves import range # xrange → range

138

from six.moves import zip # izip → zip

139

from six.moves import zip_longest # izip_longest → zip_longest

140

from six.moves import reduce # Built-in reduce moved to functools

141

```

142

143

### Utility Functions and Classes

144

145

Various utility functions and classes:

146

147

```python

148

from six.moves import cPickle # cPickle → pickle (C implementation)

149

from six.moves import reload_module # reload built-in → importlib.reload

150

from six.moves import shlex_quote # pipes.quote → shlex.quote

151

from six.moves import UserDict # UserDict → collections.UserDict

152

from six.moves import UserList # UserList → collections.UserList

153

from six.moves import UserString # UserString → collections.UserString

154

from six.moves import getcwd # os.getcwd

155

from six.moves import getcwdb # os.getcwdb

156

```

157

158

## Lazy Loading Infrastructure

159

160

### MovedAttribute Class

161

162

Descriptor class for individual moved attributes within modules.

163

164

```python { .api }

165

class MovedAttribute:

166

"""Descriptor for moved attributes."""

167

def __init__(

168

self,

169

name: str,

170

old_mod: str,

171

new_mod: str,

172

old_attr: str | None = None,

173

new_attr: str | None = None

174

)

175

```

176

177

**Parameters:**

178

- `name`: Name to use in six.moves

179

- `old_mod`: Python 2 module name

180

- `new_mod`: Python 3 module name

181

- `old_attr`: Python 2 attribute name (defaults to `name`)

182

- `new_attr`: Python 3 attribute name (defaults to `name`)

183

184

### MovedModule Class

185

186

Descriptor class for entire moved modules.

187

188

```python { .api }

189

class MovedModule:

190

"""Descriptor for moved modules."""

191

def __init__(self, name: str, old: str, new: str | None = None)

192

```

193

194

**Parameters:**

195

- `name`: Name to use in six.moves

196

- `old`: Python 2 module name

197

- `new`: Python 3 module name (defaults to `old`)

198

199

### urllib Submodule Classes

200

201

Specialized lazy loader classes for urllib submodules:

202

203

```python { .api }

204

class Module_six_moves_urllib_parse # Lazy loader for urllib.parse

205

class Module_six_moves_urllib_error # Lazy loader for urllib.error

206

class Module_six_moves_urllib_request # Lazy loader for urllib.request

207

class Module_six_moves_urllib_response # Lazy loader for urllib.response

208

class Module_six_moves_urllib_robotparser # Lazy loader for urllib.robotparser

209

class Module_six_moves_urllib # Lazy loader for complete urllib package

210

```

211

212

These classes provide the implementation for the urllib submodule lazy loading system, allowing fine-grained access to urllib functionality across Python versions.

213

214

## Common Usage Patterns

215

216

```python

217

# Standard library imports

218

import six

219

from six.moves import urllib, configparser, queue

220

221

# HTTP operations

222

from six.moves.urllib.request import urlopen

223

from six.moves.urllib.parse import urljoin, urlparse

224

225

response = urlopen('http://example.com')

226

parsed = urlparse('http://example.com/path')

227

228

# Configuration parsing

229

config = configparser.ConfigParser()

230

231

# Queue operations

232

q = queue.Queue()

233

234

# Built-in function usage

235

from six.moves import filter, map, zip

236

result = list(filter(lambda x: x > 0, [-1, 0, 1, 2]))

237

mapped = list(map(str, [1, 2, 3]))

238

pairs = list(zip([1, 2, 3], ['a', 'b', 'c']))

239

```