| 202 | | class_name = '%s.%s' % (cls.__module__, cls.__name__) |
|---|
| 203 | | args = () |
|---|
| 204 | | state = {} |
|---|
| 205 | | if cls.__reduce__ is type.__reduce__: |
|---|
| 206 | | if hasattr(object, '__reduce_ex__'): |
|---|
| 207 | | reduce = object.__reduce_ex__(2) |
|---|
| 208 | | args = reduce[1][1:] |
|---|
| 209 | | else: |
|---|
| 210 | | reduce = object.__reduce__() |
|---|
| 211 | | if len(reduce) > 2: |
|---|
| 212 | | state = reduce[2] |
|---|
| 213 | | if state is None: |
|---|
| 214 | | state = {} |
|---|
| 215 | | if not args and isinstance(state, dict): |
|---|
| 216 | | return _syck.Map(state.copy(), |
|---|
| 217 | | tag="tag:python.yaml.org,2002:object:"+class_name) |
|---|
| 218 | | if not state and isinstance(state, dict): |
|---|
| 219 | | return _syck.Seq(list(args), |
|---|
| 220 | | tag="tag:python.yaml.org,2002:new:"+class_name) |
|---|
| 221 | | value = {} |
|---|
| 222 | | if args: |
|---|
| 223 | | value['args'] = list(args) |
|---|
| 224 | | if state or not isinstance(state, dict): |
|---|
| 225 | | value['state'] = state |
|---|
| 226 | | return _syck.Map(value, |
|---|
| 227 | | tag="tag:python.yaml.org,2002:new:"+class_name) |
|---|
| 228 | | else: |
|---|
| | 204 | if cls in copy_reg.dispatch_table: |
|---|
| | 205 | reduce = copy_reg.dispatch_table[cls](object) |
|---|
| | 206 | elif hasattr(object, '__reduce_ex__'): |
|---|
| | 207 | reduce = object.__reduce_ex__(2) |
|---|
| | 208 | elif hasattr(object, '__reduce__'): |
|---|
| 230 | | cls = reduce[0] |
|---|
| 231 | | class_name = '%s.%s' % (cls.__module__, cls.__name__) |
|---|
| 232 | | args = reduce[1] |
|---|
| 233 | | state = None |
|---|
| 234 | | if len(reduce) > 2: |
|---|
| 235 | | state = reduce[2] |
|---|
| 236 | | if state is None: |
|---|
| 237 | | state = {} |
|---|
| 238 | | if not state and isinstance(state, dict): |
|---|
| 239 | | return _syck.Seq(list(args), |
|---|
| 240 | | tag="tag:python.yaml.org,2002:apply:"+class_name) |
|---|
| 241 | | value = {} |
|---|
| 242 | | if args: |
|---|
| 243 | | value['args'] = list(args) |
|---|
| 244 | | if state or not isinstance(state, dict): |
|---|
| 245 | | value['state'] = state |
|---|
| 246 | | return _syck.Map(value, |
|---|
| 247 | | tag="tag:python.yaml.org,2002:apply:"+class_name) |
|---|
| | 210 | else: |
|---|
| | 211 | raise RuntimeError("cannot dump object: %r" % object) |
|---|
| | 212 | reduce = (list(reduce)+[None]*3)[:3] |
|---|
| | 213 | function, args, state = reduce |
|---|
| | 214 | args = list(args) |
|---|
| | 215 | if state is None: |
|---|
| | 216 | state = {} |
|---|
| | 217 | if function.__name__ == '__newobj__': |
|---|
| | 218 | function = args[0] |
|---|
| | 219 | args = args[1:] |
|---|
| | 220 | tag = 'tag:python.yaml.org,2002:new:' |
|---|
| | 221 | newobj = True |
|---|
| | 222 | else: |
|---|
| | 223 | tag = 'tag:python.yaml.org,2002:apply:' |
|---|
| | 224 | newobj = False |
|---|
| | 225 | function_name = '%s.%s' % (function.__module__, function.__name__) |
|---|
| | 226 | if not args and isinstance(state, dict) and newobj: |
|---|
| | 227 | return _syck.Map(state.copy(), |
|---|
| | 228 | 'tag:python.yaml.org,2002:object:'+function_name) |
|---|
| | 229 | if isinstance(state, dict) and not state: |
|---|
| | 230 | return _syck.Seq(args, tag+function_name) |
|---|
| | 231 | value = {} |
|---|
| | 232 | if args: |
|---|
| | 233 | value['args'] = args |
|---|
| | 234 | if state or not isinstance(state, dict): |
|---|
| | 235 | value['state'] = state |
|---|
| | 236 | return _syck.Map(value, tag+function_name) |
|---|