Skip to content
Permalink
Browse files

UUID in Python

  • Loading branch information...
schani committed Jul 12, 2018
1 parent 22f0f61 commit 7f6a3d315d368d4e7501fc38ff8a0d730095fa55
Showing with 31 additions and 0 deletions.
  1. +31 −0 src/quicktype-core/language/Python.ts
@@ -129,6 +129,7 @@ export class PythonTargetLanguage extends TargetLanguage {
mapping.set("date", dateTimeType);
mapping.set("time", dateTimeType);
mapping.set("date-time", dateTimeType);
mapping.set("uuid", "uuid");
mapping.set("integer-string", "integer-string");
mapping.set("bool-string", "bool-string");
return mapping;
@@ -345,6 +346,9 @@ export class PythonRenderer extends ConvenienceRenderer {
if (transformedStringType.kind === "date-time") {
return this.withImport("datetime", "datetime");
}
if (transformedStringType.kind === "uuid") {
return this.withImport("uuid", "UUID");
}
return panic(`Transformed type ${transformedStringType.kind} not supported`);
}
);
@@ -868,6 +872,9 @@ export class JSONPythonRenderer extends PythonRenderer {
if (transformedStringType.kind === "date-time") {
return this.withImport("datetime", "datetime");
}
if (transformedStringType.kind === "uuid") {
return this.withImport("uuid", "UUID");
}
return undefined;
}
);
@@ -930,6 +937,12 @@ export class JSONPythonRenderer extends PythonRenderer {
case "date-time":
vol = this.convFn("from-datetime", inputTransformer);
break;
case "uuid":
vol = compose(
inputTransformer,
v => [this.withImport("uuid", "UUID"), "(", v, ")"]
);
break;
default:
return panic(`Parsing of ${immediateTargetType.kind} in a transformer is not supported`);
}
@@ -959,6 +972,12 @@ export class JSONPythonRenderer extends PythonRenderer {
v => [v, ".isoformat()"]
);
break;
case "uuid":
vol = compose(
inputTransformer,
v => ["str(", v, ")"]
);
break;
default:
return panic(`Parsing of ${xfer.sourceType.kind} in a transformer is not supported`);
}
@@ -1030,6 +1049,12 @@ export class JSONPythonRenderer extends PythonRenderer {
if (transformedStringType.kind === "date-time") {
return this.convFn("from-datetime", value);
}
if (transformedStringType.kind === "uuid") {
return compose(
value,
v => [this.withImport("uuid", "UUID"), "(", v, ")"]
);
}
return panic(`Transformed type ${transformedStringType.kind} not supported`);
}
);
@@ -1099,6 +1124,12 @@ export class JSONPythonRenderer extends PythonRenderer {
v => [v, ".isoformat()"]
);
}
if (transformedStringType.kind === "uuid") {
return compose(
value,
v => ["str(", v, ")"]
);
}
return panic(`Transformed type ${transformedStringType.kind} not supported`);
}
);

0 comments on commit 7f6a3d3

Please sign in to comment.
You can’t perform that action at this time.