Python regular expression not raising exception inside header.py
my client looks like this->
from email.mime.multipart import MIMEMultipart
b = MIMEMultipart()
b['a'] = "Hello"
b['b'] = "--nhttp://www.stallergenes.com/images/STAL_mail.png"
b.as_string()
This calls a function _write_headers in generator.py
This generator.py calls encode method in header.py
encode function inside header.py looks like this ->
def encode(self, splitchars=';, t', maxlinelen=None, linesep='n'):
_embedded_header = re.compile(r'n[^ t]+:')
print 'value in header.py is -> %s, %s, %s' %(value, type(value), _embeded_header.pattern, _embeded_header.search(value))
if _embedded_header.search(value):
raise HeaderParseError("header value appears to contain "
"an embedded header: {!r}".format(value))
return value
In python2.7, this is my header.py
file inside docker container.
Value of print statement in header.py-> --nhttp://www.stallergenes.com/images/STAL_mail.png, n[^ t]+:, None
So Basically, it should have been matched. why it is not getting matched against this regex?
python regex python-2.7
add a comment |
my client looks like this->
from email.mime.multipart import MIMEMultipart
b = MIMEMultipart()
b['a'] = "Hello"
b['b'] = "--nhttp://www.stallergenes.com/images/STAL_mail.png"
b.as_string()
This calls a function _write_headers in generator.py
This generator.py calls encode method in header.py
encode function inside header.py looks like this ->
def encode(self, splitchars=';, t', maxlinelen=None, linesep='n'):
_embedded_header = re.compile(r'n[^ t]+:')
print 'value in header.py is -> %s, %s, %s' %(value, type(value), _embeded_header.pattern, _embeded_header.search(value))
if _embedded_header.search(value):
raise HeaderParseError("header value appears to contain "
"an embedded header: {!r}".format(value))
return value
In python2.7, this is my header.py
file inside docker container.
Value of print statement in header.py-> --nhttp://www.stallergenes.com/images/STAL_mail.png, n[^ t]+:, None
So Basically, it should have been matched. why it is not getting matched against this regex?
python regex python-2.7
If the output ofprint
is--nhttp://www.stallergenes.com/images/STAL_mail.png
, then you do not have a line break in thevalue
. Otherwise,'n'
would be displayed as a line break. Apparently your'n'
is actually a'\n'
.
– DYZ
Nov 28 '18 at 16:45
But why it is not breaking? it is also working fine for inputs like "Cecilia Alarcon 12:01 PM:n(y):D", "Failed monitors include:nFreeWheel: 2018-03-25", "Anoka Stake Centern6:30 & 7:30pmCT"
– Kartik Thakurela
Nov 29 '18 at 5:47
add a comment |
my client looks like this->
from email.mime.multipart import MIMEMultipart
b = MIMEMultipart()
b['a'] = "Hello"
b['b'] = "--nhttp://www.stallergenes.com/images/STAL_mail.png"
b.as_string()
This calls a function _write_headers in generator.py
This generator.py calls encode method in header.py
encode function inside header.py looks like this ->
def encode(self, splitchars=';, t', maxlinelen=None, linesep='n'):
_embedded_header = re.compile(r'n[^ t]+:')
print 'value in header.py is -> %s, %s, %s' %(value, type(value), _embeded_header.pattern, _embeded_header.search(value))
if _embedded_header.search(value):
raise HeaderParseError("header value appears to contain "
"an embedded header: {!r}".format(value))
return value
In python2.7, this is my header.py
file inside docker container.
Value of print statement in header.py-> --nhttp://www.stallergenes.com/images/STAL_mail.png, n[^ t]+:, None
So Basically, it should have been matched. why it is not getting matched against this regex?
python regex python-2.7
my client looks like this->
from email.mime.multipart import MIMEMultipart
b = MIMEMultipart()
b['a'] = "Hello"
b['b'] = "--nhttp://www.stallergenes.com/images/STAL_mail.png"
b.as_string()
This calls a function _write_headers in generator.py
This generator.py calls encode method in header.py
encode function inside header.py looks like this ->
def encode(self, splitchars=';, t', maxlinelen=None, linesep='n'):
_embedded_header = re.compile(r'n[^ t]+:')
print 'value in header.py is -> %s, %s, %s' %(value, type(value), _embeded_header.pattern, _embeded_header.search(value))
if _embedded_header.search(value):
raise HeaderParseError("header value appears to contain "
"an embedded header: {!r}".format(value))
return value
In python2.7, this is my header.py
file inside docker container.
Value of print statement in header.py-> --nhttp://www.stallergenes.com/images/STAL_mail.png, n[^ t]+:, None
So Basically, it should have been matched. why it is not getting matched against this regex?
python regex python-2.7
python regex python-2.7
edited Nov 28 '18 at 16:40
DYZ
27.8k62150
27.8k62150
asked Nov 28 '18 at 11:07
Kartik ThakurelaKartik Thakurela
297
297
If the output ofprint
is--nhttp://www.stallergenes.com/images/STAL_mail.png
, then you do not have a line break in thevalue
. Otherwise,'n'
would be displayed as a line break. Apparently your'n'
is actually a'\n'
.
– DYZ
Nov 28 '18 at 16:45
But why it is not breaking? it is also working fine for inputs like "Cecilia Alarcon 12:01 PM:n(y):D", "Failed monitors include:nFreeWheel: 2018-03-25", "Anoka Stake Centern6:30 & 7:30pmCT"
– Kartik Thakurela
Nov 29 '18 at 5:47
add a comment |
If the output ofprint
is--nhttp://www.stallergenes.com/images/STAL_mail.png
, then you do not have a line break in thevalue
. Otherwise,'n'
would be displayed as a line break. Apparently your'n'
is actually a'\n'
.
– DYZ
Nov 28 '18 at 16:45
But why it is not breaking? it is also working fine for inputs like "Cecilia Alarcon 12:01 PM:n(y):D", "Failed monitors include:nFreeWheel: 2018-03-25", "Anoka Stake Centern6:30 & 7:30pmCT"
– Kartik Thakurela
Nov 29 '18 at 5:47
If the output of
print
is --nhttp://www.stallergenes.com/images/STAL_mail.png
, then you do not have a line break in the value
. Otherwise, 'n'
would be displayed as a line break. Apparently your 'n'
is actually a '\n'
.– DYZ
Nov 28 '18 at 16:45
If the output of
print
is --nhttp://www.stallergenes.com/images/STAL_mail.png
, then you do not have a line break in the value
. Otherwise, 'n'
would be displayed as a line break. Apparently your 'n'
is actually a '\n'
.– DYZ
Nov 28 '18 at 16:45
But why it is not breaking? it is also working fine for inputs like "Cecilia Alarcon 12:01 PM:n(y):D", "Failed monitors include:nFreeWheel: 2018-03-25", "Anoka Stake Centern6:30 & 7:30pmCT"
– Kartik Thakurela
Nov 29 '18 at 5:47
But why it is not breaking? it is also working fine for inputs like "Cecilia Alarcon 12:01 PM:n(y):D", "Failed monitors include:nFreeWheel: 2018-03-25", "Anoka Stake Centern6:30 & 7:30pmCT"
– Kartik Thakurela
Nov 29 '18 at 5:47
add a comment |
1 Answer
1
active
oldest
votes
n
matches a new line. I don't think that this was your purpose. If you escape it by adding a it should work-
\n[^ t]+:
1
OP has a newline in"--nhttp://www.stallergenes.com/images/STAL_mail.png"
, it is not a sequence ofand
n
chars.
– Wiktor Stribiżew
Nov 28 '18 at 11:12
@WiktorStribiżew What should I change? is this because of some raw string input? I tried with another input value in header.py is -> BUENAS TARDES.nLES MANDO LOS REPORTES DE JLnNOTA: SIN PAROS, <type 'str'>, None searching --- -1 Code in header.py is something like this... print 'value in header.py is -> %s, %s, %s' %(value, type(value), _embeded_header.search(value)) print 'searching --- %s' %(value.find('n'))
– Kartik Thakurela
Dec 12 '18 at 11:10
@KartikThakurela Sorry, I cannot repro that.
– Wiktor Stribiżew
Dec 12 '18 at 11:13
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53518019%2fpython-regular-expression-not-raising-exception-inside-header-py%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
n
matches a new line. I don't think that this was your purpose. If you escape it by adding a it should work-
\n[^ t]+:
1
OP has a newline in"--nhttp://www.stallergenes.com/images/STAL_mail.png"
, it is not a sequence ofand
n
chars.
– Wiktor Stribiżew
Nov 28 '18 at 11:12
@WiktorStribiżew What should I change? is this because of some raw string input? I tried with another input value in header.py is -> BUENAS TARDES.nLES MANDO LOS REPORTES DE JLnNOTA: SIN PAROS, <type 'str'>, None searching --- -1 Code in header.py is something like this... print 'value in header.py is -> %s, %s, %s' %(value, type(value), _embeded_header.search(value)) print 'searching --- %s' %(value.find('n'))
– Kartik Thakurela
Dec 12 '18 at 11:10
@KartikThakurela Sorry, I cannot repro that.
– Wiktor Stribiżew
Dec 12 '18 at 11:13
add a comment |
n
matches a new line. I don't think that this was your purpose. If you escape it by adding a it should work-
\n[^ t]+:
1
OP has a newline in"--nhttp://www.stallergenes.com/images/STAL_mail.png"
, it is not a sequence ofand
n
chars.
– Wiktor Stribiżew
Nov 28 '18 at 11:12
@WiktorStribiżew What should I change? is this because of some raw string input? I tried with another input value in header.py is -> BUENAS TARDES.nLES MANDO LOS REPORTES DE JLnNOTA: SIN PAROS, <type 'str'>, None searching --- -1 Code in header.py is something like this... print 'value in header.py is -> %s, %s, %s' %(value, type(value), _embeded_header.search(value)) print 'searching --- %s' %(value.find('n'))
– Kartik Thakurela
Dec 12 '18 at 11:10
@KartikThakurela Sorry, I cannot repro that.
– Wiktor Stribiżew
Dec 12 '18 at 11:13
add a comment |
n
matches a new line. I don't think that this was your purpose. If you escape it by adding a it should work-
\n[^ t]+:
n
matches a new line. I don't think that this was your purpose. If you escape it by adding a it should work-
\n[^ t]+:
answered Nov 28 '18 at 11:10
Laurent MouchartLaurent Mouchart
195313
195313
1
OP has a newline in"--nhttp://www.stallergenes.com/images/STAL_mail.png"
, it is not a sequence ofand
n
chars.
– Wiktor Stribiżew
Nov 28 '18 at 11:12
@WiktorStribiżew What should I change? is this because of some raw string input? I tried with another input value in header.py is -> BUENAS TARDES.nLES MANDO LOS REPORTES DE JLnNOTA: SIN PAROS, <type 'str'>, None searching --- -1 Code in header.py is something like this... print 'value in header.py is -> %s, %s, %s' %(value, type(value), _embeded_header.search(value)) print 'searching --- %s' %(value.find('n'))
– Kartik Thakurela
Dec 12 '18 at 11:10
@KartikThakurela Sorry, I cannot repro that.
– Wiktor Stribiżew
Dec 12 '18 at 11:13
add a comment |
1
OP has a newline in"--nhttp://www.stallergenes.com/images/STAL_mail.png"
, it is not a sequence ofand
n
chars.
– Wiktor Stribiżew
Nov 28 '18 at 11:12
@WiktorStribiżew What should I change? is this because of some raw string input? I tried with another input value in header.py is -> BUENAS TARDES.nLES MANDO LOS REPORTES DE JLnNOTA: SIN PAROS, <type 'str'>, None searching --- -1 Code in header.py is something like this... print 'value in header.py is -> %s, %s, %s' %(value, type(value), _embeded_header.search(value)) print 'searching --- %s' %(value.find('n'))
– Kartik Thakurela
Dec 12 '18 at 11:10
@KartikThakurela Sorry, I cannot repro that.
– Wiktor Stribiżew
Dec 12 '18 at 11:13
1
1
OP has a newline in
"--nhttp://www.stallergenes.com/images/STAL_mail.png"
, it is not a sequence of
and n
chars.– Wiktor Stribiżew
Nov 28 '18 at 11:12
OP has a newline in
"--nhttp://www.stallergenes.com/images/STAL_mail.png"
, it is not a sequence of
and n
chars.– Wiktor Stribiżew
Nov 28 '18 at 11:12
@WiktorStribiżew What should I change? is this because of some raw string input? I tried with another input value in header.py is -> BUENAS TARDES.nLES MANDO LOS REPORTES DE JLnNOTA: SIN PAROS, <type 'str'>, None searching --- -1 Code in header.py is something like this... print 'value in header.py is -> %s, %s, %s' %(value, type(value), _embeded_header.search(value)) print 'searching --- %s' %(value.find('n'))
– Kartik Thakurela
Dec 12 '18 at 11:10
@WiktorStribiżew What should I change? is this because of some raw string input? I tried with another input value in header.py is -> BUENAS TARDES.nLES MANDO LOS REPORTES DE JLnNOTA: SIN PAROS, <type 'str'>, None searching --- -1 Code in header.py is something like this... print 'value in header.py is -> %s, %s, %s' %(value, type(value), _embeded_header.search(value)) print 'searching --- %s' %(value.find('n'))
– Kartik Thakurela
Dec 12 '18 at 11:10
@KartikThakurela Sorry, I cannot repro that.
– Wiktor Stribiżew
Dec 12 '18 at 11:13
@KartikThakurela Sorry, I cannot repro that.
– Wiktor Stribiżew
Dec 12 '18 at 11:13
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53518019%2fpython-regular-expression-not-raising-exception-inside-header-py%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
If the output of
print
is--nhttp://www.stallergenes.com/images/STAL_mail.png
, then you do not have a line break in thevalue
. Otherwise,'n'
would be displayed as a line break. Apparently your'n'
is actually a'\n'
.– DYZ
Nov 28 '18 at 16:45
But why it is not breaking? it is also working fine for inputs like "Cecilia Alarcon 12:01 PM:n(y):D", "Failed monitors include:nFreeWheel: 2018-03-25", "Anoka Stake Centern6:30 & 7:30pmCT"
– Kartik Thakurela
Nov 29 '18 at 5:47